Skip to content

feat(trade): add attached order (take-profit/stop-loss) support#110

Draft
sunli829 wants to merge 1 commit into
mainfrom
feat/attached-order-support
Draft

feat(trade): add attached order (take-profit/stop-loss) support#110
sunli829 wants to merge 1 commit into
mainfrom
feat/attached-order-support

Conversation

@sunli829

Copy link
Copy Markdown
Contributor

Summary

Ports the attached order (take-profit / stop-loss) feature added to the Rust/Python/Node.js/Java/C/C++ SDKs in longbridge/openapi#549 (docs: longbridge/developers#1092). PR #549 is still open/unmerged upstream at the time of this PR.

  • New types: AttachedOrderType (ProfitTaker / StopLoss / Bracket), AttachedOrderDetail, SubmitAttachedParams, ReplaceAttachedParams
  • SubmitOrder / ReplaceOrder: new AttachedParams field
  • Order / OrderDetail: new AttachedOrders []AttachedOrderDetail field
  • New TradeContext.OrderDetailAttached(orderId) / CancelOrderAttached(orderId) methods — query/cancel an attached sub-order by its own order ID. Added as separate methods rather than changing OrderDetail/CancelOrder's existing signatures, since Go has no method overloading or default parameters (other SDKs did this via optional/default params or impl Into<Options>; Go's closest precedent is the C SDK's separate lb_trade_context_cancel_order_attached function).
  • GetTodayOrders: new OrderId and IsAttached fields (OrderId was previously missing entirely even though the API already supported it) — combined, treats OrderId as an attached sub-order ID and returns that sub-order as an Order entry
  • New example: examples/submit_order_with_attached

Breaking change

OrderDetail.ChargeDetail is now *OrderChargeDetail (was a value type), since the server returns null for this field on attached sub-orders. Matches the same breaking change made upstream across all 6 languages.

Note for reviewers

AttachedOrderDetail's AttachedTypeDisplay, TriggerStatus, and Tag fields are implemented as typed string enums (e.g. "PROFIT_TAKER", "DEACTIVE", "Normal"), matching the upstream Rust struct definitions (tested end-to-end per PR #549's description). However, the longbridge/developers docs PR's JSON example shows these same three fields as raw integers instead. Since both source PRs are still open/unreviewed, this is unconfirmed against a live API response — if the wire format turns out to be numeric, JSON unmarshaling of these three fields will fail. Worth verifying against a real sandbox response before this ships.

Test plan

  • go build ./... and go vet ./trade/...
  • Verified the jinzhu/copier-based JSON→domain-type conversion (nested pointer structs, slices of new struct types, nil-safety for ChargeDetail/AttachedParams) via a temporary round-trip test, since this doesn't touch live credentials
  • examples/submit_order_with_attached builds and vets cleanly in the examples module
  • Not tested against a live API response (no sandbox credentials in this session)

🤖 Generated with Claude Code

Ports the attached order feature added to the Rust/Python/Node.js/Java/C/C++
SDKs in longbridge/openapi#549 (docs: longbridge/developers#1092).

New types: AttachedOrderType, AttachedOrderDetail, SubmitAttachedParams,
ReplaceAttachedParams. SubmitOrder/ReplaceOrder gain an AttachedParams field;
Order/OrderDetail gain an AttachedOrders field. New OrderDetailAttached and
CancelOrderAttached methods query/cancel an attached sub-order by its own
order ID (added as separate methods rather than changing the existing
signatures, since Go has no overloading/default params). GetTodayOrders
gains OrderId and IsAttached fields.

Breaking change: OrderDetail.ChargeDetail is now *OrderChargeDetail (was a
value type), since the server returns null for attached sub-orders.
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