Class: CoinSync::Importers::Changelly

Inherits:
Base
  • Object
show all
Defined in:
lib/coinsync/importers/changelly.rb

Defined Under Namespace

Classes: HistoryEntry

Instance Method Summary collapse

Methods inherited from Base

#can_build?, #initialize, register_commands, register_importer, registered_commands

Constructor Details

This class inherits a constructor from CoinSync::Importers::Base

Instance Method Details

#read_transaction_list(source) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/coinsync/importers/changelly.rb', line 31

def read_transaction_list(source)
  csv = CSV.new(source, col_sep: ',')

  transactions = []

  csv.each do |line|
    next if line[0] == 'Status'

    entry = HistoryEntry.new(line)

    next if entry.status != 'finished'

    transactions << Transaction.new(
      exchange: 'Changelly',
      time: entry.date,
      bought_amount: entry.received_amount,
      bought_currency: entry.received_currency,
      sold_amount: entry.exchanged_amount,
      sold_currency: entry.exchanged_currency
    )
  end

  transactions.reverse
end