class CoinPortfolio::ExchangeClient
Attributes
api_key[R]
api_secret[R]
client_factory[R]
Public Class Methods
new(api_key:, api_secret:, client_factory: Coinbase::Wallet::Client)
click to toggle source
# File lib/coin_portfolio/exchange_client.rb, line 5 def initialize(api_key:, api_secret:, client_factory: Coinbase::Wallet::Client) @api_key = api_key @api_secret = api_secret @client_factory = client_factory end
Public Instance Methods
price()
click to toggle source
# File lib/coin_portfolio/exchange_client.rb, line 11 def price sell_price = client.sell_price CoinPortfolio::Money.new(amount: BigDecimal.new(sell_price["amount"]), currency: sell_price["currency"]) end
transactions()
click to toggle source
# File lib/coin_portfolio/exchange_client.rb, line 16 def transactions transactions_from_client.map do |transaction| amount = transaction["amount"] money_amount = CoinPortfolio::Money.new(amount: BigDecimal.new(amount["amount"]).abs, currency: amount["currency"]) native_amount = transaction["native_amount"] money_native_amount = CoinPortfolio::Money.new(amount: BigDecimal.new(native_amount["amount"]).abs, currency: native_amount["currency"]) incoming = amount["amount"][0] != "-" CoinPortfolio::Transaction.new(amount: money_amount, native_amount: money_native_amount, incoming: incoming) end end
Private Instance Methods
account_id()
click to toggle source
# File lib/coin_portfolio/exchange_client.rb, line 38 def account_id client.primary_account["id"] end
client()
click to toggle source
# File lib/coin_portfolio/exchange_client.rb, line 42 def client @client = client_factory.new(api_key: api_key, api_secret: api_secret) end
transactions_from_client()
click to toggle source
# File lib/coin_portfolio/exchange_client.rb, line 34 def transactions_from_client client.transactions(account_id, fetch_all: true) end