-
Notifications
You must be signed in to change notification settings - Fork 779
feat: clean code #789
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
feat: clean code #789
Changes from all commits
3dc048c
20bf306
ca710f5
710492e
a01efdd
39fc1fa
3a86069
406d9e5
32690f2
447e045
7a3c43e
4314ba1
48e11d3
de2923f
9fb448d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,13 +13,15 @@ type Config struct { | |||||
| APIKey string | ||||||
| SecretKey string | ||||||
| UseTestnet bool | ||||||
| UseDemo bool | ||||||
| } | ||||||
|
|
||||||
| // Global configuration instance | ||||||
| var AppConfig = &Config{ | ||||||
| APIKey: getEnvOrDefault("BINANCE_API_KEY", ""), | ||||||
| SecretKey: getEnvOrDefault("BINANCE_SECRET_KEY", ""), | ||||||
| UseTestnet: getEnvOrDefault("BINANCE_USE_TESTNET", "true") == "true", | ||||||
| UseDemo: getEnvOrDefault("BINANCE_USE_DEMO", "true") == "true", | ||||||
|
||||||
| UseDemo: getEnvOrDefault("BINANCE_USE_DEMO", "true") == "true", | |
| UseDemo: getEnvOrDefault("BINANCE_USE_DEMO", "false") == "true", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "os/signal" | ||
|
|
||
| "github.com/adshao/go-binance/v2" | ||
| "github.com/adshao/go-binance/v2/futures" | ||
| ) | ||
|
|
||
| func WatchFuturesUserDataStream() { | ||
| futures.UseDemo = true | ||
| apiKey := "" | ||
| secret := "" | ||
| client := binance.NewFuturesClient(apiKey, secret) | ||
|
|
||
| listenKey, err := client.NewStartUserStreamService().Do(context.Background()) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
|
|
||
| userDataHandler := func(event *futures.WsUserDataEvent) { | ||
| fmt.Printf("Event: %s, Time: %d\n", event.Event, event.Time) | ||
|
|
||
| switch event.Event { | ||
| case futures.UserDataEventTypeAlgoUpdate: | ||
| fmt.Printf("ALGO update: %+v\n", event.AlgoUpdate) | ||
| case futures.UserDataEventTypeTradeLite: | ||
| fmt.Printf("Trade lite: %+v\n", event) | ||
| } | ||
| } | ||
|
|
||
| errHandler := func(err error) { | ||
| panic(err) | ||
| } | ||
|
|
||
| doneC, stopC, err := futures.WsUserDataServe(listenKey, userDataHandler, errHandler) | ||
| if err != nil { | ||
| fmt.Println(err) | ||
| return | ||
| } | ||
| c := make(chan os.Signal, 1) | ||
| signal.Notify(c, os.Interrupt) | ||
| select { | ||
| case <-c: | ||
| stopC <- struct{}{} | ||
| } | ||
| <-doneC | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -126,6 +126,7 @@ type FuturesAlgoOrderStatusType string | |
| var ( | ||
| BaseAPIMainURL = "https://api.binance.com" | ||
| BaseAPITestnetURL = "https://testnet.binance.vision" | ||
| BaseAPIDemoURL = "https://demo-api.binance.com" | ||
| ) | ||
|
|
||
| // SelfTradePreventionMode define self trade prevention strategy | ||
|
|
@@ -139,6 +140,9 @@ type MarginAccountBorrowRepayType string | |
| // UseTestnet switch all the API endpoints from production to the testnet | ||
| var UseTestnet = false | ||
|
|
||
| // UseDemo switch all the API endpoints from production to the demo | ||
| var UseDemo = false | ||
|
|
||
| // Global enums | ||
| const ( | ||
| SideTypeBuy SideType = "BUY" | ||
|
|
@@ -361,6 +365,9 @@ func getAPIEndpoint() string { | |
| if UseTestnet { | ||
| return BaseAPITestnetURL | ||
| } | ||
| if UseDemo { | ||
| return BaseAPIDemoURL | ||
| } | ||
| return BaseAPIMainURL | ||
|
Comment on lines
365
to
371
|
||
| } | ||
|
|
||
|
|
@@ -436,7 +443,7 @@ type Client struct { | |
| OrderCount common.OrderCount | ||
| } | ||
|
|
||
| func (c *Client) debug(format string, v ...interface{}) { | ||
| func (c *Client) debug(format string, v ...any) { | ||
| if c.Debug { | ||
| c.Logger.Printf(format, v...) | ||
| } | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,7 @@ type UserDataEventReasonType string | |
| var ( | ||
| BaseApiMainUrl = "https://dapi.binance.com" | ||
| BaseApiTestnetUrl = "https://testnet.binancefuture.com" | ||
| BaseApiDemoURL = "https://demo-dapi.binance.com" | ||
| ) | ||
|
|
||
| // Global enums | ||
|
|
@@ -180,6 +181,9 @@ func getApiEndpoint() string { | |
| if UseTestnet { | ||
| return BaseApiTestnetUrl | ||
| } | ||
| if UseDemo { | ||
| return BaseApiDemoURL | ||
| } | ||
| return BaseApiMainUrl | ||
|
Comment on lines
181
to
187
|
||
| } | ||
|
|
||
|
|
@@ -239,7 +243,7 @@ type Client struct { | |
| OrderCount common.OrderCount | ||
| } | ||
|
|
||
| func (c *Client) debug(format string, v ...interface{}) { | ||
| func (c *Client) debug(format string, v ...any) { | ||
| if c.Debug { | ||
| c.Logger.Printf(format, v...) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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