longportapp / openapi-sdk

LongPort OpenAPI SDK Base.
https://open.longportapp.com
Apache License 2.0
112 stars 11 forks source link

OpenApiException: (602001) 参数校验失败,请联系客服 #9

Closed dzzhyk closed 9 months ago

dzzhyk commented 9 months ago

描述

大佬们,使用openapi在模拟账户下单后获取了SubmitOrderResponse,然后使用order_id查询order_detail,有时会出现602001错误,参数校验失败 查了一下错误码,没找到这个错误码,是什么问题呢?

代码

resp = trade_ctx.submit_order(...订单参数)
order_id = resp.order_id
lp_order = trade_ctx.order_detail(order_id) #报错602001

请问有没有地方可以查看全部错误码及其原因?

huacnlee commented 9 months ago

order_id 是不是空的。你打印看看

602001 这个错误是参数不正确,你对文档看一下参数的说明,是否存在有遗漏。

dzzhyk commented 9 months ago

大佬好,昨晚又测试了一下,发现查询order_detail之前是有order_id的

代码:

prec = Decimal('0.00')
try:
    self.logger.info(f'LongPortBroker 创建订单: '
                     f'symbol={data.p.symbol}, '
                     f'order_type={order_type}, '
                     f'side={side}, '
                     f"submitted_price={Decimal.from_float(price).quantize(prec) if price is not None else None}, "
                     f'submitted_quantity={amount}, '
                     f'time_in_force={time_in_force}, '
                     f"trigger_price={Decimal.from_float(plimit).quantize(prec) if plimit is not None else None}, "
                     f"trailing_amount={Decimal.from_float(trailamount).quantize(prec) if trailamount is not None else None}, "
                     f"trailing_percent={Decimal.from_float(trailpercent).quantize(prec) if trailpercent is not None else None}, "
                     f"limit_offset={Decimal.from_float(plimit).quantize(prec) if plimit is not None else None}, "
                     f'expire_date={expire_at}')

    resp = trade_ctx.submit_order(
        symbol=data.p.symbol,
        order_type=order_type,
        side=side,
        submitted_price=Decimal.from_float(price).quantize(prec) if price is not None else None,
        submitted_quantity=int(amount),
        time_in_force=time_in_force,
        trigger_price=Decimal.from_float(plimit).quantize(prec) if plimit is not None else None,
        trailing_amount=Decimal.from_float(trailamount).quantize(prec) if trailamount is not None else None,
        trailing_percent=Decimal.from_float(trailpercent).quantize(prec) if trailpercent is not None else None,
        limit_offset=Decimal.from_float(plimit).quantize(prec) if plimit is not None else None,
        expire_date=expire_at,
        outside_rth=OutsideRTH.RTHOnly
    )
    oid = resp.order_id
    self.logger.info(f'LongPortBroker 订单提交回复: {resp}, order_id: {oid}')
    lp_order = trade_ctx.order_detail(order_id=oid)
except Exception as ex:
    self.logger.error('LongPortBroker 提交订单异常: ' + '\n'.join(traceback.format_exception(ex)))
    return None

部分相关日志:

[2024-01-24 04:32:14] [INFO] 当前position[AAPL.US]: --- Position Begin, - Size: 10, - Price: 195.11, - Price orig: 0.0, - Closed: 0, - Opened: 10, - Adjbase: None, --- Position End
[2024-01-24 04:32:14] [INFO] 测试卖出 AAPL.US
[2024-01-24 04:32:14] [INFO] LongPortBroker 创建订单: symbol=AAPL.US, order_type=OrderType.MO, side=OrderSide.Sell, submitted_price=None, submitted_quantity=10, time_in_force=TimeInForceType.Day, trigger_price=None, trailing_amount=None, trailing_percent=None, limit_offset=None, expire_date=None
[2024-01-24 04:32:14] [INFO] LongPortBroker 订单提交回复: SubmitOrderResponse { order_id: "934546019830861824" }, order_id: 934546019830861824
[2024-01-24 04:32:14] [ERROR] LongPortBroker 提交订单异常: Traceback (most recent call last):

  File "<string>", line 224, in _submit

longbridge.OpenApiException: OpenApiException: (602001) 参数校验失败,请联系客服

返回602001报错后,该卖出市价单仍然成交了:

请问这个能排查出什么原因吗?我这边是同时下单5个标的,下单后立刻查询订单详情,order_detail接口查询qps应该是5,会不会是查询太快导致

LuGHuaaa commented 9 months ago

是查询间隔太短导致的, 当时数据还没插入数据库. 可以考虑加一些延时再查询, 或者可以考虑通过 websocket 获取订单数据.

dzzhyk commented 9 months ago

感谢大佬