Class: RbtcArbitrage::Clients::CoinbaseClient

Inherits:
Object
  • Object
show all
Includes:
RbtcArbitrage::Client
Defined in:
lib/rbtc_arbitrage/clients/coinbase_client.rb

Instance Attribute Summary

Attributes included from RbtcArbitrage::Client

#options

Instance Method Summary collapse

Methods included from RbtcArbitrage::Client

#buy, #initialize, #logger, #sell, #validate_keys

Instance Method Details

#addressObject



52
53
54
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 52

def address
  @address ||= interface.receive_address.address
end

#balanceObject

Returns an array of Floats. The first element is the balance in BTC; The second is in USD.



15
16
17
18
19
20
21
22
23
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 15

def balance
  if @options[:verbose]
    warning = "Coinbase doesn't provide a USD balance because"
    warning << " it connects to your bank account. Be careful, "
    warning << "because this will withdraw directly from your accounts."
    logger.warn warning
  end
  @balance ||= [interface.balance.to_f, max_float]
end

#exchangeObject

return a symbol as the name of this exchange



8
9
10
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 8

def exchange
  :coinbase
end

#interfaceObject



48
49
50
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 48

def interface
  @interface ||= Coinbase::Client.new(ENV['COINBASE_KEY'])
end

#price(action) ⇒ Object

‘action` is :buy or :sell Returns a Numeric type.



37
38
39
40
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 37

def price action
  method = "#{action}_price".to_sym
  @price ||= interface.send(method).to_f
end

#trade(action) ⇒ Object

‘action` is :buy or :sell



31
32
33
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 31

def trade action
  interface.send("#{action}!".to_sym, @options[:volume])
end

#transfer(client) ⇒ Object

Transfers BTC to the address of a different exchange.



44
45
46
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 44

def transfer client
  interface.send_money client.address, @options[:volume]
end

#validate_envObject

Configures the client’s API keys.



26
27
28
# File 'lib/rbtc_arbitrage/clients/coinbase_client.rb', line 26

def validate_env
  validate_keys :coinbase_key, :coinbase_address
end