Class: RbtcArbitrage::Clients::BtceClient

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

Instance Attribute Summary

Attributes included from RbtcArbitrage::Client

#options

Instance Method Summary collapse

Methods included from RbtcArbitrage::Client

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

Instance Method Details

#balanceObject



10
11
12
13
14
15
16
17
18
# File 'lib/rbtc_arbitrage/clients/btce_client.rb', line 10

def balance
  return @balance if @balance
  begin
    balances = interface.get_info["return"]["funds"]
    @balance = [balances["btc"], balances["usd"]]
  rescue NoMethodError => e
    raise SecurityError, "Invalid API key for BTC-e"
  end
end

#exchangeObject



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

def exchange
  :btce
end

#interfaceObject



20
21
# File 'lib/rbtc_arbitrage/clients/btce_client.rb', line 20

def interface
end

#price(action) ⇒ Object



42
43
44
45
46
# File 'lib/rbtc_arbitrage/clients/btce_client.rb', line 42

def price action
  return @ticker[action.to_s] if @ticker
  @ticker = Btce::Ticker.new("btc_usd").json["ticker"]
  @ticker[action.to_s]
end

#trade(action) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rbtc_arbitrage/clients/btce_client.rb', line 27

def trade action
  warning = "BTC-E does not support API bitcoin transfer. "
  warning << "If you really want to trade, you will have "
  warning << "to manually send bitcoin. Enter 'accept' to continue. \n> "
  @options[:logger].warn warning if @options[:verbose]
  return false unless gets.chomp == "accept"
  opts = {
    type: action,
    rate: price(action),
    amount: @options[:volume],
    pair: "btc_usd"
  }
  interface.trade opts
end

#transfer(client) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rbtc_arbitrage/clients/btce_client.rb', line 48

def transfer client
  if @options[:verbose]
    error = "BTC-E does not have a 'transfer' API.\n"
    error << "You must transfer bitcoin manually."
    @options[:logger].error error
  end
end

#validate_envObject



23
24
25
# File 'lib/rbtc_arbitrage/clients/btce_client.rb', line 23

def validate_env
  validate_keys :btce_key, :btce_secret, :btce_address
end