Skip to content

Conversation

@sc0Vu
Copy link
Contributor

@sc0Vu sc0Vu commented Dec 11, 2025

changes:

  • futures: remove simplejson usage
  • add demo environment, can switch by UseDemo
  • fix stuck process when call WsUserDataServeSignature
  • rename interface{} to any

@sc0Vu sc0Vu requested a review from carlosmiei December 11, 2025 15:54
@sc0Vu sc0Vu force-pushed the clean-code-algo-order branch from 1de513b to 32690f2 Compare December 12, 2025 22:00

# There is a bug if we define the same json tag in the struct.
# Disable structtag temporarily.
# see: https://github.com/golang/go/issues/40102
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not a bug, is a feature

Duplicate json tags, making the intent of the code unclear.

think this

func TestSameJsonTag(t *testing.T) {
	data := []byte(`{
	"i":"1"
	}`)

	type V struct {
		Ii int    `json:"i"`
		S  string `json:"i"`
	}

	var v V
	if err := json.Unmarshal(data, &v); err != nil {
		t.Fatal(err)
	}
	if v.Ii != 0 {
		t.Errorf("i expected %d, got %d", 0, v.Ii)
	}
	if v.S != "1" {
		t.Errorf("i expected %s, got %s", "1", v.S)
	}
}

@0x0001
Copy link
Contributor

0x0001 commented Dec 15, 2025

Cannot remove simplejson
Because the Go language's JSON parser causes bug regression.
Like this

func TestCaseInsensitiveJsonTag(t *testing.T) {
	// before data
	data := []byte(`{
	"n":"1"
	}`)

	type V struct {
		Name string `json:"n"`
	}

	var v V
	if err := json.Unmarshal(data, &v); err != nil {
		t.Fatal(err)
	}
	if v.Name != "1" {
		t.Errorf("Name expected %s, got %s", "1", v.Name)
	}

	// after data
	data = []byte(`{
	"n":"1",
	"N":"2"
	}`)
	var v2 V
	if err := json.Unmarshal(data, &v2); err != nil {
		t.Fatal(err)
	}
	if v2.Name != "1" {
		t.Errorf("Name V2 expected %s, got %s", "1", v2.Name)
	}
}

--- FAIL: TestCaseInsensitiveJsonTag (0.00s)
json_test.go:135: Name V2 expected 1, got 2

@sc0Vu
Copy link
Contributor Author

sc0Vu commented Dec 15, 2025

@0x0001 The case sensitive tag would work if both n and N are defined. For example,

type V struct {
	Name string `json:"n"`
	Name2 string `json:"N"`
}

This issue may occur if a required key is missing in our code and the key is case-sensitive. However, I believe it should work correctly with the current JSON encoding.Or is there anything I might be missing?

@0x0001
Copy link
Contributor

0x0001 commented Dec 15, 2025

@0x0001 The case sensitive tag would work if both n and N are defined. For example,

type V struct {
	Name string `json:"n"`
	Name2 string `json:"N"`
}

This issue may occur if a required key is missing in our code and the key is case-sensitive. However, I believe it should work correctly with the current JSON encoding.Or is there anything I might be missing?

Yes, but we've had cases where binance updated the response and added new fields.

@0x0001
Copy link
Contributor

0x0001 commented Dec 15, 2025

maybe we can use json/v2 replace encoding/json

github.com/go-json-experiment/json

Since you are doing this work, I think we can replace all interface{} with any. What do you think?

@sc0Vu
Copy link
Contributor Author

sc0Vu commented Dec 16, 2025

@0x0001 I’m not sure it’s a good idea to use the v2 JSON given the case-sensitivity issue. If the Binance data were correct, we wouldn’t be facing this problem.

I've replaced interface{} to any.

@sc0Vu sc0Vu marked this pull request as ready for review December 17, 2025 07:31
@carlosmiei carlosmiei requested a review from Copilot January 19, 2026 10:02
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request implements code cleanup and several enhancements to the Binance Go SDK. The changes focus on modernizing the codebase, adding demo environment support, fixing a process deadlock issue, and removing the simplejson dependency.

Changes:

  • Replaced interface{} with any throughout the codebase for better readability (Go 1.18+)
  • Added demo environment support with new UseDemo flag and corresponding endpoints across all API modules
  • Fixed a stuck process issue in WsUserDataServeSignature by adding a goroutine to properly handle connection closure
  • Removed simplejson dependency in futures and portfolio packages, using standard JSON unmarshaling with proper struct tags

