Skip to content

Repository files navigation

Binance API Go Language SDK

Go Report CardBuild StatuscodecovlicenseGo VersionGoDocReleaseRelease DateCommit

This is a Binance Go language sdk that uses a method similar to HuobiRDCenter/huobi_Golang

Official Documents

Please make sure you have read the Binance API document before continuing.

Precautions

You are very welcome to submit issues or pull requests to share with this project to make the project more perfect

  • Remove all WAPI endpoints

    As Binance has planned to remove all WAPI endpoints from the Binance API at 2021-08-01 2:00 AM (UTC). So this the repo has removed all WAPI endpoints from the Binance API in advanceMore Information

  • spot/client/market.go:Line185GetCandlestick()

    It is not recommended using this method, this method may have type errors, please use websocket subscription to obtain data.

List of implemented APIs

The following table shows the functions included in this SDK

Spot/Margin/Savings/Mining

CategoryClientAccess Type
CommonSystem Status (SAPI)RESTful API
Test ConnectivityRESTful API
Check ServerTimeRESTful API
WalletAll Coin's InformationRESTful API
Daily Account SnapshotRESTful API
Disabled/Enabled Fast WithdrawRESTful API
Withdraw (SAPI)RESTful API
Deposit History(supporting network)RESTful API
Withdraw History(supporting network)RESTful API
Deposit Address(supporting network)RESTful API
Account Status (SAPI)RESTful API
Account API Trading Status (SAPI)RESTful API
DustLog (SAPI)RESTful API
Dust TransferRESTful API
Asset Dividend RecordRESTful API
Asset Detail (SAPI)RESTful API
Trade Fee (SAPI)RESTful API
User Universal TransferRESTful API
Query User Universal Transfer HistoryRESTful API
MarketOrder BookRESTful API
Recent Trades ListRESTful API
Old Trade LookupRESTful API
Aggregate TradeRESTful API
CandlestickRESTful API
Current Average PriceRESTful API
24h Ticker Price ChangeRESTful API
Symbol Price TickerRESTful API
Symbol Order Book TickerRESTful API
Aggregate TradeWebSocket
TradeWebSocket
CandlestickWebSocket
Individual Symbol Mini TickerWebSocket
All Market Mini TickersWebSocket
Individual Symbol TickerWebSocket
All Market TickersWebSocket
Individual Symbol Book TickerWebSocket
All Book TickersWebSocket
Partial Book DepthWebSocket
Diff. Book DepthWebSocket
TradeTest New OrderRESTful API
New orderRESTful API
Cancel orderRESTful API
Cancel all orderRESTful API
Query orderRESTful API
Current open ordersRESTful API
All ordersRESTful API
New OCORESTful API
Cancel OCORESTful API
Query OCORESTful API
Query all OCORESTful API
Query Open OCORESTful API
Account InformationRESTful API
Account Trade ListRESTful API
AccountCreate Spot/Margin/Isolated Listen KeyRESTful API
Ping/KeepAlive Spot/Margin/Isolated Listen KeyRESTful API
Delete Spot/Margin/Isolated Listen KeyRESTful PAI
Account UpdateWebSocket
Balance UpdateWebSocket
Order UpdateWebSocket

USDⓈ-M Futures

CategoryClientAccess Type
MarketAggregate TradeWebSocket
Market PriceWebSocket
All Market PriceWebSocket
Kline/CandlestickWebSocket
Continuous CandlestickWebSocket
Individual Symbol Mini TickerWebSocket
All Market Mini TickersWebSocket
Individual Symbol TickerWebSocket
All Book TickersWebSocket
Liquidation OrderWebSocket
All Market Liquidation OrdersWebSocket
Partial Book DepthWebSocket
Diff. Book DepthWebSocket
BLVT InfoWebSocket
BLVT NAV Kline/CandlestickWebSocket
Composite Index SymbolWebSocket

Usage

Below are some examples of usage

RESTful wallet transfer

Examples of user transfers in the universal

package spotclient
import (
binance "github.com/dirname/binance""github.com/dirname/binance/config""github.com/shopspring/decimal""reflect""testing""time"
)
funcinit() {
logger.Enable(false)
walletClient=spotclient.NewWalletClient(config.SpotRestHost, config.AppKey, config.AppSecret)
}
funcuniversalTransfer() {
response, err:=walletClient.UniversalTransfer("UMFUTURE_MAIN", "USDT", "10", 0)
iferr!=nil {
logger.Error("universalTransfer err: %s", err.Error())
}
switchresponse.(type) {
case model.APIErrorResponse:
logger.Info("universalTransfer API error: %v", response.(model.APIErrorResponse))
case spotclient.UniversalTransferResponse:
logger.Info("universalTransfer: %v", response.(spotclient.UniversalTransferResponse))
default:
logger.Info("universalTransfer Unknown response: %v", response)
}
}

WebSocket market quotes

Take the Kline of the USDⓈ-M Futures as an example

package main
import (
"fmt""github.com/dirname/binance/futures/usdt/websocket/market"
logger "github.com/dirname/binance/logging""github.com/dirname/binance/model""time"
)
funcmain() {
client:=futuresclient.NewUSDFuturesCandlestickWebsocketClient("btcusdt@kline_1m")
client.SetReadTimerInterval(5*time.Second)
client.SetReconnectWaitTime(5*time.Second)
client.SetKeepAliveInterval(2*time.Minute)
client.SetHandler(func() {
client.Subscribe(123, "btcusdt@kline_1m", "btcusdt@kline_5m")
client.SetCombined(true, 123)
}, func(responseinterface{}) {
switchresponse.(type) {
case futuresclient.CandlestickResponse:
logger.Info("Candlestick Response: %v", response.(futuresclient.CandlestickResponse))
case futuresclient.CandlestickCombinedResponse:
logger.Info("CandlestickCombinedResponse: %v", response.(futuresclient.CandlestickCombinedResponse))
case model.WebsocketCommonResponse:
logger.Info("Websocket Response: %v", response.(model.WebsocketCommonResponse))
case model.WebsocketErrorResponse:
logger.Info("Websocket Error Response: %v", response.(model.WebsocketErrorResponse))
default:
logger.Info("Unknown Response: %v", response)
}
})
client.Connect(true)
fmt.Scanln()
client.Unsubscribe(123, "btcusdt@kline_1m", "btcusdt@kline_5m")
client.Close()
logger.Info("Client closed")
}

Disclaimer

This SDK is for personal use and has not been officially produced. They are only used to help users become familiar with API endpoint. Please use it with caution, and expand the R&D according to your own situation.

In addition, the performance and stability of this sdk need to be tested by yourself, and the loss due to performance or stability shall be borne by you

About

This repo is some SDK of Binance

Resources

Stars

124 stars

Watchers

20 watching

Forks

Releases

Packages

Used by

Contributors

Languages