更新交割单API
发布时间:2025/11/27阅读:190点赞:30
# coding=utf-8
import requests
import json
# 用户授权码(必填,联系客服申请)
user_token = '00000000-0000-0000-0000-000000000000'
# 交割单ID(从地址栏获取,如:链接地址:https://www.9db.com/detail/0000000-0000-0000-0000-000000000000,ID为后面部分)
order_id = '00000000-0000-0000-0000-000000000000'
# 交易信号(组装交易,支持多条提交)
trade_list = [{
"TradeNumber": "1744682532", # 委托编号(非必填)
"StockSymbol": "002830", # 股票代码
"Type": "买", # 交易类型 买/卖
"Amount": 500, # 交易股数
"AvgPrice": 14.48, # 交易均价
"TradeTime": "2025-11-27 10:35", # 交易时间
"TradeReason": "搅屎棍策略卖出" # 交易理由(非必填)
},
{
"TradeNumber": "1744682533",
"StockSymbol": "002830",
"Type": "买",
"Amount": 100,
"AvgPrice": 14.48,
"TradeTime": "2025-11-27 10:35",
"TradeReason": "搅屎棍策略卖出"
}]
data_url = 'https://api.9db.com/order/TradeOrderInsert_V2'
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
"Content-Type": "application/json"
}
for r in range(10):
try:
response = requests.post(data_url, data=json.dumps({'OrderID': order_id, 'Token': user_token, 'TradeOrders': trade_list}), headers=headers)
if response.status_code == 200:
response_result = json.loads(response.text)
if response_result['errorCode'] != 0:
print('交易信号发送失败,原因:' + str(response_result['errorMess']))
else:
print('交易信号发送成功~')
break
except Exception as ex:
print('交易信号发送失败,原因:' + str(ex))