An open source sdk for Binance exchange written in Golang. There are endpoints/streams that are not implemented yet. Feel free to collaborate with me if you need them now :)
THIS LIBRARY IS NOT READY FOR PRODUCTION YET
After you've configured your local Go package:
go get github.com/opencrypter/binance-go
This SDK is based on the official binance api docs
You only have to call the constructor function in order to use it:
import "github.com/opencrypter/binance-go"
sdk := binance.New("Your-api-key", "Your secret api-key")
exchangeInfo, err := sdk.ExchangeInfo()
Current exchange trading rules and symbol information
Official doc: exchange-information
exchangeInfo, err := sdk.ExchangeInfo()
Order depth for a specific symbol
Official doc: Order book
// Example with limit by default
query := binance.NewDepthQuery("ETHBTC")
depth, err := sdk.Depth(query)
// Example with limit parameter
query := binance.NewDepthQuery("ETHBTC").Limit(5)
depth, err := sdk.Depth(query)
Get historical trades for a specific symbol
Official doc: Recent trades list
// Example to retrieve last trades with the limit by default
query := binance.NewTradesQuery("ETHBTC")
response, err := sdk.Trades(query)
// Example to retrieve historical trades from the given id and a result limit
query := binance.NewTradesQuery("ETHBTC").Limit(350).FromId(3500)
trades, err := sdk.Trades(query)
Get compressed, aggregate trades. Trades that fill at the time, from the same order, with the same price will have the quantity aggregated.
Official doc: Compressed/Aggregate trades list
// Example with parameters by default
query := binance.NewCompressedTradesQuery("ETHBTC")
response, err := sdk.CompressedTrades(query)
// Example with all parameters. Keep in mind that you cannot use all parameters at the same time (read the official doc)
query := binance.NewCompressedTradesQuery("ETHBTC").Limit(10).FromId(1).StartTime(1498793709153).EndTime(1498793709163)
trades, err := sdk.CompressedTrades(query)
Kline/candlestick bars for a symbol. Klines are uniquely identified by their open time.
Official doc: Kline/Candlestick data
// Example with parameters by default
query := binance.NewKLinesQuery("ETHBTC", binance.Interval12h)
response, err := sdk.KLines(query)
// Example with all parameters.
query := NewKLinesQuery("ETHBTC", Interval1m).Limit(10).StartTime(1498793709153).EndTime(1498793709163)
trades, err := sdk.KLines(query)
Latest price for a symbol.
Official doc: Symbol price ticker
query := binance.NewSymbolPriceTickerQuery("ETHBTC")
response, err := sdk.SymbolPriceTicker(query)
Latest price for all symbols.
Official doc: Symbol price ticker
response, err := sdk.AllSymbolPriceTickers()
Best price/qty on the order book for a symbol.
Official doc: Symbol order book ticker
query := binance.NewSymbolOrderBookTickerQuery("ETHBTC")
response, err := sdk.SymbolOrderBookTicker(query)
Best price/qty on the order book for all symbols.
Official doc: Symbol order book ticker
response, err := sdk.AllSymbolOrderBookTickers()
Send a new order.
Official doc: New order (TRADE)
request := binance.NewOrderRequest("BTCUSDT", "SELL", "MARKET", 10)
response, err := sdk.NewOrder(request)
// With all optional parameters (See official doc)
request := NewOrderRequest("BTCUSDT", "SELL", "MARKET", 10).
TimeInForce("GTC").
Price(0.1).
NewClientOrderId("6gCrw2kRUAF9CvJDGP16IP").
StopPrice(0.1).
IcebergQuantity(0.1).
NewOrderResponseType("ACK").
RecvWindow(2)
response, err := sdk.NewOrder(request)
Get order detail.
Official doc: Query order (USER_DATA)
query := binance.NewGetOrderQuery("LTCBTC")
response, err := sdk.GetOrder(query)
// With all optional parameters (See official doc)
query := binance.NewGetOrderQuery("LTCBTC").
OrderId(1).
OrigClientOrderId("myOrder1").
RecvWindow(2)
response, err := sdk.GetOrder(query)
Cancel an active order.
Official doc: Cancel order (TRADE)
request := binance.NewCancelOrderRequest("LTCBTC")
response, err := sdk.CancelOrder(request)
// With all optional parameters (See official doc)
request := binance.NewCancelOrderRequest("LTCBTC").
OrderId(1).
OrigClientOrderId("myOrder1").
RecvWindow(2000)
response, err := sdk.CancelOrder(request)
Get all open orders on a symbol.
Official doc: Current open orders (USER_DATA)
query := binance.NewGetOpenOrdersQuery("LTCBTC")
response, err := sdk.GetOpenOrders(query)
// With all optional parameters (See official doc)
query := binance.NewGetOpenOrdersQuery("LTCBTC").RecvWindow(2)
response, err := sdk.GetOpenOrders(query)
Get all account orders; active, canceled, or filled.
Official doc: All orders (USER_DATA)
query := binance.NewGetAllOrdersQuery("LTCBTC")
response, _ := sdk.GetAllOrders(query)
// With all optional parameters (See official doc)
query := binance.NewGetAllOrdersQuery("LTCBTC").
OrderId(1).
Limit(200).
RecvWindow(2000)
response, _ := sdk.GetAllOrders(query)
Get current account information.
Official doc: Account information (USER_DATA)
query := binance.NewAccountQuery()
response, _ := sdk.Account(query)
// With all optional parameters (See official doc)
query := binance.NewAccountQuery().RecvWindow(2000)
response, _ := sdk.Account(query)
Get trades for a specific account and symbol.
Official doc: Account trade list (USER_DATA)
query := binance.NewMyTradesQuery("ETHBTC")
response, _ := sdk.MyTrades(query)
// With all optional parameters (See official doc)
query := binance.NewMyTradesQuery("ETHBTC").Limit(10).RecvWindow(2).FromId(200)
response, _ := sdk.MyTrades(query)
Not available yet.
All is covered 100%. You can run all tests as normally you do it:
go test -test.v
MIT licensed. See the LICENSE file for details.