### Install Spot Connector Source: https://github.com/binance/binance-connector-go/blob/main/README.md Example of how to install the Spot connector using go get. ```bash go get github.com/binance/binance-connector-go/clients/spot ``` -------------------------------- ### Install Multiple Connectors Source: https://github.com/binance/binance-connector-go/blob/main/README.md Example of how to install multiple connectors simultaneously using go get. ```bash go get github.com/binance/binance-connector-go/clients/spot github.com/binance/binance-connector-go/clients/margintrading github.com/binance/binance-connector-go/clients/wallet ``` -------------------------------- ### Installation Source: https://github.com/binance/binance-connector-go/blob/main/clients/wallet/docs/migration-guide.md Instructions to uninstall the old package and install the new one. ```bash rm $(which binance-connector-go) go get github.com/binance/binance-connector-go/clients/wallet ``` -------------------------------- ### Installation Source: https://github.com/binance/binance-connector-go/blob/main/clients/spot/docs/migration-guide.md Uninstall the old package and install the new one. ```bash rm $(which binance-connector-go) go get github.com/binance/binance-connector-go/clients/spot ``` -------------------------------- ### Get NFT Asset Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/nft/README.md Example of how to use the Binance NFT client to get NFT asset information. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/nft" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetNFTAsset() } func GetNFTAsset() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.NFTRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := client.NewBinanceNFTClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.NFTAPI.GetNFTAsset(context.Background()).Execute() if err != nil { log.Println(err) return } rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### StartUserDataStream Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/derivativestradingcoinfutures/src/restapi/docs/UserDataStreamsAPI.md This Go code snippet demonstrates how to start a user data stream using the Binance Connector for Go. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/derivativestradingcoinfutures" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceDerivativesTradingCoinFuturesClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.UserDataStreamsAPI.StartUserDataStream(context.Background()).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `UserDataStreamsAPI.StartUserDataStream``: %v\n", err) return } // response from `StartUserDataStream`: StartUserDataStreamResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Daily Account Snapshot Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/wallet/src/restapi/docs/AccountAPI.md This example shows how to get a daily account snapshot using the AccountAPI. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/wallet" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { type_ := "type__example" // string | startTime := int64(1623319461670) // int64 | (optional) endTime := int64(1641782889000) // int64 | (optional) limit := int64(7) // int64 | min 7, max 30, default 7 (optional) recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceWalletClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.AccountAPI.DailyAccountSnapshot(context.Background()).Type(type_).StartTime(startTime).EndTime(endTime).Limit(limit).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `AccountAPI.DailyAccountSnapshot``: %v\n", err) return } // response from `DailyAccountSnapshot`: DailyAccountSnapshotResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Client Initialization - New Source: https://github.com/binance/binance-connector-go/blob/main/clients/margintrading/docs/migration-guide.md Example of initializing the client with the new modularized Margin Trading Connector. ```go configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.MarginTradingRestApiProdUrl), ) client := wallet.NewBinanceWalletClient(wallet.WithRestAPI(configuration)) ``` -------------------------------- ### Installation Source: https://github.com/binance/binance-connector-go/blob/main/clients/fiat/docs/migration-guide.md Uninstall the old package and install the new one. ```bash rm $(which binance-connector-go) go get github.com/binance/binance-connector-go/clients/fiat ``` -------------------------------- ### Installation Source: https://github.com/binance/binance-connector-go/blob/main/clients/margintrading/docs/migration-guide.md Commands to uninstall the old package and install the new modularized Margin Trading Connector. ```bash rm $(which binance-connector-go) go get github.com/binance/binance-connector-go/clients/margintrading ``` -------------------------------- ### Installation Source: https://github.com/binance/binance-connector-go/blob/main/clients/subaccount/docs/migration-guide.md Uninstall the old package and install the new one. ```bash rm $(which binance-connector-go) go get github.com/binance/binance-connector-go/clients/subaccount ``` -------------------------------- ### Install binance-common package Source: https://github.com/binance/binance-connector-go/blob/main/common/README.md Command to install the binance-common utility package using go get. ```bash go get github.com/binance/binance-connector-go/common ``` -------------------------------- ### Get Exchange Info Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/alpha/README.md This example demonstrates how to fetch exchange information using the Binance Go Alpha SDK. It includes setting up the configuration, creating the client, executing the request, and logging the response. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/alpha" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetExchangeInfo() } func GetExchangeInfo() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.AlphaRestApiProdUrl), common.WithApiKey("Your API Key"), ) apiClient := client.NewBinanceAlphaClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.MarketDataAPI.GetExchangeInfo(context.Background()).Execute() if err != nil { log.Println(err) return } rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Start User Data Stream Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/derivativestradingcoinfutures/src/websocketapi/docs/UserDataStreamsAPI.md This Go code snippet demonstrates how to start a user data stream using the Binance Connector Go library. It includes connecting to the WebSocket, sending the request, and handling the response. ```go package main import ( "log" "os" models "github.com/binance/binance-connector-go/clients/derivativestradingcoinfutures" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { id := "e9d6b4349871b40611412680b3445fac" // string Unique WebSocket request ID. (optional) configuration := common.NewConfigurationWebsocketApi( common.WithWsApiBasePath(common.SpotWebsocketApiProdUrl), common.WithWsApiKey("Your API Key"), common.WithWsApiSecret("Your API Secret"), ) wsClient := models.NewBinanceDerivativesTradingCoinFuturesClient(models.WithWebsocketAPI(configuration)) // Connect to WebSocket err := wsClient.WebsocketAPI.Connect() if err != nil { log.Printf("Error connecting to WebSocket: %v\n", err) return } resp, err := wsClient.WebsocketAPI.UserDataStreamsAPI.StartUserDataStream().Id(id).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `UserDataStreamsAPI.StartUserDataStream``: %v\n", err) return } result, _ := json.MarshalIndent(resp.Typed, "", " ") log.Printf("Result: %s\n", result) err = wsClient.WebsocketAPI.CloseWebSocketConnection() if err != nil { log.Printf("Error closing WebSocket connection: %v\n", err) return } } ``` -------------------------------- ### Update Client Initialization - Migration Step Source: https://github.com/binance/binance-connector-go/blob/main/clients/margintrading/docs/migration-guide.md Example of updating client initialization code during migration. ```go configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.MarginTradingRestApiProdUrl), ) client := margintrading.NewBinanceMarginTradingClient(margintrading.WithRestAPI(configuration)) ``` -------------------------------- ### Migration Step 3: Update Client Initialization Source: https://github.com/binance/binance-connector-go/blob/main/clients/wallet/docs/migration-guide.md Example of updating client initialization code for the new modular wallet client. ```go client := binance.NewClient(apiKey, secretKey, baseURL) to: configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.WalletRestApiProdUrl), ) client := wallet.NewBinanceWalletClient(wallet.WithRestAPI(configuration)) ``` -------------------------------- ### FlexibleLoanAdjustLtv Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/cryptoloan/src/restapi/docs/FlexibleRateAPI.md Example of how to use the FlexibleLoanAdjustLtv method. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/cryptoloan" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { loanCoin := "loanCoin_example" // string | collateralCoin := "collateralCoin_example" // string | adjustmentAmount := float32(1.0) // float32 | direction := "direction_example" // string | "ADDITIONAL", "REDUCED" recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceCryptoLoanClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.FlexibleRateAPI.FlexibleLoanAdjustLtv(context.Background()).LoanCoin(loanCoin).CollateralCoin(collateralCoin).AdjustmentAmount(adjustmentAmount).Direction(direction).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `FlexibleRateAPI.FlexibleLoanAdjustLtv``: %v\n", err) return } // response from `FlexibleLoanAdjustLtv`: FlexibleLoanAdjustLtvResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Get BFUSD Redemption History Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/simpleearn/src/restapi/docs/BfusdAPI.md This Go code snippet illustrates how to fetch BFUSD redemption history using the Binance Connector Go library. It shows the setup of parameters and the execution of the API call, similar to the rate history example. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/simpleearn" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { startTime := int64(1623319461670) // int64 | (optional) endTime := int64(1641782889000) // int64 | (optional) current := int64(1) // int64 | Currently querying page. Starts from 1. Default: 1 (optional) size := int64(10) // int64 | Number of results per page. Default: 10, Max: 100 (optional) recvWindow := int64(5000) // int64 | The value cannot be greater than 60000 (ms) (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceSimpleEarnClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.BfusdAPI.GetBfusdRedemptionHistory(context.Background()).StartTime(startTime).EndTime(endTime).Current(current).Size(size).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `BfusdAPI.GetBfusdRedemptionHistory``: %v\n", err) return } // response from `GetBfusdRedemptionHistory`: GetBfusdRedemptionHistoryResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/spot/docs/restapi/proxy.md This Go code snippet shows how to initialize the Binance Spot client with proxy settings. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/spot/src" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { ExchangeInfo() } func ExchangeInfo() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceSpotClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.GeneralAPI.ExchangeInfo(context.Background()).Symbol("BTCUSDT").Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### GetFlexibleSubscriptionPreview Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/simpleearn/src/restapi/docs/FlexibleLockedAPI.md Example Go code to get a preview of a flexible subscription using the Binance Simple Earn Go Client. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/simpleearn" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { productId := "1" // string | amount := float32(1.0) // float32 | Amount recvWindow := int64(5000) // int64 | The value cannot be greater than 60000 (ms) (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceSimpleEarnClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.FlexibleLockedAPI.GetFlexibleSubscriptionPreview(context.Background()).ProductId(productId).Amount(amount).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `FlexibleLockedAPI.GetFlexibleSubscriptionPreview``: %v\n", err) return } // response from `GetFlexibleSubscriptionPreview`: GetFlexibleSubscriptionPreviewResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/copytrading/docs/restapi/proxy.md Example Go code showing how to set up a proxy for the Binance Copy Trading client. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/copytrading" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetFuturesLeadTraderStatus() } func GetFuturesLeadTraderStatus() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.CopyTradingRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceCopyTradingClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.FutureCopyTradingAPI.GetFuturesLeadTraderStatus(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### GetWbethWrapHistory Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/staking/src/restapi/docs/EthStakingAPI.md Example of how to get WBETH wrap history. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/staking" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { startTime := int64(1623319461670) // int64 | (optional) endTime := int64(1641782889000) // int64 | (optional) current := int64(1) // int64 | Currently querying page. Start from 1. Default:1 (optional) size := int64(10) // int64 | Default:10, Max:100 (optional) recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceStakingClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.EthStakingAPI.GetWbethWrapHistory(context.Background()).StartTime(startTime).EndTime(endTime).Current(current).Size(size).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `EthStakingAPI.GetWbethWrapHistory``: %v\n", err) return } // response from `GetWbethWrapHistory`: GetWbethWrapHistoryResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/algo/docs/restapi/proxy.md This Go code snippet shows how to set up a proxy configuration when initializing the Binance Algo client. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/algo" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { QueryHistoricalAlgoOrdersSpotAlgo() } func QueryHistoricalAlgoOrdersSpotAlgo() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.AlgoRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceAlgoClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.SpotAlgoAPI.QueryHistoricalAlgoOrdersSpotAlgo(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Agent Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/derivativestradingusdsfutures/docs/websocketapi/agent.md This Go code snippet shows how to initialize the Binance Derivatives Trading USD Futures client with a custom agent (proxy URL) and then execute a request to get position information. ```go package main import ( "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/derivativestradingusdsfutures" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { NewConfigurationWebsocketApi() } func NewConfigurationWebsocketApi() { configuration := common.NewConfigurationWebsocketApi( common.WithWsApiBasePath(common.DerivativesTradingUsdsFuturesWebsocketApiProdUrl), common.WithWsAgent("your-proxy-url"), ) wsClient := client.NewBinanceDerivativesTradingUsdsFuturesClient( client.WithWebsocketAPI(configuration), ) err := wsClient.WebsocketAPI.Connect() if err != nil { log.Printf("Error connecting to WebSocket: %v\n", err) return } responseChan, errorChan, err := wsClient.WebsocketAPI.TradeAPI.PositionInformation().ExecuteAsync() if err != nil { log.Printf("Error executing position information request: %v\n", err) return } select { case resp := <-responseChan: result, _ := json.MarshalIndent(resp.Typed, "", " ") log.Printf("Result: %s\n", result) case err := <-errorChan: log.Printf("Error: %v\n", err) } err = wsClient.WebsocketAPI.CloseWebSocketConnection() if err != nil { log.Printf("Error closing WebSocket connection: %v\n", err) return } } ``` -------------------------------- ### GetWbethUnwrapHistory Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/staking/src/restapi/docs/EthStakingAPI.md Example of how to get WBETH unwrap history. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/staking" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { startTime := int64(1623319461670) // int64 | (optional) endTime := int64(1641782889000) // int64 | (optional) current := int64(1) // int64 | Currently querying page. Start from 1. Default:1 (optional) size := int64(10) // int64 | Default:10, Max:100 (optional) recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceStakingClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.EthStakingAPI.GetWbethUnwrapHistory(context.Background()).StartTime(startTime).EndTime(endTime).Current(current).Size(size).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `EthStakingAPI.GetWbethUnwrapHistory``: %v\n", err) return } // response from `GetWbethUnwrapHistory`: GetWbethUnwrapHistoryResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/cryptoloan/docs/restapi/proxy.md This Go code snippet shows how to initialize the Binance Crypto Loan client with proxy settings. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/cryptoloan" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetFlexibleLoanBorrowHistory() } func GetFlexibleLoanBorrowHistory() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.CryptoLoanRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceCryptoLoanClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.FlexibleRateAPI.GetFlexibleLoanBorrowHistory(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/margintrading/docs/restapi/proxy.md This Go code snippet shows how to initialize the Binance Margin Trading client with proxy settings. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/margintrading" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetSummaryOfMarginAccount() } func GetSummaryOfMarginAccount() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.MarginTradingRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceMarginTradingClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.AccountAPI.GetSummaryOfMarginAccount(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### SolStakingAccount Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/staking/src/restapi/docs/SolStakingAPI.md Example of how to get SOL staking account information. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/staking" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceStakingClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.SolStakingAPI.SolStakingAccount(context.Background()).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `SolStakingAPI.SolStakingAccount``: %v\n", err) return } // response from `SolStakingAccount`: SolStakingAccountResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### FlexibleLoanBorrow Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/cryptoloan/src/restapi/docs/FlexibleRateAPI.md Example of how to use the FlexibleLoanBorrow method. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/cryptoloan" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { loanCoin := "loanCoin_example" // string | collateralCoin := "collateralCoin_example" // string | loanAmount := float32(1.0) // float32 | Mandatory when collateralAmount is empty (optional) collateralAmount := float32(1.0) // float32 | Mandatory when loanAmount is empty (optional) recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceCryptoLoanClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.FlexibleRateAPI.FlexibleLoanBorrow(context.Background()).LoanCoin(loanCoin).CollateralCoin(collateralCoin).LoanAmount(loanAmount).CollateralAmount(collateralAmount).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `FlexibleRateAPI.FlexibleLoanBorrow``: %v\n", err) return } // response from `FlexibleLoanBorrow`: FlexibleLoanBorrowResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### GetUnclaimedRewards Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/staking/src/restapi/docs/SolStakingAPI.md Example of how to get unclaimed SOL staking rewards. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/staking" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceStakingClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.SolStakingAPI.GetUnclaimedRewards(context.Background()).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `SolStakingAPI.GetUnclaimedRewards``: %v\n", err) return } // response from `GetUnclaimedRewards`: GetUnclaimedRewardsResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/derivativestradingportfoliomargin/docs/restapi/proxy.md This Go code snippet shows how to initialize the BinanceDerivativesTradingPortfolioMarginClient with proxy settings. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/derivativestradingportfoliomargin" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { AccountInformation() } func AccountInformation() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.DerivativesTradingPortfolioMarginRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceDerivativesTradingPortfolioMarginClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.AccountAPI.AccountInformation(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Migration Steps: Replace the old package with the new one Source: https://github.com/binance/binance-connector-go/blob/main/clients/fiat/docs/migration-guide.md Commands to edit go.mod and get the new Fiat package and common package. ```bash go mod edit -dropreplace github.com/binance/binance-connector-go go get github.com/binance/binance-connector-go/clients/fiat go get github.com/binance/binance-connector-go/common ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/c2c/docs/restapi/proxy.md This Go code snippet shows how to set up a proxy for the Binance C2C client. It includes importing necessary packages, creating a configuration with proxy details, and making a request to get C2C trade history. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/c2c" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetC2CTradeHistory() } func GetC2CTradeHistory() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.C2CRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceC2CClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.C2CAPI.GetC2CTradeHistory(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/nft/docs/restapi/proxy.md This Go code snippet shows how to set up a proxy configuration when initializing the Binance NFT client. ```Go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/nft" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetNFTAsset() } func GetNFTAsset() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.NFTRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceNFTClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.NFTAPI.GetNFTAsset(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### GetOpenSymbolList Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/wallet/src/restapi/docs/AssetAPI.md Example of how to get open symbol list using AssetAPI. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/wallet" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceWalletClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.AssetAPI.GetOpenSymbolList(context.Background()).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `AssetAPI.GetOpenSymbolList``: %v\n", err) return } // response from `GetOpenSymbolList`: GetOpenSymbolListResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### AcquiringAlgorithm Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/mining/src/restapi/docs/MiningAPI.md This Go code snippet demonstrates how to use the AcquiringAlgorithm method of the MiningAPI to fetch acquiring algorithm information. It shows the setup of the API client and execution of the request. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/mining" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceMiningClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.MiningAPI.AcquiringAlgorithm(context.Background()).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `MiningAPI.AcquiringAlgorithm``: %v\n", err) return } // response from `AcquiringAlgorithm`: AcquiringAlgorithmResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/viploan/docs/restapi/proxy.md This Go code snippet shows how to initialize the Binance VIP Loan client with proxy settings. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/viploan" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { GetCollateralAssetData() } func GetCollateralAssetData() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.VipLoanRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceVipLoanClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.MarketDataAPI.GetCollateralAssetData(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Get Trades Source: https://github.com/binance/binance-connector-go/blob/main/clients/spot/src/restapi/docs/MarketAPI.md Example of how to get recent trades for a symbol using the Market API. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/spot" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { symbol := "BNBUSDT" // string | limit := int32(500) // int32 | Default: 500; Maximum: 1000. (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceSpotClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.MarketAPI.GetTrades(context.Background()).Symbol(symbol).Limit(limit).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `MarketAPI.GetTrades``: %v\n", err) return } // response from `GetTrades`: GetTradesResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### GetIpRestrictionForASubAccountApiKey Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/subaccount/src/restapi/docs/ApiManagementAPI.md Example of how to get IP restriction details for a sub-account API key. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/subaccount" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { email := "sub-account-email@email.com" // string | [Sub-account email](#email-address) subAccountApiKey := "subAccountApiKey_example" // string | recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceSubAccountClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.ApiManagementAPI.GetIpRestrictionForASubAccountApiKey(context.Background()).Email(email).SubAccountApiKey(subAccountApiKey).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `ApiManagementAPI.GetIpRestrictionForASubAccountApiKey``: %v\n", err) return } // response from `GetIpRestrictionForASubAccountApiKey`: GetIpRestrictionForASubAccountApiKeyResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Proxy Configuration Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/derivativestradingoptions/docs/restapi/proxy.md This Go code snippet shows how to set up a proxy configuration for the Binance Derivatives Trading Options client. ```go package main import ( "context" "encoding/json" "log" client "github.com/binance/binance-connector-go/clients/derivativestradingoptions" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { OptionAccountInformation() } func OptionAccountInformation() { configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.DerivativesTradingOptionsRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), common.WithProxy(common.ProxyConfig{ Host: "127.0.0.1", Port: 8080, Protocol: "http", }), ) apiClient := client.NewBinanceDerivativesTradingOptionsClient( client.WithRestAPI(configuration), ) resp, err := apiClient.RestApi.AccountAPI.OptionAccountInformation(context.Background()).Execute() if err != nil { log.Println(err) return } dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### WrapBeth Example Source: https://github.com/binance/binance-connector-go/blob/main/clients/staking/src/restapi/docs/EthStakingAPI.md Example code for wrapping BETH. ```go package main import ( "context" "encoding/json" "log" "os" models "github.com/binance/binance-connector-go/clients/staking" "github.com/binance/binance-connector-go/common/v2/common" ) func main() { amount := float32(1.0) // float32 | Amount in SOL. recvWindow := int64(5000) // int64 | (optional) configuration := common.NewConfigurationRestAPI( common.WithBasePath(common.SpotRestApiProdUrl), common.WithApiKey("Your API Key"), common.WithApiSecret("Your API Secret"), ) apiClient := models.NewBinanceStakingClient(models.WithRestAPI(configuration)) resp, err := apiClient.RestApi.EthStakingAPI.WrapBeth(context.Background()).Amount(amount).RecvWindow(recvWindow).Execute() if err != nil { log.Println(os.Stderr, "Error when calling `EthStakingAPI.WrapBeth``: %v\n", err) return } // response from `WrapBeth`: WrapBethResponse rateLimitsValue, _ := json.MarshalIndent(resp.RateLimits, "", " ") log.Printf("Rate limits: %s\n", string(rateLimitsValue)) dataValue, _ := json.MarshalIndent(resp.Data, "", " ") log.Printf("Response: %s\n", string(dataValue)) } ``` -------------------------------- ### Migration Step 1: Replace the old package with the new one Source: https://github.com/binance/binance-connector-go/blob/main/clients/subaccount/docs/migration-guide.md Commands to edit go.mod and get the new packages. ```bash go mod edit -dropreplace github.com/binance/binance-connector-go go get github.com/binance/binance-connector-go/clients/subaccount go get github.com/binance/binance-connector-go/common ```