【发布时间】: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