Module: Bitmex

Defined in:
lib/bitmex.rb,
lib/bitmex/base.rb,
lib/bitmex/chat.rb,
lib/bitmex/mash.rb,
lib/bitmex/rest.rb,
lib/bitmex/user.rb,
lib/bitmex/order.rb,
lib/bitmex/quote.rb,
lib/bitmex/stats.rb,
lib/bitmex/trade.rb,
lib/bitmex/apikey.rb,
lib/bitmex/client.rb,
lib/bitmex/version.rb,
lib/bitmex/position.rb,
lib/bitmex/websocket.rb,
lib/bitmex/instrument.rb

Overview

Bitmex module

Defined Under Namespace

Classes: Apikey, Base, Chat, Client, Error, ForbiddenError, Instrument, Mash, Order, Position, Quote, Rest, Stats, Trade, User, Websocket

Constant Summary collapse

TESTNET_HOST =
'testnet.bitmex.com'.freeze
MAINNET_HOST =
'www.bitmex.com'.freeze
VERSION =
'0.1.6'

Class Method Summary collapse

Class Method Details

.headers(api_key, api_secret, verb, path, body, query) ⇒ Object



43
44
45
46
47
48
49
50
51
52
# File 'lib/bitmex.rb', line 43

def self.headers(api_key, api_secret, verb, path, body, query)
  return {} unless api_key || api_secret

  expires = Time.now.utc.to_i + 60
  {
    'api-expires' => expires.to_s,
    'api-key' => api_key,
    'api-signature' => Bitmex.signature(api_secret, verb, path, expires, body, query)
  }
end

.signature(api_secret, verb, path, expires, body, query) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/bitmex.rb', line 31

def self.signature(api_secret, verb, path, expires, body, query)
  body = '' if body.nil?
  body = body.to_s unless body.is_a? String

  if query != nil && query.is_a?(Hash) && !query.empty?
    path += "?#{URI.encode_www_form(query)}"
  end

  data = verb + path + expires.to_s + body
  OpenSSL::HMAC.hexdigest 'SHA256', api_secret, data
end