Bitfinex API: How to Place an Order

I want to place an order on Bitfinex, somewhere along the line, I am doing something wrong (python 3.6.2). Anyone have an idea?

    #PYTHON 3.4
import requests
import json
import base64
import hashlib
import time
import hmac

bitfinexURL = 'https://api.bitfinex.com/v1/order/new'
bitfinexKey = 'xxx'
bitfinexSecret = b'xxx' #the b is deliberate, encodes to bytes

def start():
    payloadObject = {
            'request':'/v1/order/new',
            'nonce':str(time.time() * 100000), #convert to string
            'symbol': 'BTCUSD',
            'amount': '0.01',
            'price': '3000',
            'side': 'SELL',
            'type': 'limit',
    }
    payload_json = json.dumps(payloadObject)
    payload = base64.b64encode(bytes(payload_json, "utf-8"))
    m = hmac.new(bitfinexSecret, payload, hashlib.sha384)
    m = m.hexdigest()
    #headers
    headers = {
          'X-BFX-APIKEY' : bitfinexKey,
          'X-BFX-PAYLOAD' : base64.b64encode(bytes(payload_json, "utf-8")),
          'X-BFX-SIGNATURE' : m
    }

    r = requests.post(bitfinexURL, data={}, headers=headers)
    return
start()

      

Thanks for the help in advance!

+4


source to share





All Articles