Class: CoinSync::Importers::BitstampCSV

Inherits:
Base
  • Object
show all
Defined in:
lib/coinsync/importers/bitstamp_csv.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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/coinsync/importers/bitstamp_csv.rb', line 34

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

  transactions = []
  bitcoin = CryptoCurrency.new('BTC')

  csv.each do |line|
    next if line.empty?
    next if line[0] == 'Type'

    entry = HistoryEntry.new(line)

    if entry.type == 'Kup'
      transactions << Transaction.new(
        exchange: 'Bitcurex',
        bought_currency: bitcoin,
        sold_currency: entry.market,
        time: entry.date,
        bought_amount: entry.amount,
        sold_amount: entry.total
      )
    elsif entry.type == 'Sprzedaj'
      transactions << Transaction.new(
        exchange: 'Bitcurex',
        bought_currency: entry.market,
        sold_currency: bitcoin,
        time: entry.date,
        bought_amount: entry.total,
        sold_amount: entry.amount
      )
    else
      raise "Bitcurex importer error: unexpected entry type '#{entry.type}'"
    end
  end

  transactions.reverse
end