Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created August 6, 2015 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marshluca/7bce74a65c0062dee8c9 to your computer and use it in GitHub Desktop.
Save marshluca/7bce74a65c0062dee8c9 to your computer and use it in GitHub Desktop.
request bitfinex API
def headers_for(path, options={})
payload = {}
payload['request'] = path
payload['nonce'] = (Time.now.to_f * 10000).to_i.to_s
payload.merge!(options)
payload_enc = Base64.encode64(payload.to_json).gsub(/\s/, '')
sig = Digest::HMAC.hexdigest(payload_enc, @api_secret, Digest::SHA384)
{
'Content-Type' => 'application/json',
'X-BFX-APIKEY' => @api_key,
'X-BFX-PAYLOAD' => payload_enc,
'x-BFX-SIGNATURE' => sig
}
end
path = "/v1/order/new"
params = {
symbol: "btcusd",
amount: amount,
price: price,
side: "sell",
type: "exchange market",
exchange: "bitfinex",
is_hidden: false
}
client.post(path, params, headers_for(path, params))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment