Skip to content

Fix MARGIN_CALL decode when position list 'p' is a JSON string (#687) - #820

Open
viaweb3 wants to merge 1 commit into
ccxt:masterfrom
viaweb3:fix/futures-margin-call-string-positions
Open

viaweb3 wants to merge 1 commit into
ccxt:masterfrom
viaweb3:fix/futures-margin-call-string-positions

Conversation

@viaweb3

@viaweb3 viaweb3 commented Aug 12, 2026

Copy link
Copy Markdown

Summary

Fixes #687 — futures.WsUserDataServe occasionally returns an error:

json: cannot unmarshal string into Go struct field .p of type []futures.WsPosition

The exchange sometimes sends the MARGIN_CALL event's position list (p) as a JSON string ("null" or "") instead of an array. The default decoder fails on that, which tears down the user-data websocket stream.

Changes

  • Added a tolerant WsPositionSlice type with a custom UnmarshalJSON that treats a string value as an empty list (the field is non-essential for margin-call handling).
  • Applied it to the MarginCallPositions (json:"p") field in the futures, delivery and portfolio user-data event structs (identical schema, same bug class).
  • Added regression tests for both the "null" and "" cases.

Verification

go test ./futures/ ./delivery/ ./portfolio/ — all pass, including the two new tests that previously reproduced the decode error. go build ./... and go vet are clean.

Fixes #687

…cxt#687)

The exchange occasionally sends the MARGIN_CALL event's position list 'p'
as a JSON string (e.g. "null" or "") instead of an array. The default
decoder then fails with:

  json: cannot unmarshal string into Go struct field .p of type []futures.WsPosition

This drops the user-data stream. Add a tolerant WsPositionSlice type that
treats a string value as an empty list, and use it for the
MarginCallPositions field in the futures, delivery and portfolio
user-data event structs (all share the same schema).

Add regression tests covering the string ("null") and empty-string cases.

Fixes ccxt#687
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.

json: cannot unmarshal string into Go struct field .p of type []futures.WsPosition

1 participant