class CoinSync::Importers::Bitcurex

Public Instance Methods

read_transaction_list(source) click to toggle source
# File lib/coinsync/importers/bitcurex.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] == 'LP'

    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