Class: CoinSync::Importers::BinanceAPI::HistoryEntry

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HistoryEntry

Returns a new instance of HistoryEntry.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/coinsync/importers/binance_api.rb', line 25

def initialize(hash)
  @quantity = BigDecimal.new(hash['qty'])
  @commission = BigDecimal.new(hash['commission'])
  @commission_asset = CryptoCurrency.new(hash['commissionAsset'])
  @price = BigDecimal.new(hash['price'])
  @time = Time.at(hash['time'] / 1000)
  @buyer = hash['isBuyer']

  @asset, @currency = parse_coins(hash['symbol'])

  if (@buyer && @commission_asset != @asset) || (!@buyer && @commission_asset != @currency)
    raise "Binance API: Unexpected fee: #{hash}"
  end
end

Instance Attribute Details

#assetObject

Returns the value of attribute asset.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def asset
  @asset
end

#buyerObject

Returns the value of attribute buyer.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def buyer
  @buyer
end

#commissionObject

Returns the value of attribute commission.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def commission
  @commission
end

#commission_assetObject

Returns the value of attribute commission_asset.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def commission_asset
  @commission_asset
end

#currencyObject

Returns the value of attribute currency.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def currency
  @currency
end

#priceObject

Returns the value of attribute price.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def price
  @price
end

#quantityObject

Returns the value of attribute quantity.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def quantity
  @quantity
end

#timeObject

Returns the value of attribute time.



23
24
25
# File 'lib/coinsync/importers/binance_api.rb', line 23

def time
  @time
end

Instance Method Details

#parse_coins(symbol) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/coinsync/importers/binance_api.rb', line 40

def parse_coins(symbol)
  BASE_COINS.each do |coin|
    if symbol.end_with?(coin)
      asset = symbol.gsub(/#{coin}$/, '')
      return [CryptoCurrency.new(asset), CryptoCurrency.new(coin)]
    end
  end

  raise "Binance API: Unexpected trade symbol: #{symbol}"
end