Class: RbtcArbitrage::Clients::MtGoxClient
- Inherits:
-
Object
- Object
- RbtcArbitrage::Clients::MtGoxClient
- Includes:
- RbtcArbitrage::Client
- Defined in:
- lib/rbtc_arbitrage/clients/mtgox_client.rb
Instance Attribute Summary
Attributes included from RbtcArbitrage::Client
Instance Method Summary collapse
-
#balance ⇒ Object
Returns an array of Floats.
- #exchange ⇒ Object
-
#price(action) ⇒ Object
‘action` is :buy or :sell Returns a Numeric type.
-
#trade(action) ⇒ Object
‘action` is :buy or :sell.
-
#transfer(other_client) ⇒ Object
Transfers BTC to the address of a different exchange.
-
#validate_env ⇒ Object
Configures the MtGox client’s API keys.
Methods included from RbtcArbitrage::Client
#address, #buy, #initialize, #logger, #sell, #validate_keys
Instance Method Details
#balance ⇒ Object
Returns an array of Floats. The first element is the balance in BTC; The second is in USD.
10 11 12 13 14 |
# File 'lib/rbtc_arbitrage/clients/mtgox_client.rb', line 10 def balance return @balance if @balance balances = MtGox.balance @balance = [balances[0].amount.to_f, balances[1].amount.to_f] end |
#exchange ⇒ Object
27 28 29 |
# File 'lib/rbtc_arbitrage/clients/mtgox_client.rb', line 27 def exchange :mtgox end |
#price(action) ⇒ Object
‘action` is :buy or :sell Returns a Numeric type.
33 34 35 36 37 38 39 40 |
# File 'lib/rbtc_arbitrage/clients/mtgox_client.rb', line 33 def price action return @price if @price action = { buy: :sell, sell: :buy, }[action] @price = MtGox.ticker.send(action) end |
#trade(action) ⇒ Object
‘action` is :buy or :sell
43 44 45 46 |
# File 'lib/rbtc_arbitrage/clients/mtgox_client.rb', line 43 def trade action action = "#{action.to_s}!".to_sym MtGox.send(action, [:volume], :market) end |
#transfer(other_client) ⇒ Object
Transfers BTC to the address of a different exchange.
51 52 53 |
# File 'lib/rbtc_arbitrage/clients/mtgox_client.rb', line 51 def transfer other_client MtGox.withdraw! [:volume], other_client.address end |
#validate_env ⇒ Object
Configures the MtGox client’s API keys.
19 20 21 22 23 24 25 |
# File 'lib/rbtc_arbitrage/clients/mtgox_client.rb', line 19 def validate_env validate_keys :mtgox_key, :mtgox_secret, :mtgox_address MtGox.configure do |config| config.key = ENV["MTGOX_KEY"] config.secret = ENV["MTGOX_SECRET"] end end |