Skip to content

fix(trade): avoid resending cancellations after HTTP 429 - #648

Open
Tickwhiz wants to merge 1 commit into
longbridge:mainfrom
Tickwhiz:fix/single-attempt-order-cancellation
Open

Tickwhiz wants to merge 1 commit into
longbridge:mainfrom
Tickwhiz:fix/single-attempt-order-cancellation

Conversation

@Tickwhiz

@Tickwhiz Tickwhiz commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A single TradeContext::cancel_order call goes through the JSON sender's rate-limit retry loop. With an empty HTTP 429 response on every attempt, a loopback server observed six DELETE /v1/trade/order requests for one cancellation on SDK 5.5.0 and 5.6.1 with both API key and OAuth authentication. If a later attempt succeeds, the caller can also miss the initial rate-limit error.

Add RequestBuilder::send_once using the existing signed request and response handling. Use it for order cancellation so the caller receives the first rate-limit error and can decide whether and when to retry. Order queries keep their current backoff behavior. The public trade method's signature is unchanged.

Regression coverage

The loopback test calls the public cancel_order and today_orders methods. Its server returns two empty 429 responses followed by a valid success envelope. On the unpatched main revision the cancellation consumes all three responses and returns success. With this change the server observes DELETE, GET, GET: cancellation returns the first 429 with its trace ID and body, and the order query retries successfully.

  • cargo test -p longbridge -p longbridge-httpcli --lib — 115 SDK tests and 25 HTTP client tests passed.
  • cargo +nightly fmt --all and git diff --check passed.
  • cargo clippy --all --all-features passed for the full workspace.
  • Independent public TradeContext loopback on the candidate with API key and OAuth authentication: six cases passed. Each cancellation sent one DELETE for a persistent empty 429, an API-error JSON 429, or a successful JSON 200. The status or business error and trace ID were preserved in the failure cases.
  • A local build of the candidate Python wheel was stopped by the host during native extension compilation. The candidate loopback results above use the Rust API. The published Python wheel results in the summary are baseline measurements.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant