All Projects → adshao → Go Binance

adshao / Go Binance

Licence: mit
A Go SDK for Binance API

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Go Binance

Ccxt
A JavaScript / Python / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
Stars: ✭ 22,501 (+5002.27%)
Mutual labels:  api, bitcoin, btc, eth, exchange
Ccxt Rest
Open Source Unified REST API of 100+ Crypto Exchange Sites (18k+ docker pulls) - https://ccxt-rest.io/
Stars: ✭ 210 (-52.38%)
Mutual labels:  api, bitcoin, btc, eth, exchange
Coinpricebar
💰 Cryptocurrency prices on MacBook Touch Bar
Stars: ✭ 290 (-34.24%)
Mutual labels:  bitcoin, btc, eth, binance
Cryptolist
Curated collection of blockchain & cryptocurrency resources.
Stars: ✭ 3,501 (+693.88%)
Mutual labels:  api, bitcoin, btc, eth
Tardis Node
Convenient access to tick-level real-time and historical cryptocurrency market data via Node.js
Stars: ✭ 126 (-71.43%)
Mutual labels:  btc, eth, binance, exchange
Crypto vba
An Excel/VBA project to communicate with various cryptocurrency exchanges APIs
Stars: ✭ 103 (-76.64%)
Mutual labels:  bitcoin, btc, binance, exchange
Coinbin.org
₿ A Human–Friendly API Service for Crypto Currency Information.
Stars: ✭ 253 (-42.63%)
Mutual labels:  api, bitcoin, btc, eth
My Token
📈Track token prices of your favorite exchanges in terminal!
Stars: ✭ 141 (-68.03%)
Mutual labels:  bitcoin, btc, binance, exchange
Coinapi Sdk
SDKs for CoinAPI
Stars: ✭ 238 (-46.03%)
Mutual labels:  api, bitcoin, sdk, exchange
Cryptocurrency Portfolio
Google Sheets automatic creation with Google Apps Script (GAS) for managing a cryptocurrency tracking spreadsheet with multi exchanges
Stars: ✭ 134 (-69.61%)
Mutual labels:  api, binance, exchange
Huobi golang
Go SDK for Huobi Spot API
Stars: ✭ 76 (-82.77%)
Mutual labels:  api, sdk, exchange
Huobi java
Java SDK for Huobi Spot API
Stars: ✭ 180 (-59.18%)
Mutual labels:  api, sdk, exchange
Coinbase Pro Node
Coinbase Pro API written in TypeScript and covered by tests.
Stars: ✭ 116 (-73.7%)
Mutual labels:  api, bitcoin, exchange
Ccxt.net
CCXT.NET – CryptoCurrency eXchange Trading Library for .NET
Stars: ✭ 89 (-79.82%)
Mutual labels:  api, bitcoin, exchange
Crypto Exchange
Pulls together list of crypto exchanges to interact with their API's in a uniform fashion.
Stars: ✭ 241 (-45.35%)
Mutual labels:  api, bitcoin, exchange
Currencyviewer
Short python framework that dynamically displays and converts the cryptocurrencies in your Kraken wallet into equivalents fiat money.
Stars: ✭ 13 (-97.05%)
Mutual labels:  api, bitcoin, exchange
Uniswap Python
🦄 The unofficial Python client for the Uniswap exchange.
Stars: ✭ 191 (-56.69%)
Mutual labels:  api, eth, exchange
Optimal Buy Cbpro
Scheduled buying of BTC, ETH, and LTC from Coinbase Pro, optimally!
Stars: ✭ 288 (-34.69%)
Mutual labels:  bitcoin, btc, eth
coinmarketcap-icons-cryptos
Repository of all crypto icons, and allows you to download all images of icons of crypto currencies listed on the coinmarketcap site 9129 icons
Stars: ✭ 17 (-96.15%)
Mutual labels:  btc, eth, binance
kunkka-match
高性能撮合引擎
Stars: ✭ 50 (-88.66%)
Mutual labels:  exchange, btc, eth

go-binance

A Golang SDK for binance API.

Build Status GoDoc Go Report Card codecov

All the REST APIs listed in binance API document are implemented, as well as the websocket APIs.

For best compatibility, please use Go >= 1.8.

Make sure you have read binance API document before continuing.

API List

Name Description Status
rest-api.md Details on the Rest API (/api) Implemented
web-socket-streams.md Details on available streams and payloads Implemented
user-data-stream.md Details on the dedicated account stream Implemented
wapi-api.md Details on the Withdrawal API (/wapi) Partially Implemented
margin-api.md Details on the Margin API (/sapi) Implemented
futures-api.md Details on the Futures API (/fapi) Partially Implemented
delivery-api.md Details on the Coin-M Futures API (/dapi) Partially Implemented

Installation

go get github.com/adshao/go-binance/v2

For v1 API, it has been moved to v1 branch, please use:

go get github.com/adshao/go-binance/v1

Importing

import (
    "github.com/adshao/go-binance/v2"
)

Documentation

GoDoc

REST API

Setup

Init client for API services. Get APIKey/SecretKey from your binance account.

