Skip to content

feat(trade): Add grid trading APIs (Rust core + all bindings) - #563

Draft
hogan-yuan wants to merge 3 commits into
mainfrom
feat/grid-trading-rust-core
Draft

feat(trade): Add grid trading APIs (Rust core + all bindings)#563
hogan-yuan wants to merge 3 commits into
mainfrom
feat/grid-trading-rust-core

Conversation

@hogan-yuan

Copy link
Copy Markdown
Member

What

Adds grid trading support to the Longbridge OpenAPI SDK — the Rust core plus all four language bindings (Python, Node.js, Java, C/C++).

Endpoints (11)

submit · replace · list (GET) · list-by-ids (POST) · detail · trigger-history · cancel · suspend · restart · strategy-questionnaire · order-info, plus the GridOrderChanged WebSocket push event.

Commits

  1. Rust coreTradeContext (async) + TradeContextSync (blocking) methods, request/response types, PushEvent::GridOrderChanged.
  2. Bindings — mirrored into Python (pyo3, sync+async), Node.js (napi), Java (JNI + Java POJOs), C (repr(C) FFI) + C++ wrapper.

Conventions

  • Security is passed and returned via symbol (700.HK) across all fields.
  • Datetime fields exposed as RFC3339 (unix-seconds in, RFC3339 out), matching existing trade types.
  • trigger_price_type: 1 = spread, 2 = percent.

Verification

  • cargo build (whole workspace) + cargo clippy -p longbridge: clean.
  • Java mvn compile, C++ -fsyntax-only: pass.
  • End-to-end against the test environment: 10/11 endpoints verified with real requests/responses; types corrected against the live gateway payload.
  • trigger-history returns empty because the test grids never triggered — TriggerOrder fields follow the proto and are pending real-response confirmation (needs a ForceTrigger on the backend).

🤖 Generated with Claude Code

- 11 REST methods on TradeContext: submit / replace / list (GET) /
  list-by-ids (POST) / detail / trigger-history / cancel / suspend /
  restart / strategy-questionnaire / order-info
- Security is passed and returned via `symbol` (700.HK) across all
  request and response fields, matching the OpenAPI convention
- Response types mirror the live gateway payload; datetime fields are
  exposed as RFC3339 (unix-seconds in, RFC3339 out) like other trade
  types; includes grid_status / pullback+rebound / trigger_buy+sell_
  quantity / trigger_times / total_* / paging flags; order-info nests
  channel_infos + bid_sizes
- Response types derive Serialize for consumer convenience
- GridTradeRule request params follow the gridtrading proto
- PushEvent::GridOrderChanged for the grid master-order WS push
- grid_trading example

Verified end-to-end against the test environment: all 11 endpoints
succeed with correct field parsing. trigger_price_type: 1 = spread,
2 = percent.
Mirror the 11 grid trading methods and all grid types from the Rust core
into each language binding, following existing trade patterns:

- Python (pyo3): sync + async TradeContext methods, PyObject/PyEnum mirrors
- Node.js (napi): TradeContext methods, JsObject remote mirrors
- Java (JNI + javasrc): JNI wrappers + Java POJOs + TradeContext methods
- C / C++: repr(C) FFI structs + extern C fns + C++ wrapper

Each adds submit/replace/list(GET)/list-by-ids(POST)/detail/trigger-history/
cancel/suspend/restart/strategy-questionnaire/order-info plus the
GridOrderChanged push event.
Move grid trading out of the trade module/context into its own `grid`
module, mirroring how DCA is structured:

- Core: standalone REST-only `GridContext` (async) + `GridContextSync`
  (blocking); grid types/options/responses under `longbridge::grid::*`.
- All bindings (Python/Node.js/Java/C+C++): grid exposed as its own
  context class (`GridContext.create(config)` etc.), separate from the
  trade context.
- The WS push (`GridOrderChanged`) stays on `TradeContext` since it
  travels on the trade private topic.
- Drop the redundant `grid_`/`grid_order_` prefix from method names
  (submit / replace / list / list_by_ids / detail / trigger_history /
  cancel / suspend / restart / order_info), matching DCAContext's
  unprefixed methods. Types keep the `Grid` prefix.
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