Skip to content

openxapi/binance-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go API client for Binance

Go Reference

OpenAPI specification for Binance cryptocurrency exchange.

Overview

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.

Supported Products

Product Package Modules
Spot github.com/openxapi/binance-go/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/umfutures USDS Margined Futures
Binance Link
COIN-M Futures github.com/openxapi/binance-go/cmfutures COIN Margined Futures
Options github.com/openxapi/binance-go/options Options
Portfolio Margin github.com/openxapi/binance-go/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.

Import

import (
    spot "github.com/openxapi/binance-go/spot"
)

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Usage

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)

Authentication

The API client supports HMAC, RSA and Ed25519 authentication.

The authentication is calculated per request, so you can use different keys for different requests.

HMAC

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)

RSA or Ed25519

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)

Configuration

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

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)

Packages

No packages published