文件预览

cancel-order.md

查看 paper-test2 技能包中的文件内容。

文件内容

references/cancel-order.md

# cancel-order

Cancel a WORKING order via `DELETE /v1/orders/{order_id}`.

## When to consult this

User says "撤单 ord_xxx", "撤掉刚才那单", "cancel ord_abc12345". Always
require confirmation first (see SKILL.md Confirmation discipline).

## Identifying the order_id

If user references "刚才那单" or similar without giving an explicit
`order_id`, query recent WORKING orders first:

    python3 -c "
    from scripts._http import Client
    print(Client().get('/v1/accounts/acc_default/orders?status=WORKING'))
    "

Present the candidates (symbol, side, qty, limit price) and ask the user
which one to cancel before proceeding.

## Calling

    python3 -c "
    from scripts._http import Client
    print(Client().delete('/v1/orders/ord_accdefault_abc12345'))
    "

## Successful response

The server returns the final order snapshot after cancellation:

    {
      "order_id": "ord_accdefault_abc12345",
      "client_order_id": "<uuid>",
      "state": "CANCELLED",
      "remaining_qty": 0,
      "fills": [],
      "state_history": [
        {"state": "NEW",       "ts": "...", "reason": null},
        {"state": "WORKING",   "ts": "...", "reason": null},
        {"state": "CANCELLED", "ts": "...", "reason": null}
      ]
    }

For **BUY** cancellations, the frozen amount (price × qty + fee estimate) is
released back to `cash.available`. For **SELL** cancellations, the locked
share quantity is released from `positions[*].qty_locked_sell` (sellable
shares increase again). Tell the user what was released — for BUY, compute
roughly as `price × qty`; for SELL, use the order `qty`. The exact figures
are in the account / positions snapshot.

## Error responses

| Code | HTTP | recovery_hint | What to tell the user |
|------|------|---------------|----------------------|
| `ORDER_NOT_FOUND` | 404 | fix_input | order_id wrong or the order is already in a terminal state |
| `ORDER_NOT_CANCELLABLE` | 409 | fix_input | order is FILLED / REJECTED / CANCELLED; nothing to cancel |
| `CANCEL_FAILED` | 409 | retry | raced with a fill; _http.py does not auto-retry DELETE; surface as-is and suggest querying order state |