Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Go API client for cmfutures

OpenAPI specification for Binance exchange - Cmfutures API

Overview

This API client was generated by the OpenAPI Generator project.

Please do not edit the generated code manually, but rather regenerate it from OpenXAPI.

  • API version: 0.3.0
  • Package version: 0.3.0

Installation

Put the package under your project folder and add the following in import:

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

To use a proxy, set the environment variable HTTP_PROXY:

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

Usage

Example

conf := cmfutures.NewConfiguration()
client := cmfutures.NewAPIClient(conf)
ctx := context.Background()

info, res, err := client.SpotTradingAPI.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 := cmfutures.NewConfiguration()
client := cmfutures.NewAPIClient(conf)
ctx := context.Background()

// get API key from env
apiKey := os.Getenv("BINANCE_API_KEY")
auth := cmfutures.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.SpotTradingAPI.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 := cmfutures.NewConfiguration()
client := cmfutures.NewAPIClient(conf)
ctx := context.Background()

// get API key from env
apiKey := os.Getenv("BINANCE_API_KEY")
auth := cmfutures.NewAuth(apiKey)
// Key type will be auto-detected, you can use RSA or Ed25519 key here
auth.PrivateKeyPath = "/local/.keys/binance_api_test_private_key.pem"
ctx, err = auth.ContextWithValue(ctx)
if err != nil {
    fmt.Println(err)
}
// Get current time in millisecond
user, res, err := client.SpotTradingAPI.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 cmfutures.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), cmfutures.ContextServerIndex, 1)

Documentation for API Endpoints

All URIs are relative to https://dapi.binance.com

