Class: Btce::TradeAPI

Inherits:
API
  • Object
show all
Defined in:
lib/btce/api/trade_api.rb

Constant Summary collapse

KEY =
YAML::load File.open 'btce-api-key.yml'
OPERATIONS =
%w(getInfo
TransHistory
TradeHistory
OrderList
WithdrawCoin
ActiveOrders
Trade
CancelOrder)

Constants inherited from API

API::BTCE_DOMAIN, API::CURRENCIES, API::CURRENCY_PAIRS, API::MAX_DIGITS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from API

get_https, get_json

Constructor Details

#initialize(opts = {}) ⇒ TradeAPI

Returns a new instance of TradeAPI

Raises:

  • (ArgumentError)

59
60
61
62
63
# File 'lib/btce/api/trade_api.rb', line 59

def initialize(opts={})
  raise ArgumentError unless opts.has_key?(:key) and opts.has_key?(:secret)
  @key = opts[:key]
  @secret = opts[:secret]
end

Class Method Details

.new_from_keyfileObject


43
44
45
# File 'lib/btce/api/trade_api.rb', line 43

def new_from_keyfile
  new key: KEY["key"], secret: KEY["secret"]
end

Instance Method Details

#sign(params) ⇒ Object


65
66
67
68
69
70
71
# File 'lib/btce/api/trade_api.rb', line 65

def sign(params)
  # The digest needs to be created.
  hmac = OpenSSL::HMAC.new(@secret,
                           OpenSSL::Digest::SHA512.new)
  params = params.collect {|k,v| "#{k}=#{v}"}.join('&')
  signed = hmac.update params
end

#trade_api_call(method, extra) ⇒ Object


73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/btce/api/trade_api.rb', line 73

def trade_api_call(method, extra)
  params = {"method" => method, "nonce" => nonce}
  if ! extra.empty?
    extra.each do |k,v|
      params[k.to_s] = v
    end
  end
  signed = sign params
  API::get_json({ :url => "https://#{API::BTCE_DOMAIN}/tapi",
                  :key => @key,
                  :params => params,
                  :signed => signed })
end