Reviewed changes

Copilot reviewed 51 out of 51 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
v2/websocket_service.go Added demo endpoints and fixed stuck process with proper connection cleanup goroutine
v2/client.go Added UseDemo flag and demo API endpoint with selection logic
v2/request.go Replaced interface{} with any in params and method signatures
v2/futures/websocket_service.go Removed simplejson dependency, added JSON tags to structs, added demo endpoint support
v2/futures/client.go Added demo API endpoint and selection logic
v2/futures/exchange_info_service.go Replaced interface{} with any in struct field types
v2/delivery/websocket_service.go Added demo endpoint support and replaced interface{} with any
v2/delivery/client.go Added demo API endpoint and selection logic
v2/delivery/exchange_info_service.go Replaced interface{} with any in struct field types
v2/options/websocket_service.go Added demo endpoint constants (empty) and replaced interface{} with any
v2/options/exchange_info_service.go Replaced interface{} with any in struct field types
v2/portfolio/websocket_service.go Removed simplejson dependency and added JSON tag
v2/common/websocket/types.go Replaced interface{} with any in request parameters
examples/config.go Added UseDemo configuration with default value
examples/watcher_futures.go New example demonstrating futures user data stream with demo environment
check.sh Added go vet structtag=false flag to work around JSON tag issue

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 38 to 44
if UseTestnet {
return baseWsTestnetUrl
}
if UseDemo {
return baseWsDemoUrl
}
return baseWsMainUrl
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. However, since the demo URLs are empty strings, returning an empty string when UseDemo is true will cause connection failures. Consider adding validation to prevent UseDemo from being used when the endpoint is not configured.

Copilot uses AI. Check for mistakes.
Comment on lines 55 to 61
if UseTestnet {
return BaseWsTestnetURL
}
if UseDemo {
return BaseWsDemoURL
}
return BaseWsMainURL
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines 66 to 72
if UseTestnet {
return BaseCombinedTestnetURL
}
if UseDemo {
return BaseCombinedDemoURL
}
return BaseCombinedMainURL
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines 1186 to 1192
if UseTestnet {
return BaseWsApiTestnetURL
}
if UseDemo {
return BaseWsApiDemoURL
}
return BaseWsApiMainURL
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
APIKey: getEnvOrDefault("BINANCE_API_KEY", ""),
SecretKey: getEnvOrDefault("BINANCE_SECRET_KEY", ""),
UseTestnet: getEnvOrDefault("BINANCE_USE_TESTNET", "true") == "true",
UseDemo: getEnvOrDefault("BINANCE_USE_DEMO", "true") == "true",
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The default value for UseDemo is set to "true", which means the demo environment will be used by default when BINANCE_USE_DEMO is not set. This is likely unintended as most users would expect the production environment by default. Consider changing the default to "false".

Suggested change
UseDemo: getEnvOrDefault("BINANCE_USE_DEMO", "true") == "true",
UseDemo: getEnvOrDefault("BINANCE_USE_DEMO", "false") == "true",

Copilot uses AI. Check for mistakes.
Comment on lines 67 to 73
if UseTestnet {
return BaseCombinedTestnetURL
}
if UseDemo {
return BaseCombinedDemoURL
}
return BaseCombinedMainURL
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines 219 to 225
if UseTestnet {
return BaseApiTestnetUrl
}
if UseDemo {
return BaseApiDemoURL
}
return BaseApiMainUrl
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines 181 to 187
if UseTestnet {
return BaseApiTestnetUrl
}
if UseDemo {
return BaseApiDemoURL
}
return BaseApiMainUrl
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines 35 to 41
if UseTestnet {
return BaseWsTestnetUrl
}
if UseDemo {
return BaseWsDemoURL
}
return BaseWsMainUrl
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
Comment on lines 365 to 371
if UseTestnet {
return BaseAPITestnetURL
}
if UseDemo {
return BaseAPIDemoURL
}
return BaseAPIMainURL
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The endpoint selection logic has a potential issue: if both UseTestnet and UseDemo are set to true, UseTestnet takes precedence and UseDemo is ignored. Consider adding validation to ensure only one environment flag is active at a time, or document this priority explicitly.

Copilot uses AI. Check for mistakes.
@carlosmiei carlosmiei merged commit 36a1f70 into ccxt:master Jan 19, 2026
8 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