Class Method HTTP request Description
FuturesAPI CreateBatchOrdersV1 Post /dapi/v1/batchOrders Place Multiple Orders(TRADE)
FuturesAPI CreateCountdownCancelAllV1 Post /dapi/v1/countdownCancelAll Auto-Cancel All Open Orders (TRADE)
FuturesAPI CreateLeverageV1 Post /dapi/v1/leverage Change Initial Leverage (TRADE)
FuturesAPI CreateListenKeyV1 Post /dapi/v1/listenKey Start User Data Stream (USER_STREAM)
FuturesAPI CreateMarginTypeV1 Post /dapi/v1/marginType Change Margin Type (TRADE)
FuturesAPI CreateOrderV1 Post /dapi/v1/order New Order (TRADE)
FuturesAPI CreatePositionMarginV1 Post /dapi/v1/positionMargin Modify Isolated Position Margin(TRADE)
FuturesAPI CreatePositionSideDualV1 Post /dapi/v1/positionSide/dual Change Position Mode(TRADE)
FuturesAPI DeleteAllOpenOrdersV1 Delete /dapi/v1/allOpenOrders Cancel All Open Orders(TRADE)
FuturesAPI DeleteBatchOrdersV1 Delete /dapi/v1/batchOrders Cancel Multiple Orders(TRADE)
FuturesAPI DeleteListenKeyV1 Delete /dapi/v1/listenKey Close User Data Stream(USER_STREAM)
FuturesAPI DeleteOrderV1 Delete /dapi/v1/order Cancel Order (TRADE)
FuturesAPI GetAccountV1 Get /dapi/v1/account Account Information (USER_DATA)
FuturesAPI GetAdlQuantileV1 Get /dapi/v1/adlQuantile Position ADL Quantile Estimation(USER_DATA)
FuturesAPI GetAggTradesV1 Get /dapi/v1/aggTrades Compressed/Aggregate Trades List
FuturesAPI GetAllOrdersV1 Get /dapi/v1/allOrders All Orders (USER_DATA)
FuturesAPI GetBalanceV1 Get /dapi/v1/balance Futures Account Balance (USER_DATA)
FuturesAPI GetCommissionRateV1 Get /dapi/v1/commissionRate User Commission Rate (USER_DATA)
FuturesAPI GetConstituentsV1 Get /dapi/v1/constituents Query Index Price Constituents
FuturesAPI GetContinuousKlinesV1 Get /dapi/v1/continuousKlines Continuous Contract Kline/Candlestick Data
FuturesAPI GetDepthV1 Get /dapi/v1/depth Order Book
FuturesAPI GetExchangeInfoV1 Get /dapi/v1/exchangeInfo Exchange Information
FuturesAPI GetForceOrdersV1 Get /dapi/v1/forceOrders User's Force Orders(USER_DATA)
FuturesAPI GetFundingInfoV1 Get /dapi/v1/fundingInfo Get Funding Rate Info
FuturesAPI GetFundingRateV1 Get /dapi/v1/fundingRate Get Funding Rate History of Perpetual Futures
FuturesAPI GetFuturesDataBasis Get /futures/data/basis Basis
FuturesAPI GetFuturesDataGlobalLongShortAccountRatio Get /futures/data/globalLongShortAccountRatio Long/Short Ratio
FuturesAPI GetFuturesDataOpenInterestHist Get /futures/data/openInterestHist Open Interest Statistics
FuturesAPI GetFuturesDataTakerBuySellVol Get /futures/data/takerBuySellVol Taker Buy/Sell Volume
FuturesAPI GetFuturesDataTopLongShortAccountRatio Get /futures/data/topLongShortAccountRatio Top Trader Long/Short Ratio (Accounts)
FuturesAPI GetFuturesDataTopLongShortPositionRatio Get /futures/data/topLongShortPositionRatio Top Trader Long/Short Ratio (Positions)
FuturesAPI GetHistoricalTradesV1 Get /dapi/v1/historicalTrades Old Trades Lookup(MARKET_DATA)
FuturesAPI GetIncomeAsynIdV1 Get /dapi/v1/income/asyn/id Get Futures Transaction History Download Link by Id (USER_DATA)
FuturesAPI GetIncomeAsynV1 Get /dapi/v1/income/asyn Get Download Id For Futures Transaction History(USER_DATA)
FuturesAPI GetIncomeV1 Get /dapi/v1/income Get Income History(USER_DATA)
FuturesAPI GetIndexPriceKlinesV1 Get /dapi/v1/indexPriceKlines Index Price Kline/Candlestick Data
FuturesAPI GetKlinesV1 Get /dapi/v1/klines Kline/Candlestick Data
FuturesAPI GetLeverageBracketV1 Get /dapi/v1/leverageBracket Notional Bracket for Pair(USER_DATA)
FuturesAPI GetLeverageBracketV2 Get /dapi/v2/leverageBracket Notional Bracket for Symbol(USER_DATA)
FuturesAPI GetMarkPriceKlinesV1 Get /dapi/v1/markPriceKlines Mark Price Kline/Candlestick Data
FuturesAPI GetOpenInterestV1 Get /dapi/v1/openInterest Open Interest
FuturesAPI GetOpenOrderV1 Get /dapi/v1/openOrder Query Current Open Order(USER_DATA)
FuturesAPI GetOpenOrdersV1 Get /dapi/v1/openOrders Current All Open Orders (USER_DATA)
FuturesAPI GetOrderAmendmentV1 Get /dapi/v1/orderAmendment Get Order Modify History (USER_DATA)
FuturesAPI GetOrderAsynIdV1 Get /dapi/v1/order/asyn/id Get Futures Order History Download Link by Id (USER_DATA)
FuturesAPI GetOrderAsynV1 Get /dapi/v1/order/asyn Get Download Id For Futures Order History (USER_DATA)
FuturesAPI GetOrderV1 Get /dapi/v1/order Query Order (USER_DATA)
FuturesAPI GetPingV1 Get /dapi/v1/ping Test Connectivity
FuturesAPI GetPmAccountInfoV1 Get /dapi/v1/pmAccountInfo Classic Portfolio Margin Account Information (USER_DATA)
FuturesAPI GetPositionMarginHistoryV1 Get /dapi/v1/positionMargin/history Get Position Margin Change History(TRADE)
FuturesAPI GetPositionRiskV1 Get /dapi/v1/positionRisk Position Information(USER_DATA)
FuturesAPI GetPositionSideDualV1 Get /dapi/v1/positionSide/dual Get Current Position Mode(USER_DATA)
FuturesAPI GetPremiumIndexKlinesV1 Get /dapi/v1/premiumIndexKlines Premium index Kline Data
FuturesAPI GetPremiumIndexV1 Get /dapi/v1/premiumIndex Index Price and Mark Price
FuturesAPI GetTicker24hrV1 Get /dapi/v1/ticker/24hr 24hr Ticker Price Change Statistics
FuturesAPI GetTickerBookTickerV1 Get /dapi/v1/ticker/bookTicker Symbol Order Book Ticker
FuturesAPI GetTickerPriceV1 Get /dapi/v1/ticker/price Symbol Price Ticker
FuturesAPI GetTimeV1 Get /dapi/v1/time Check Server time
FuturesAPI GetTradeAsynIdV1 Get /dapi/v1/trade/asyn/id Get Futures Trade Download Link by Id(USER_DATA)
FuturesAPI GetTradeAsynV1 Get /dapi/v1/trade/asyn Get Download Id For Futures Trade History (USER_DATA)
FuturesAPI GetTradesV1 Get /dapi/v1/trades Recent Trades List
FuturesAPI GetUserTradesV1 Get /dapi/v1/userTrades Account Trade List (USER_DATA)
FuturesAPI UpdateBatchOrdersV1 Put /dapi/v1/batchOrders Modify Multiple Orders(TRADE)
FuturesAPI UpdateListenKeyV1 Put /dapi/v1/listenKey Keepalive User Data Stream (USER_STREAM)
FuturesAPI UpdateOrderV1 Put /dapi/v1/order Modify Order (TRADE)

Documentation For Models

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author