Skip to content

feat(trade): add estimate_multileg_available_quantity (POST /v1/trade/estimate/multileg) - #603

Open
hogan-yuan wants to merge 9 commits into
mainfrom
feat/estimate-multileg
Open

hogan-yuan wants to merge 9 commits into
mainfrom
feat/estimate-multileg

Conversation

@hogan-yuan

Copy link
Copy Markdown
Member

Summary

New TradeContext.estimate_multileg_available_quantity — a pre-trade estimate of a US multi-leg option combination's maximum tradable quantity and margin impact (max_open_qty, unit_margin, initial_margin_change, maintenance_margin_change).

Request: side, order_type, submitted_quantity, strategy (MultiLegStrategy), legs (each symbol + a reserved side), optional submitted_price.

RESTful note

The single-leg estimate_max_purchase_quantity is a GET with scalar query params. This one carries a legs array — which cannot be encoded in a query string — so it is a POST with a JSON body, consistent with the multi-leg submit endpoint (POST /v1/trade/order/multileg).

Layers

Rust core (async + blocking) + C, C++, Java, Node.js, Python. Each builds; longbridge.h, index.d.ts, openapi.pyi regenerated/updated. Go is a separate PR; CLI/MCP are follow-ups.

…/estimate/multileg)

Pre-trade estimate for a US multi-leg option combination: max tradable quantity
and margin impact. Because the request carries a legs array it is a POST with a
JSON body (RESTful), unlike the scalar single-leg estimate which is GET+query.
Rust core async + blocking.
Align the doc comments in every layer (Rust, C, C++, Java, Node.js,
Python) with what the gateway actually returns:

- max_open_qty: the server returns i64::MAX when the legs don't form the
  given strategy; treat that as no usable estimate.
- unit_margin: net debit at market for debit combos, margin requirement for
  credit/short combos (was "margin required per combination unit").
- initial/maintenance_margin_change: scale with submitted_quantity and are 0
  for debit combos.
- submitted_price: still required for limit types, but the estimate is
  computed from market prices so it doesn't change the result.
- Leg order does not matter.

Also allow clippy::too_many_arguments on the async Python method, matching
the rest of the Python bindings.
Resolve conflicts in CHANGELOG.md, c/src/trade_context/context.rs, nodejs/src/trade/context.rs and rust/src/trade/context.rs.

Agent: rust-maintainer
@hogan-yuan

Copy link
Copy Markdown
Member Author

Merged main into this branch (merge commit c4e91b1, no rebase) to clear the conflicts.

Resolved files:

  • CHANGELOG.md: kept the multi-leg estimate entry under [Unreleased] / Added together with main's new entries.
  • rust/src/trade/context.rs, nodejs/src/trade/context.rs: union of the imports (EstimateMultiLegAvailableQuantityOptions plus main's US asset types).
  • c/src/trade_context/context.rs: kept both lb_trade_context_estimate_multileg_available_quantity and main's parse_delayed_until / delayed_until_error helpers.

Checks: cargo check --workspace --all-targets passes, cargo +nightly fmt --all -- --check is clean, and cargo test -p longbridge --lib passes (81 tests).

🤖 Noop (rust-maintainer) · AI agent acting for @your-github

hogan-yuan added a commit to longbridge/longbridge-terminal that referenced this pull request Nov 5, 2026
Resolve conflicts in Cargo.toml, Cargo.lock and src/cli/trade.rs. Pin longbridge to c4e91b1b1 (longbridge/openapi#603 with main merged in), which carries estimate_multileg on top of 5.3.0.

Agent: rust-maintainer
hogan-yuan added a commit to longbridge/longbridge-mcp that referenced this pull request Nov 5, 2026
Resolve conflicts in Cargo.toml, Cargo.lock and src/tools/mod.rs. Pin longbridge / longbridge-proto to c4e91b1b1 (longbridge/openapi#603 with main merged in), which carries estimate_multileg on top of 5.3.

Agent: rust-maintainer
@huacnlee huacnlee closed this Nov 16, 2026
@huacnlee
huacnlee deleted the feat/estimate-multileg branch November 16, 2026 01:22
@hogan-yuan
hogan-yuan restored the feat/estimate-multileg branch December 4, 2026 06:49
@hogan-yuan hogan-yuan reopened this Dec 4, 2026
# Conflicts:
#	CHANGELOG.md
#	c/src/trade_context/context.rs
#	c/src/trade_context/types.rs
#	nodejs/src/trade/context.rs
#	python/src/trade/context.rs
#	python/src/trade/context_async.rs
#	rust/src/trade/context.rs
hogan-yuan added a commit to longbridge/longbridge-mcp that referenced this pull request Dec 4, 2026
Resolve conflicts in Cargo.toml, Cargo.lock and README.md by keeping main.
Drop the git pin on the unreleased longbridge SDK: the estimate tool now
POSTs /v1/trade/estimate/multileg through the HTTP client until the SDK
method (longbridge/openapi#603) ships. Add the ja locale entry and bump the
published tool counts to 205.

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.

2 participants