Class: Btce::TradeAPI

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

Constant Summary collapse

OPERATIONS =
%w(getInfo
TransHistory
TradeHistory
OrderList
Trade
CancelOrder)

Constants inherited from API

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

Class Method Summary collapse

Methods inherited from API

get_https, get_json

Class Method Details

.nonceObject



271
272
273
274
275
276
# File 'lib/btce.rb', line 271

def nonce
  while result = Time.now.to_i and @last_nonce and @last_nonce >= result
    sleep 1
  end
  return @last_nonce = result
end

.sign(params) ⇒ Object



250
251
252
253
254
255
256
257
258
# File 'lib/btce.rb', line 250

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

.trade_api_call(method, extra) ⇒ Object



260
261
262
263
264
265
266
267
268
269
# File 'lib/btce.rb', line 260

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
  get_json "https://#{API::BTCE_DOMAIN}/tapi", params, signed
end