查询委托单的代码为什么会出错?

用户头像sh_*048w9p
2025-07-22 发布

def execute_buy_decision(context, data, stock, hist):
name = get_security_info(stock).display_name

查询委托单异常: name 'trade_api' is not defined

try:

1. 查询所有未成交委托单

orders = trade_api.get_orders()
for order in orders:
print(
f"委托单号: {order['order_id']} | 股票: {order['symbol']} | 方向: {order['side']} | "
f"价格: {order['price']} | 数量: {order['amount']} | 状态: {order['status']} | "
f"下单时间: {order['datetime']}"
)

for order in orders:
if order['symbol'] == stock and order['status'] == '未成交':
print(f"{name}({stock}) 已有未成交委托,跳过下单")
return False
except Exception as e:
print(f"查询委托单异常: {e}")

评论

用户头像
2025-07-22 23:39:19

已解决

评论