Categorygithub.com/oopsmouse/go-binance
modulepackage
0.0.0-20180220134734-489176faa80b
Repository: https://github.com/oopsmouse/go-binance.git
Documentation: pkg.go.dev

# README

Binance API

To read full documentation, specs and find out which request params are required/optional, please visit the official documentation page.

Getting started

var logger log.Logger
logger = log.NewLogfmtLogger(log.NewSyncWriter(os.Stderr))
logger = log.With(logger, "time", log.DefaultTimestampUTC, "caller", log.DefaultCaller)

hmacSigner := &binance.HmacSigner{
    Key: []byte("API secret"),
}
ctx, _ := context.WithCancel(context.Background())
// use second return value for cancelling request when shutting down the app

binanceService := binance.NewAPIService(
    "https://www.binance.com",
    "API key",
    hmacSigner,
    logger,
    ctx,
)
b := binance.NewBinance(binanceService)

Examples

Following provides list of main usages of library. See example package for testing application with more examples.

Each call has its own Request structure with data that can be provided. The library is not responsible for validating the input and if non-zero value is used, the param is sent to the API server.

In case of an standard error, instance of binance.Error is returned with additional info.

NewOrder

newOrder, err := b.NewOrder(binance.NewOrderRequest{
    Symbol:      "BNBETH",
    Quantity:    1,
    Price:       999,
    Side:        binance.SideSell,
    TimeInForce: binance.GTC,
    Type:        binance.TypeLimit,
    Timestamp:   time.Now(),
})
if err != nil {
    panic(err)
}
fmt.Println(newOrder)

CancelOrder

canceledOrder, err := b.CancelOrder(binance.CancelOrderRequest{
    Symbol:    "BNBETH",
    OrderID:   newOrder.OrderID,
    Timestamp: time.Now(),
})
if err != nil {
    panic(err)
}
fmt.Printf("%#v\n", canceledOrder)

Klines

kl, err := b.Klines(binance.KlinesRequest{
    Symbol:   "BNBETH",
    Interval: binance.Hour,
})
if err != nil {
    panic(err)
}
fmt.Printf("%#v\n", kl)

Trade Websocket

interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)

kech, done, err := b.TradeWebsocket(binance.TradeWebsocketRequest{
    Symbol: "ETHBTC",
})
if err != nil {
    panic(err)
}
go func() {
    for {
        select {
        case ke := <-kech:
            fmt.Printf("%#v\n", ke)
        case <-done:
            break
        }
    }
}()

fmt.Println("waiting for interrupt")
<-interrupt
fmt.Println("canceling context")
cancelCtx()
fmt.Println("waiting for signal")
<-done
fmt.Println("exit")
return

Known issues

  • Websocket error handling is not perfect and occasionally attempts to read from closed connection.

# Packages

No description provided by the author

# Functions

NewAPIService creates instance of Service.
NewBinance returns Binance instance.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
FOK (Fill or Kill) orders fills all in its entirety, otherwise, the entire order will be cancelled.
No description provided by the author
GTC (Good-Til-Canceled) orders are effective until they are executed or canceled.
No description provided by the author
IOC (Immediate or Cancel) orders fills all or part of an order immediately and cancels the remaining part of the order.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
LIMIT timeInForce, quantity, price.
LIMIT_MAKER quantity, price.
MARKET quantity.
STOP_LOSS quantity, stopPrice.
STOP_LOSS_LIMIT timeInForce, quantity, price, stopPrice.
TAKE_PROFIT quantity, stopPrice.
TAKE_PROFIT_LIMIT timeInForce, quantity, price, stopPrice.
No description provided by the author

# Structs

Account represents user's account information.
No description provided by the author
AccountRequest represents Account request data.
AggTrade represents aggregated trade.
No description provided by the author
AggTradesRequest represents AggTrades request data.
AllOrdersRequest represents AllOrders request data.
Balance groups balance-related information.
BookTicker represents book ticker data.
CanceledOrder represents data about canceled order.
CancelOrderRequest represents CancelOrder request data.
Deposit represents Deposit data.
No description provided by the author
No description provided by the author
Error represents Binance error structure with error code and message.
No description provided by the author
ExecutedOrder represents data about executed order.
HistoryRequest represents history-related calls request data.
HmacSigner uses HMAC SHA256 for signing payloads.
Kline represents single Kline information.
No description provided by the author
KlinesRequest represents Klines request data.
No description provided by the author
MyTradesRequest represents MyTrades request data.
NewOrderRequest represents NewOrder request data.
OpenOrdersRequest represents OpenOrders request data.
Order represents single order information.
OrderBook represents Bids and Asks.
OrderBookRequest represents OrderBook request data.
PriceTicker represents ticker data for price.
ProcessedOrder represents data from processed order.
Trade represents trade.
QueryOrderRequest represents QueryOrder request data.
Stream represents stream information.
No description provided by the author
Ticker24 represents data for 24hr ticker.
TickerRequest represents Ticker request data.
No description provided by the author
Trade represents data about trade.
TradesRequest represents Trades request data.
No description provided by the author
No description provided by the author
Withdrawal represents withdrawal data.
WithdrawRequest represents Withdraw request data.
WithdrawResult represents Withdraw result.
No description provided by the author

# Interfaces

Binance is wrapper for Binance API.
Service represents service layer for Binance API.
Signer signs provided payloads.

# Type aliases

Interval represents interval enum.
OrderSide represents order side enum.
OrderStatus represents order status enum.
OrderType represents order type enum.
Time in force to indicate how long an order will remain active before it is executed or expires.