对于使用Bittrex API V3的newOrder
请求,您需要进行身份验证。以下是一个示例代码来执行newOrder
请求:
import requests
import hmac
import hashlib
import time
# API请求信息
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'
api_url = 'https://api.bittrex.com/v3/orders'
# 请求头
headers = {
'Content-Type': 'application/json',
'Api-Key': api_key,
}
# 请求参数
market = 'BTC-ETH'
quantity = '0.5'
price = '0.04'
side = 'buy'
time_in_force = 'GOOD_TIL_CANCELLED'
type = 'LIMIT'
# 创建请求体
body = {
'marketSymbol': market,
'direction': side,
'type': type,
'quantity': quantity,
'limit': price,
'timeInForce': time_in_force,
}
# 生成API签名
timestamp = str(int(time.time() * 1000))
pre_sign = timestamp + api_url + 'POST' + str(body)
signature = hmac.new(api_secret.encode(), pre_sign.encode(), hashlib.sha512).hexdigest()
# 添加API签名到请求头
headers['Api-Timestamp'] = timestamp
headers['Api-Signature'] = signature
# 发送请求
response = requests.post(api_url, headers=headers, json=body)
print(response.json())
请注意,此示例代码仅提供了基本的请求参数和身份验证逻辑。您可能需要根据自己的实际需求进行调整和修改。