feat(trade): add attached order (take-profit/stop-loss) support#110
Draft
sunli829 wants to merge 1 commit into
Draft
feat(trade): add attached order (take-profit/stop-loss) support#110sunli829 wants to merge 1 commit into
sunli829 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
AttachedOrderType(ProfitTaker/StopLoss/Bracket),AttachedOrderDetail,SubmitAttachedParams,ReplaceAttachedParamsSubmitOrder/ReplaceOrder: newAttachedParamsfieldOrder/OrderDetail: newAttachedOrders []AttachedOrderDetailfieldTradeContext.OrderDetailAttached(orderId)/CancelOrderAttached(orderId)methods — query/cancel an attached sub-order by its own order ID. Added as separate methods rather than changingOrderDetail/CancelOrder's existing signatures, since Go has no method overloading or default parameters (other SDKs did this via optional/default params orimpl Into<Options>; Go's closest precedent is the C SDK's separatelb_trade_context_cancel_order_attachedfunction).GetTodayOrders: newOrderIdandIsAttachedfields (OrderIdwas previously missing entirely even though the API already supported it) — combined, treatsOrderIdas an attached sub-order ID and returns that sub-order as anOrderentryexamples/submit_order_with_attachedBreaking change
OrderDetail.ChargeDetailis now*OrderChargeDetail(was a value type), since the server returnsnullfor this field on attached sub-orders. Matches the same breaking change made upstream across all 6 languages.Note for reviewers
AttachedOrderDetail'sAttachedTypeDisplay,TriggerStatus, andTagfields 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, thelongbridge/developersdocs 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 ./...andgo vet ./trade/...jinzhu/copier-based JSON→domain-type conversion (nested pointer structs, slices of new struct types, nil-safety forChargeDetail/AttachedParams) via a temporary round-trip test, since this doesn't touch live credentialsexamples/submit_order_with_attachedbuilds and vets cleanly in theexamplesmodule🤖 Generated with Claude Code