API Bitfinex:如何下订单

时间:2017-07-30 10:15:40

标签: json orders

我希望在Bitfinex上下订单,我正在做错事的某个地方(python 3.6.2)。任何人都有任何想法?

    #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()

提前感谢您的帮助!

0 个答案:

没有答案