gpt4 book ai didi

python-2.7 - 用于 Python 的 Bittrex REST API,我想使用 API v3 https ://api. bittrex.com/v3/orders 创建订单

转载 作者:行者123 更新时间:2023-12-03 23:47:01 26 4
gpt4 key购买 nike

我需要帮助来使用 bittrex 版本 3 REST API 创建订单。我有下面的代码,但我不明白缺少什么才能工作。我可以进行其他 GET 调用,但我不能进行此 POST 请求。我不知道如何处理参数的传递。

官方文档位于 https://bittrex.github.io/api/v3#tag-Orders .

def NewOrder(market, amount, price):
#print 'open sell v3', market
market = 'HEDG-BTC'#'BTC-'+market
uri = 'https://api.bittrex.com/v3/orders?'
params = {
'marketSymbol': 'BTC-HEDG',#'HEDG-BTC', #market
'direction': 'BUY',
'type': 'LIMIT',
'quantity': amount,
'limit': price,
'timeInForce': 'POST_ONLY_GOOD_TIL_CANCELLED',
'useAwards': True
}

timestamp = str(int(time.time()*1000))
Content = ""
contentHash = hashlib.sha512(Content.encode()).hexdigest()

Method = 'POST'
uri2 = buildURI(uri, params)
#uri2 = 'https://api.bittrex.com/v3/orders?direction=BUY&limit=0.00021&marketSymbol=HEDG-BTC&quantity=1.1&timeInForce=POST_ONLY_GOOD_TIL_CANCELLED&type=LIMIT&useAwards=True'
#print uri2
PreSign = timestamp + uri2 + Method + contentHash# + subaccountId
#print PreSign
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(uri2, data={}, headers=headers, timeout=11)
return json.loads(r.content)

NewOrder('HEDG', 1.1, 0.00021)

还有我的错误信息:

{u'code': u'BAD_REQUEST', u'data': {u'invalidRequestParameter': u'direction'}, u'detail': u'Refer to the data field for specific field validation failures.'}

最佳答案

从文档看来,api 期望此正文为 json 数据:

{
"marketSymbol": "string",
"direction": "string",
"type": "string",
"quantity": "number (double)",
"ceiling": "number (double)",
"limit": "number (double)",
"timeInForce": "string",
"clientOrderId": "string (uuid)",
"useAwards": "boolean"
}

并且您将这些值设置为 url params,这就是问题所在。

你需要这样做:

uri = 'https://api.bittrex.com/v3/orders'

# NOTE >>>> please check that you provide all the required fields.
payload = {
'marketSymbol': 'BTC-HEDG',#'HEDG-BTC', #market
'direction': 'BUY',
'type': 'LIMIT',
'quantity': amount,
'limit': price,
'timeInForce': 'POST_ONLY_GOOD_TIL_CANCELLED',
'useAwards': True
}

# do rest of the stuffs as you are doing

# post payload as json data with the url given in doc
r = requests.post(uri, json=payload, headers=headers, timeout=11)
print(r.json())

如果您仍有问题,请告诉我们。如果有效,请将答案标记为已接受。希望这会有所帮助。

关于python-2.7 - 用于 Python 的 Bittrex REST API,我想使用 API v3 https ://api. bittrex.com/v3/orders 创建订单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62110824/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com