Class: RbtcArbitrage::Clients::CampbxClient

Inherits:
Object
  • Object
show all
Includes:
RbtcArbitrage::Client
Defined in:
lib/rbtc_arbitrage/clients/campbx_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



43
44
45
# File 'lib/rbtc_arbitrage/clients/campbx_client.rb', line 43

def address
  @address ||= interface.get_btc_address["Success"]
end

#balanceObject



10
11
12
13
14
# File 'lib/rbtc_arbitrage/clients/campbx_client.rb', line 10

def balance
  return @balance if @balance
  funds = interface.my_funds
  [funds["Total BTC"].to_f, funds["Total USD"].to_f]
end

#exchangeObject



6
7
8
# File 'lib/rbtc_arbitrage/clients/campbx_client.rb', line 6

def exchange
  :campbx
end

#interfaceObject



16
17
18
# File 'lib/rbtc_arbitrage/clients/campbx_client.rb', line 16

def interface
  @interface ||= CampBX::API.new(ENV['CAMPBX_KEY'],ENV['CAMPBX_SECRET'])
end

#price(action) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/rbtc_arbitrage/clients/campbx_client.rb', line 30

def price action
  return @price if @price
  action = {
    buy: "Best Ask",
    sell: "Best Bid",
  }[action]
  @price = interface.xticker[action].to_f
end

#trade(action) ⇒ Object



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

def trade action
  trade_mode = "Quick#{action.to_s.capitalize}"
  interface.trade_enter trade_mode, @options[:volume], price(action)
end

#transfer(client) ⇒ Object



39
40
41
# File 'lib/rbtc_arbitrage/clients/campbx_client.rb', line 39

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

#validate_envObject



20
21
22
23
# File 'lib/rbtc_arbitrage/clients/campbx_client.rb', line 20

def validate_env
  validate_keys :campbx_key, :campbx_secret

end