Skip to content

fix(spot): parse listStatus user data events (wrong event name, missing "O" orders array) - #822

Merged
carlosmiei merged 1 commit into
ccxt:masterfrom
l3xxxy:fix/ws-list-status-orders
Oct 29, 2026
Merged

carlosmiei merged 1 commit into
ccxt:masterfrom
l3xxxy:fix/ws-list-status-orders

Conversation

@l3xxxy

@l3xxxy l3xxxy commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Problem

WsUserDataServe / WsUserDataServeSignature never populate WsUserDataEvent.OCOUpdate for order-list (OCO/OTO/OTOCO) events:

  1. UserDataEventTypeListStatus is "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 events executionReport, balanceUpdate, outboundAccountPosition). The event-type switch therefore never matches and OCOUpdate stays empty; user code comparing against the constant (as in examples/websocket_user_data_signature) never fires either.
  2. WsOCOUpdate.Orders has 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".
  • Map "O" onto Orders and give WsOCOOrderList UnmarshalJSON/MarshalJSON that treat it as the plain array, so the existing field path event.OCOUpdate.Orders.WsOCOOrders keeps working (no public API change).

Tests

  • Added TestWsUserDataServeListStatus using the documented payload; it fails on master (OCOUpdate empty) and passes with this change.
  • go test -race ./..., go vet -structtag=false ./... and gofmt -l are clean.

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.
@carlosmiei carlosmiei self-assigned this Oct 29, 2026

@carlotestor carlotestor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (WsUserDataServe switch at websocket_service.go:705 and the signature/WS-API path at :878) use the constant, so this one-line change fixes both, and examples/websocket_user_data_signature starts working too.
  • "O" array: the custom UnmarshalJSON/MarshalJSON on WsOCOOrderList is a reasonable way to fix this without breaking event.OCOUpdate.Orders.WsOCOOrders. null or a missing "O" still leaves WsOCOOrders nil. No other type embeds WsOCOOrderList, so nothing else is affected. Unmarshalling executionReport, whose "O" is the order creation time (int), is safe because OCOUpdate is only decoded for listStatus.
  • The new test uses the documented payload and checks every field, including the nested orders.

Nits, not blocking:

  1. The json:"O" tag on WsOCOOrderList.WsOCOOrders is now dead because the custom (un)marshaller bypasses it. Consider dropping it to avoid confusion.
  2. 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.
  3. It would be worth adding a second listStatus case, e.g. ALL_DONE/REJECT with "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.

@carlosmiei
carlosmiei merged commit 8120d83 into ccxt:master Oct 29, 2026
2 checks passed
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.

3 participants