【问题标题】:Bittrex REST API v3, Python POST orders, INVALID_CONTENT_HASHBittrex REST API v3,Python POST 订单,INVALID_CONTENT_HASH
【发布时间】:2020-06-01 19:48:30
【问题描述】:

我想使用 bittrex Rest API v3 创建订单以使用我的 bittrex 积分。

我无法创建有效的 CONTENT_HASH,因此无法创建订单。有人可以帮我吗,代码如下。

API 文档:https://bittrex.github.io/api/v3#/definitions/NewOrder

import urllib2;import random;import httplib;import urllib;import json;import hashlib;import 
hmac;import time
import requests
import json
import base64
import hashlib
import time
import hmac
from operator import itemgetter
from datetime import datetime, timedelta
import os

def NewOrder(market, amount, price):
market = 'BTC-'+market
uri = 'https://api.bittrex.com/v3/orders'

payload = {
    'marketSymbol': market,
    'direction': 'BUY',
    'type': 'LIMIT',
    'quantity': amount,
    #'ceiling': amount, #0.0, #'number (double)',
    'limit': price,
    'timeInForce': 'GOOD_TILL_CANCELLED',#'POST_ONLY_GOOD_TIL_CANCELLED',
    #'clientOrderId': accountId,
    'useAwards': True
}
#ceiling (optional, must be included for ceiling orders and excluded for non-ceiling orders)
#clientOrderId (optional) client-provided identifier for advanced order tracking

timestamp = str(int(time.time()*1000))
Content = json.dumps(payload, separators=(',',':'))
#Content = '{"direction":"BUY","limit":0.00021,"marketSymbol":"BTC-HEDG","quantity":1.1,"useAwards":true,"timeInForce":"GOOD_TILL_CANCELLED","type":"LIMIT"}'
#Content = '{"direction":"BUY","marketSymbol":"BTC-HEDG","useAwards":true,"timeInForce":"GOOD_TILL_CANCELLED","limit":0.00021,"type":"LIMIT","quantity":1.1}'
print Content
contentHash = hashlib.sha512(Content.encode()).hexdigest()
print '---', contentHash

Method = 'POST'
PreSign = timestamp + uri + Method + contentHash# + accountId
Signature = hmac.new(apisecret, PreSign.encode(), hashlib.sha512).hexdigest()

headers = {
      'Api-Key' : apikey,
      'Api-Timestamp' : timestamp,
      'Api-Content-Hash': contentHash,
      'Api-Signature' : Signature
}
r = requests.post(uri, json=payload, headers=headers, timeout=11)
print(r.json())

>>> NewOrder('HEDG', 1.1, 0.00021)

{u'code': u'INVALID_CONTENT_HASH'}

【问题讨论】:

    标签: python-2.7 request python-requests http-post bitcoin


    【解决方案1】:

    您可能需要检查timeInForceGOOD_TIL_CANCELLED 的拼写。请注意,Bittrex 拼错了“till”这个词。

    【讨论】:

      【解决方案2】:

      为了修复 INVALID_CONTENT_HASH 错误,我这样做了:

      contentHash = hashlib.sha512(bytes(json.dumps(payload), "utf-8")).hexdigest()
      

      【讨论】:

        【解决方案3】:

        您只使用了 URI,尽管 API 要求您使用 URI + 查询字符串。变化:

        url = uri + '?' + '&'.join(['{}={}'.format(k, v) for (k, v) in payload.items()])
        PreSign = timestamp + url + Method + contentHash + accountId
        
        ...
        
        r = requests.post(url, json=payload, headers=headers, timeout=11)
        

        注意:仅当您使用 json arg 发送参数时它才有效。我尝试使用 paramsdata args 发送参数并得到相同的 INVALID_CONTENT_HASH 结果。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2017-11-26
          • 1970-01-01
          • 2020-02-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多