var (
    apiKey = "your api key"
    secretKey = "your secret key"
)
client := binance.NewClient(apiKey, secretKey)
futuresClient := binance.NewFuturesClient(apiKey, secretKey)    // USDT-M Futures
deliveryClient := binance.NewDeliveryClient(apiKey, secretKey)  // Coin-M Futures

A service instance stands for a REST API endpoint and is initialized by client.NewXXXService function.

Simply call API in chain style. Call Do() in the end to send HTTP request.

Following are some simple examples, please refer to godoc for full references.

Create Order

order, err := client.NewCreateOrderService().Symbol("BNBETH").
        Side(binance.SideTypeBuy).Type(binance.OrderTypeLimit).
        TimeInForce(binance.TimeInForceTypeGTC).Quantity("5").
        Price("0.0030000").Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(order)

// Use Test() instead of Do() for testing.

Get Order

order, err := client.NewGetOrderService().Symbol("BNBETH").
    OrderID(4432844).Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(order)

Cancel Order

_, err := client.NewCancelOrderService().Symbol("BNBETH").
    OrderID(4432844).Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}

List Open Orders

openOrders, err := client.NewListOpenOrdersService().Symbol("BNBETH").
    Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
for _, o := range openOrders {
    fmt.Println(o)
}

List Orders

orders, err := client.NewListOrdersService().Symbol("BNBETH").
    Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
for _, o := range orders {
    fmt.Println(o)
}

List Ticker Prices

prices, err := client.NewListPricesService().Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
for _, p := range prices {
    fmt.Println(p)
}

Show Depth

res, err := client.NewDepthService().Symbol("LTCBTC").
    Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(res)

List Klines

klines, err := client.NewKlinesService().Symbol("LTCBTC").
    Interval("15m").Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
for _, k := range klines {
    fmt.Println(k)
}

List Aggregate Trades

trades, err := client.NewAggTradesService().
    Symbol("LTCBTC").StartTime(1508673256594).EndTime(1508673256595).
    Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
for _, t := range trades {
    fmt.Println(t)
}

Get Account

res, err := client.NewGetAccountService().Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(res)

Start User Stream

res, err := client.NewStartUserStreamService().Do(context.Background())
if err != nil {
    fmt.Println(err)
    return
}
fmt.Println(res)

Websocket

You don't need Client in websocket API. Just call binance.WsXxxServe(args, handler, errHandler).

For delivery API you can use delivery.WsXxxServe(args, handler, errHandler).

Depth

wsDepthHandler := func(event *binance.WsDepthEvent) {
    fmt.Println(event)
}
errHandler := func(err error) {
    fmt.Println(err)
}
doneC, stopC, err := binance.WsDepthServe("LTCBTC", wsDepthHandler, errHandler)
if err != nil {
    fmt.Println(err)
    return
}
// use stopC to exit
go func() {
    time.Sleep(5 * time.Second)
    stopC <- struct{}{}
}()
// remove this if you do not want to be blocked here
<-doneC

Kline

wsKlineHandler := func(event *binance.WsKlineEvent) {
    fmt.Println(event)
}
errHandler := func(err error) {
    fmt.Println(err)
}
doneC, _, err := binance.WsKlineServe("LTCBTC", "1m", wsKlineHandler, errHandler)
if err != nil {
    fmt.Println(err)
    return
}
<-doneC

Aggregate

wsAggTradeHandler := func(event *binance.WsAggTradeEvent) {
    fmt.Println(event)
}
errHandler := func(err error) {
    fmt.Println(err)
}
doneC, _, err := binance.WsAggTradeServe("LTCBTC", wsAggTradeHandler, errHandler)
if err != nil {
    fmt.Println(err)
    return
}
<-doneC

User Data

wsHandler := func(message []byte) {
    fmt.Println(string(message))
}
errHandler := func(err error) {
    fmt.Println(err)
}
doneC, _, err := binance.WsUserDataServe(listenKey, wsHandler, errHandler)
if err != nil {
    fmt.Println(err)
    return
}
<-doneC

Setting Server Time

Your system time may be incorrect and you may use following function to set the time offset based off Binance Server Time:

// use the client future for Futures
client.NewSetServerTimeService().Do(context.Background())

Or you can also overwrite the TimeOffset yourself:

client.TimeOffset = 123

Testnet

You can use the testnet by enabling the corresponding flag.

Note that you can't use your regular API and Secret keys for the testnet. You have to create an account on the testnet websites : https://testnet.binancefuture.com/ for futures and delivery or https://testnet.binance.vision/ for the Spot Test Network.

Spot

Use the binance.UseTestnet flag before calling the client creation and the websockets methods.

import (
    "github.com/adshao/go-binance/v2"
)

binance.UseTestnet = true
client := binance.NewClient(apiKey, secretKey)

Futures (usd(s)-m futures)

Use the futures.UseTestnet flag before calling the client creation and the websockets methods

import (
    "github.com/adshao/go-binance/v2/futures"
)

futures.UseTestnet = true
BinanceClient = futures.NewClient(ApiKey, SecretKey)

Delivery (coin-m futures)

Use the delivery.UseTestnet flag before calling the client creation and the websockets methods

import (
    "github.com/adshao/go-binance/v2/delivery"
)

delivery.UseTestnet = true
BinanceClient = delivery.NewClient(ApiKey, SecretKey)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].