Skip to content

fix: portfolio websocket EventType parsing error #723

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 17, 2025

Conversation

feeeei
Copy link
Contributor

@feeeei feeeei commented Jun 16, 2025

This is a known bug in Go's encoding/json standard library: the package ignores case sensitivity when parsing JSON struct tags.

Minimal reproduction example:

package main
import (
	"encoding/json"
	"fmt"
)
func main() {
	var event struct {
		EventType string `json:"e"`
	}
	// JSON contains same field with different cases
	message := []byte(`{"e":"listenKeyExpired","E":1750063270815}`)
	if err := json.Unmarshal(message, &event); err != nil {
		fmt.Println(err) // outout: json: cannot unmarshal number into Go struct field .e of type string
	}
	fmt.Println(event)
}

Related Go official issue:
golang/go#14750

The simplest current workaround is to ensure struct member names exactly match the JSON field case.

@carlosmiei
Copy link
Collaborator

@feeeei Thanks a lot for fixing it, we will review and merge it shortly.

@feeeei
Copy link
Contributor Author

feeeei commented Jun 17, 2025

@carlosmiei

The current Portfolio WebSocket code appears to be copied from the Futures module without thorough real-world testing.

Specific issues include:

  1. The actual WebSocket returns a numeric timestamp (e.g., "E": 1750142342023), but tests artificially changed it to a string type to avoid reproducing the bug;
  2. In USER-DATA streams:
  • The position field in ACCOUNT_UPDATE events contained incorrect data;
  • ORDER_TRADE_UPDATE events lacked critical fields like wt and ot.

API DOCS LINK:

All mentioned issues have been fixed.

@carlosmiei
Copy link
Collaborator

@feeeei Thanks once again

@carlosmiei carlosmiei merged commit 00cb80c into ccxt:master Jun 17, 2025
2 checks passed
@feeeei feeeei deleted the fix/event_type branch June 23, 2025 14:47
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.

None yet

2 participants