Repository navigation
fix(spot): parse listStatus user data events (wrong event name, missing "O" orders array) - #822
Merged
Merged
Conversation
The spot user data stream never populated WsUserDataEvent.OCOUpdate: - UserDataEventTypeListStatus was "ListStatus", but the stream sends "e": "listStatus" (see the official payload example in user-data-stream.md), so the event-type switch in WsUserDataServe and WsUserDataServeSignature never matched and OCOUpdate stayed empty. - WsOCOUpdate.Orders had no json tag, so the "O" array of orders was dropped even when the struct was unmarshalled directly. Map "O" onto Orders via WsOCOOrderList.UnmarshalJSON/MarshalJSON so the existing field path (OCOUpdate.Orders.WsOCOOrders) keeps working, and fix the event-type constant. Add a test using the documented payload.
carlotestor
reviewed
Oct 29, 2026
carlotestor
left a comment
There was a problem hiding this comment.
Reviewed at b9ad63d. Looks correct to me.
- Event name: the spot user data stream sends
"e": "listStatus", so the old"ListStatus"constant could never match. Both dispatch sites (WsUserDataServeswitch at websocket_service.go:705 and the signature/WS-API path at :878) use the constant, so this one-line change fixes both, andexamples/websocket_user_data_signaturestarts working too. "O"array: the customUnmarshalJSON/MarshalJSONonWsOCOOrderListis a reasonable way to fix this without breakingevent.OCOUpdate.Orders.WsOCOOrders.nullor a missing"O"still leavesWsOCOOrdersnil. No other type embedsWsOCOOrderList, so nothing else is affected. UnmarshallingexecutionReport, whose"O"is the order creation time (int), is safe becauseOCOUpdateis only decoded forlistStatus.- The new test uses the documented payload and checks every field, including the nested orders.
Nits, not blocking:
- The
json:"O"tag onWsOCOOrderList.WsOCOOrdersis now dead because the custom (un)marshaller bypasses it. Consider dropping it to avoid confusion. - Changing the constant's value is technically observable to anyone who matched on the literal
"ListStatus". That code could never have fired, though, so it's worth a line in the changelog/release notes at most. - It would be worth adding a second
listStatuscase, e.g.ALL_DONE/REJECTwith"r"set, or an OTO payload, to cover non-OCO contingency types. Optional.
I couldn't run the suite on my side, so this is a static review.
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.
Problem
WsUserDataServe/WsUserDataServeSignaturenever populateWsUserDataEvent.OCOUpdatefor order-list (OCO/OTO/OTOCO) events:UserDataEventTypeListStatusis"ListStatus", but the stream sends"e": "listStatus"(payload example in the official docs: https://github.com/binance/binance-spot-api-docs/blob/master/user-data-stream.md#order-update, consistent with the other camelCase spot eventsexecutionReport,balanceUpdate,outboundAccountPosition). The event-type switch therefore never matches andOCOUpdatestays empty; user code comparing against the constant (as inexamples/websocket_user_data_signature) never fires either.WsOCOUpdate.Ordershas no json tag, so the top-level"O": [{ "s", "i", "c" }, ...]array is dropped and the order IDs / client order IDs of the list are never available.Fix
UserDataEventTypeListStatus = "listStatus"."O"ontoOrdersand giveWsOCOOrderListUnmarshalJSON/MarshalJSONthat treat it as the plain array, so the existing field pathevent.OCOUpdate.Orders.WsOCOOrderskeeps working (no public API change).Tests
TestWsUserDataServeListStatususing the documented payload; it fails on master (OCOUpdateempty) and passes with this change.go test -race ./...,go vet -structtag=false ./...andgofmt -lare clean.