OpenAPI specification for Binance cryptocurrency exchange REST API.
This API client was automatically generated by OpenXAPI using OpenAPI Generator.
Please do not edit the generated code manually.
If you need to update the API client, please submit an issue or a PR to OpenXAPI to update the OpenAPI specification or the Go client templates, and regenerate the API client.
| Category | Product | Package | Modules |
|---|---|---|---|
| REST API | Spot | github.com/openxapi/binance-go/rest/spot |
✅ Spot Trading ✅ Margin Trading ✅ Algo Trading ✅ Wallet ✅ Copy Trading ✅ Convert ✅ Sub Account ✅ Binance Link ✅ Futures Data ✅ Portfolio Margin Pro ✅ Staking ✅ Dual Investment ✅ Mining ✅ Crypto Loan ✅ VIP Loan ✅ C2C ✅ Fiat ✅ NFT ✅ Gift Card ✅ Rebate ✅ Simple Earn ✅ Binance Pay History |
| USDS-M Futures | github.com/openxapi/binance-go/rest/umfutures |
✅ USDS Margined Futures ✅ Binance Link |
|
| COIN-M Futures | github.com/openxapi/binance-go/rest/cmfutures |
✅ COIN Margined Futures | |
| Options | github.com/openxapi/binance-go/rest/options |
✅ Options | |
| Portfolio Margin | github.com/openxapi/binance-go/rest/pmargin |
✅ Portfolio Margin |
Feel free to contribute to this project by adding support for other products.
With OpenXAPI, you can add support for other products and generate API clients in different languages in a breeze.
Following is an example of how to use the spot API client, please refer to the sub-folders for other products for more details.
Install the REST module:
go get github.com/openxapi/binance-go/restOr install specific products:
# REST API for specific products
go get github.com/openxapi/binance-go/rest/spot
go get github.com/openxapi/binance-go/rest/umfutures
go get github.com/openxapi/binance-go/rest/cmfutures
go get github.com/openxapi/binance-go/rest/options
go get github.com/openxapi/binance-go/rest/pmarginimport (
spot "github.com/openxapi/binance-go/rest/spot"
)To use a proxy, set the environment variable HTTP_PROXY:
os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")Example
conf := spot.NewConfiguration()
client := spot.NewAPIClient(conf)
ctx := context.Background()
info, res, err := client.SpotAPI.GetExchangeInfoV3(ctx).Symbol("BTCUSDT").Execute()
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n", info)
fmt.Printf("%+v\n", res)The API client supports HMAC, RSA and Ed25519 authentication.
The authentication is calculated per request, so you can use different keys for different requests.
Example
conf := spot.NewConfiguration()
client := spot.NewAPIClient(conf)
ctx := context.Background()
// get API key from env
apiKey := os.Getenv("BINANCE_API_KEY")
auth := spot.NewAuth(apiKey)
auth.SetSecretKey(os.Getenv("BINANCE_SECRET_KEY"))
ctx, err = auth.ContextWithValue(ctx)
if err != nil {
fmt.Println(err)
}
// Get current time in millisecond
user, res, err := client.SpotAPI.GetAccountV3(ctx).Timestamp(time.Now().UnixMilli()).Execute()
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n", user)
fmt.Printf("%+v\n", res)Example
conf := spot.NewConfiguration()
client := spot.NewAPIClient(conf)
ctx := context.Background()
// get API key from env
apiKey := os.Getenv("BINANCE_API_KEY")
auth := spot.NewAuth(apiKey)
// Key type will be auto-detected, you can use RSA or Ed25519 key here
auth.PrivateKeyPath = "/path/to/your/private_key.pem"
ctx, err = auth.ContextWithValue(ctx)
if err != nil {
fmt.Println(err)
}
// Get current time in millisecond
user, res, err := client.SpotAPI.GetAccountV3(ctx).Timestamp(time.Now().UnixMilli()).Execute()
if err != nil {
fmt.Println(err)
}
fmt.Printf("%+v\n", user)
fmt.Printf("%+v\n", res)Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.
For using other server than the one defined on index 0 set context value spot.ContextServerIndex of type int.
ctx := context.WithValue(context.Background(), spot.ContextServerIndex, 1)