Class: CoinSync::Importers::BinanceAPI::HistoryEntry
- Inherits:
-
Object
- Object
- CoinSync::Importers::BinanceAPI::HistoryEntry
- Defined in:
- lib/coinsync/importers/binance_api.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
Returns the value of attribute asset.
-
#buyer ⇒ Object
Returns the value of attribute buyer.
-
#commission ⇒ Object
Returns the value of attribute commission.
-
#commission_asset ⇒ Object
Returns the value of attribute commission_asset.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#price ⇒ Object
Returns the value of attribute price.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
-
#initialize(hash) ⇒ HistoryEntry
constructor
A new instance of HistoryEntry.
- #parse_coins(symbol) ⇒ Object
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
#asset ⇒ Object
Returns the value of attribute asset.
23 24 25 |
# File 'lib/coinsync/importers/binance_api.rb', line 23 def asset @asset end |
#buyer ⇒ Object
Returns the value of attribute buyer.
23 24 25 |
# File 'lib/coinsync/importers/binance_api.rb', line 23 def buyer @buyer end |
#commission ⇒ Object
Returns the value of attribute commission.
23 24 25 |
# File 'lib/coinsync/importers/binance_api.rb', line 23 def commission @commission end |
#commission_asset ⇒ Object
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 |
#currency ⇒ Object
Returns the value of attribute currency.
23 24 25 |
# File 'lib/coinsync/importers/binance_api.rb', line 23 def currency @currency end |
#price ⇒ Object
Returns the value of attribute price.
23 24 25 |
# File 'lib/coinsync/importers/binance_api.rb', line 23 def price @price end |
#quantity ⇒ Object
Returns the value of attribute quantity.
23 24 25 |
# File 'lib/coinsync/importers/binance_api.rb', line 23 def quantity @quantity end |
#time ⇒ Object
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 |