Skip to content

Scope proposal: fix OKX protection IDs and full ADL close classification #438

Done

Description

@AmazingZ-sys

Describe the bug

Problem

In QuantDinger v6.0.7, two OKX perpetual-swap cases can be reproduced with mocked exchange responses:

  1. Protection order IDs. Invoke the native protection path with a synthetic entry ID such as qdentry123 and capture the request to POST /api/v5/trade/order-algo. Stop-loss, take-profit, and trailing-stop requests can contain hyphens in algoClOrdId. OKX requires an ASCII alphanumeric ID of at most 32 characters and can reject the protection request with 51000: Parameter algoClOrdId error.
  2. Full ADL closes. Return an otherwise matching close fill and an OKX position-history record with type: "6". OKX documents this as ADL with the position fully closed. Both OKX close-history paths only recognize type: "5" as ADL, so the full close is recorded as exchange_native_close and misses handling gated on exchange_adl.

OKX API documentation · Protection placement · Close classification

Proposed scope

  • Generate deterministic, alphanumeric OKX protection IDs of at most 32 characters, with distinct IDs across protection roles and entry attempts. Preserve the identifier returned by the exchange for binding and reconciliation.
  • Classify OKX types 5 and 6 as exchange_adl in both close-history paths. Preserve liquidation and ordinary-close classifications and leave historical records as stored.
  • Use mocked tests for request payloads, retry stability, distinct IDs, and the ADL and ordinary-close cases. No exchange credentials or live orders are needed for the tests.

Could a maintainer confirm this scope before an implementation PR, and indicate whether you would prefer one PR or two?

Steps to reproduce

Use the two numbered mocked cases in the description. No live orders are required.

Expected behavior

No response

Deployment method

Docker Compose

Relevant logs

Activity

  1. added
    bug
    on Dec 4, 2026
  2. brokermr810 commented on Dec 4, 2026

    @brokermr810
    Collaborator

    Thanks for the precise report. Both defects are fixed in commit 44a5781 on test, included in PR #439.

    • OKX stop-loss, take-profit, and trailing protection IDs now hash the complete entry identity and role into deterministic ASCII alphanumeric IDs of at most 32 characters. Roles and entry attempts remain distinct, retries are stable, and exchange-returned identifiers remain authoritative for reconciliation.
    • Both OKX close-history paths now recognize types 5 and 6 as exchange_adl. Ordinary closes and liquidation classifications remain intact; historical trades are not rewritten.
    • We also audited native protection IDs and forced-close classification across the other supported venues.

    The combined offline regression suite for the changed test modules passed: 467 passed, 1 skipped, covering mocked protection payloads, stable/distinct IDs, ADL classification, and forced-close reconciliation. No exchange credentials or live orders were used in these tests.

    Closing this report as addressed by the published fix. PR #439 tracks the merge and CI review; the fix is currently on test, not yet merged into main or released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions