Documentation ¶
Index ¶
- Variables
- type Account
- type AccountEvent
- type AccountRequest
- type AggTrade
- type AggTradeEvent
- type AggTradesRequest
- type AllOrdersRequest
- type Balance
- type Binance
- type BookTicker
- type CancelOrderRequest
- type CanceledOrder
- type Deposit
- type DepthEvent
- type DepthWebsocketRequest
- type Error
- type ExchangeInfo
- type ExecutedOrder
- type HistoryRequest
- type HmacSigner
- type Interval
- type Kline
- type KlineEvent
- type KlineWebsocketRequest
- type KlinesRequest
- type MyTradesRequest
- type NewOrderRequest
- type OpenOrdersRequest
- type Order
- type OrderBook
- type OrderBookRequest
- type OrderSide
- type OrderStatus
- type OrderType
- type PriceTicker
- type ProcessedOrder
- type ProcessedOrderFull
- type QueryOrderRequest
- type Service
- type Signer
- type Stream
- type Ticker24
- type TickerRequest
- type TimeInForce
- type Trade
- type TradeWebsocketRequest
- type UserDataWebsocketRequest
- type WSEvent
- type WithdrawRequest
- type WithdrawResult
- type Withdrawal
Constants ¶
This section is empty.
Variables ¶
var ( Minute = Interval("1m") ThreeMinutes = Interval("3m") FiveMinutes = Interval("5m") FifteenMinutes = Interval("15m") ThirtyMinutes = Interval("30m") Hour = Interval("1h") TwoHours = Interval("2h") FourHours = Interval("4h") SixHours = Interval("6h") EightHours = Interval("8h") TwelveHours = Interval("12h") Day = Interval("1d") ThreeDays = Interval("3d") Week = Interval("1w") Month = Interval("1M") )
var ( GTC = TimeInForce("GTC") IOC = TimeInForce("IOC") )
var ( StatusNew = OrderStatus("NEW") StatusPartiallyFilled = OrderStatus("PARTIALLY_FILLED") StatusFilled = OrderStatus("FILLED") StatusCancelled = OrderStatus("CANCELED") StatusPendingCancel = OrderStatus("PENDING_CANCEL") StatusRejected = OrderStatus("REJECTED") StatusExpired = OrderStatus("EXPIRED") TypeLimit = OrderType("LIMIT") TypeMarket = OrderType("MARKET") SideBuy = OrderSide("BUY") SideSell = OrderSide("SELL") )
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { MakerCommision int64 TakerCommision int64 BuyerCommision int64 SellerCommision int64 CanTrade bool CanWithdraw bool CanDeposit bool Balances []*Balance }
Account represents user's account information.
type AccountEvent ¶
type AccountRequest ¶
AccountRequest represents Account request data.
type AggTrade ¶
type AggTrade struct { ID int Price float64 Quantity float64 FirstTradeID int LastTradeID int Timestamp time.Time BuyerMaker bool BestPriceMatch bool }
AggTrade represents aggregated trade.
type AggTradeEvent ¶
type AggTradesRequest ¶
AggTradesRequest represents AggTrades request data.
type AllOrdersRequest ¶
type AllOrdersRequest struct { Symbol string OrderID int64 Limit int RecvWindow time.Duration Timestamp time.Time }
AllOrdersRequest represents AllOrders request data.
type Binance ¶
type Binance interface { // Ping tests connectivity. Ping() error // Time returns server time. Time() (time.Time, error) ExchangeInfo() (*ExchangeInfo, error) // OrderBook returns list of orders. OrderBook(obr OrderBookRequest) (*OrderBook, error) // AggTrades returns compressed/aggregate list of trades. AggTrades(atr AggTradesRequest) ([]*AggTrade, error) // Klines returns klines/candlestick data. Klines(kr KlinesRequest) ([]*Kline, error) // Ticker24 returns 24hr price change statistics. Ticker24(tr TickerRequest) (*Ticker24, error) // TickerAllPrices returns ticker data for symbols. TickerAllPrices() ([]*PriceTicker, error) // TickerAllBooks returns tickers for all books. TickerAllBooks() ([]*BookTicker, error) // NewOrder places new order and returns ProcessedOrder. NewOrder(nor NewOrderRequest) (*ProcessedOrder, error) // NewOrder places new order and returns ProcessedOrder. NewOrderFull(nor NewOrderRequest) (*ProcessedOrderFull, error) // NewOrder places testing order. NewOrderTest(nor NewOrderRequest) error // QueryOrder returns data about existing order. QueryOrder(qor QueryOrderRequest) (*ExecutedOrder, error) // CancelOrder cancels order. CancelOrder(cor CancelOrderRequest) (*CanceledOrder, error) // OpenOrders returns list of open orders. OpenOrders(oor OpenOrdersRequest) ([]*ExecutedOrder, error) // AllOrders returns list of all previous orders. AllOrders(aor AllOrdersRequest) ([]*ExecutedOrder, error) // Account returns account data. Account(ar AccountRequest) (*Account, error) // MyTrades list user's trades. MyTrades(mtr MyTradesRequest) ([]*Trade, error) // Withdraw executes withdrawal. Withdraw(wr WithdrawRequest) (*WithdrawResult, error) // DepositHistory lists deposit data. DepositHistory(hr HistoryRequest) ([]*Deposit, error) // WithdrawHistory lists withdraw data. WithdrawHistory(hr HistoryRequest) ([]*Withdrawal, error) // StartUserDataStream starts stream and returns Stream with ListenKey. StartUserDataStream() (*Stream, error) // KeepAliveUserDataStream prolongs stream livespan. KeepAliveUserDataStream(s *Stream) error // CloseUserDataStream closes opened stream. CloseUserDataStream(s *Stream) error DepthWebsocket(dwr DepthWebsocketRequest) (chan *DepthEvent, chan struct{}, error) KlineWebsocket(kwr KlineWebsocketRequest) (chan *KlineEvent, chan struct{}, error) TradeWebsocket(twr TradeWebsocketRequest) (chan *AggTradeEvent, chan struct{}, error) UserDataWebsocket(udwr UserDataWebsocketRequest) (chan *AccountEvent, chan struct{}, error) }
Binance is wrapper for Binance API.
Read web documentation for more endpoints descriptions and list of mandatory and optional params. Wrapper is not responsible for client-side validation and only sends requests further.
For each API-defined enum there's a special type and list of defined enum values to be used.
type BookTicker ¶
type BookTicker struct { Symbol string BidPrice float64 BidQty float64 AskPrice float64 AskQty float64 }
BookTicker represents book ticker data.
type CancelOrderRequest ¶
type CancelOrderRequest struct { Symbol string OrderID int64 OrigClientOrderID string NewClientOrderID string RecvWindow time.Duration Timestamp time.Time }
CancelOrderRequest represents CancelOrder request data.
type CanceledOrder ¶
type CanceledOrder struct { Symbol string OrigClientOrderID string OrderID int64 ClientOrderID string }
CanceledOrder represents data about canceled order.
type DepthEvent ¶
type DepthWebsocketRequest ¶
type DepthWebsocketRequest struct {
Symbol string
}
type ExchangeInfo ¶
type ExchangeInfo struct { Timezone string `json:"timezone"` ServerTime int64 `json:"serverTime"` RateLimits []struct { RateLimitType string `json:"rateLimitType"` Interval string `json:"interval"` IntervalNum int `json:"intervalNum"` Limit int `json:"limit"` } `json:"rateLimits"` ExchangeFilters []interface{} `json:"exchangeFilters"` Symbols []struct { Symbol string `json:"symbol"` Status string `json:"status"` BaseAsset string `json:"baseAsset"` BaseAssetPrecision int `json:"baseAssetPrecision"` QuoteAsset string `json:"quoteAsset"` QuotePrecision int `json:"quotePrecision"` BaseCommissionPrecision int `json:"baseCommissionPrecision"` QuoteCommissionPrecision int `json:"quoteCommissionPrecision"` OrderTypes []string `json:"orderTypes"` IcebergAllowed bool `json:"icebergAllowed"` OcoAllowed bool `json:"ocoAllowed"` QuoteOrderQtyMarketAllowed bool `json:"quoteOrderQtyMarketAllowed"` IsSpotTradingAllowed bool `json:"isSpotTradingAllowed"` IsMarginTradingAllowed bool `json:"isMarginTradingAllowed"` Filters []struct { FilterType string `json:"filterType"` MinPrice string `json:"minPrice,omitempty"` MaxPrice string `json:"maxPrice,omitempty"` TickSize string `json:"tickSize,omitempty"` MultiplierUp string `json:"multiplierUp,omitempty"` MultiplierDown string `json:"multiplierDown,omitempty"` AvgPriceMins int `json:"avgPriceMins,omitempty"` MinQty string `json:"minQty,omitempty"` MaxQty string `json:"maxQty,omitempty"` StepSize string `json:"stepSize,omitempty"` MinNotional string `json:"minNotional,omitempty"` ApplyToMarket bool `json:"applyToMarket,omitempty"` Limit int `json:"limit,omitempty"` MaxNumAlgoOrders int `json:"maxNumAlgoOrders,omitempty"` } `json:"filters"` } `json:"symbols"` }
ExchangeInfo
type ExecutedOrder ¶
type ExecutedOrder struct { Symbol string OrderID int ClientOrderID string Price float64 OrigQty float64 ExecutedQty float64 Status OrderStatus TimeInForce TimeInForce Type OrderType Side OrderSide StopPrice float64 IcebergQty float64 Time time.Time }
ExecutedOrder represents data about executed order.
type HistoryRequest ¶
type HistoryRequest struct { Asset string Status *int StartTime time.Time EndTime time.Time RecvWindow time.Duration Timestamp time.Time }
HistoryRequest represents history-related calls request data.
type HmacSigner ¶
type HmacSigner struct {
Key []byte
}
HmacSigner uses HMAC SHA256 for signing payloads.
func (*HmacSigner) Sign ¶
func (hs *HmacSigner) Sign(payload []byte) string
Sign signs provided payload and returns encoded string sum.
type Kline ¶
type Kline struct { OpenTime time.Time Open float64 High float64 Low float64 Close float64 Volume float64 CloseTime time.Time QuoteAssetVolume float64 NumberOfTrades int TakerBuyBaseAssetVolume float64 TakerBuyQuoteAssetVolume float64 }
Kline represents single Kline information.
type KlineEvent ¶
type KlineWebsocketRequest ¶
type KlinesRequest ¶
type KlinesRequest struct { Symbol string Interval Interval Limit int StartTime int64 EndTime int64 }
KlinesRequest represents Klines request data.
type MyTradesRequest ¶
type MyTradesRequest struct { Symbol string Limit int FromID int64 RecvWindow time.Duration Timestamp time.Time }
MyTradesRequest represents MyTrades request data.
type NewOrderRequest ¶
type NewOrderRequest struct { Symbol string Side OrderSide Type OrderType TimeInForce TimeInForce Quantity float64 Price float64 NewClientOrderID string StopPrice float64 IcebergQty float64 Timestamp time.Time }
NewOrderRequest represents NewOrder request data.
type OpenOrdersRequest ¶
OpenOrdersRequest represents OpenOrders request data.
type OrderBookRequest ¶
OrderBookRequest represents OrderBook request data.
type PriceTicker ¶
PriceTicker represents ticker data for price.
type ProcessedOrder ¶
type ProcessedOrder struct { Symbol string OrderID int64 ClientOrderID string TransactTime time.Time }
ProcessedOrder represents data from processed order.
type ProcessedOrderFull ¶
type ProcessedOrderFull struct { Symbol string `json:"symbol"` OrderID int64 `json:"orderId"` OrderListID int `json:"orderListId"` ClientOrderID string `json:"clientOrderId"` TransactTime time.Time `json:"transactTime"` Price float64 `json:"price"` OrigQty float64 `json:"origQty"` ExecutedQty float64 `json:"executedQty"` CummulativeQuoteQty float64 `json:"cummulativeQuoteQty"` Status string `json:"status"` TimeInForce string `json:"timeInForce"` Type string `json:"type"` Side string `json:"side"` Fills []struct { Price string `json:"price"` Qty string `json:"qty"` Commission string `json:"commission"` CommissionAsset string `json:"commissionAsset"` } `json:"fills"` }
type QueryOrderRequest ¶
type QueryOrderRequest struct { Symbol string OrderID int64 OrigClientOrderID string RecvWindow time.Duration Timestamp time.Time }
QueryOrderRequest represents QueryOrder request data.
type Service ¶
type Service interface { Ping() error Time() (time.Time, error) ExchangeInfo() (*ExchangeInfo, error) OrderBook(obr OrderBookRequest) (*OrderBook, error) AggTrades(atr AggTradesRequest) ([]*AggTrade, error) Klines(kr KlinesRequest) ([]*Kline, error) Ticker24(tr TickerRequest) (*Ticker24, error) TickerAllPrices() ([]*PriceTicker, error) TickerAllBooks() ([]*BookTicker, error) NewOrder(or NewOrderRequest) (*ProcessedOrder, error) NewOrderFull(or NewOrderRequest) (*ProcessedOrderFull, error) NewOrderTest(or NewOrderRequest) error QueryOrder(qor QueryOrderRequest) (*ExecutedOrder, error) CancelOrder(cor CancelOrderRequest) (*CanceledOrder, error) OpenOrders(oor OpenOrdersRequest) ([]*ExecutedOrder, error) AllOrders(aor AllOrdersRequest) ([]*ExecutedOrder, error) Account(ar AccountRequest) (*Account, error) MyTrades(mtr MyTradesRequest) ([]*Trade, error) Withdraw(wr WithdrawRequest) (*WithdrawResult, error) DepositHistory(hr HistoryRequest) ([]*Deposit, error) WithdrawHistory(hr HistoryRequest) ([]*Withdrawal, error) StartUserDataStream() (*Stream, error) KeepAliveUserDataStream(s *Stream) error CloseUserDataStream(s *Stream) error DepthWebsocket(dwr DepthWebsocketRequest) (chan *DepthEvent, chan struct{}, error) KlineWebsocket(kwr KlineWebsocketRequest) (chan *KlineEvent, chan struct{}, error) TradeWebsocket(twr TradeWebsocketRequest) (chan *AggTradeEvent, chan struct{}, error) UserDataWebsocket(udwr UserDataWebsocketRequest) (chan *AccountEvent, chan struct{}, error) }
Service represents service layer for Binance API.
The main purpose for this layer is to be replaced with dummy implementation if necessary without need to replace Binance instance.
func NewAPIService ¶
func NewAPIService(url, apiKey string, signer Signer, logger log.Logger, ctx context.Context) Service
NewAPIService creates instance of Service.
If logger or ctx are not provided, NopLogger and Background context are used as default. You can use context for one-time request cancel (e.g. when shutting down the app).
type Signer ¶
type Signer interface { // Sign signs provided payload and returns encoded string sum. Sign(payload []byte) string }
Signer signs provided payloads.
type Stream ¶
type Stream struct {
ListenKey string
}
Stream represents stream information.
Read web docs to get more information about using streams.
type Ticker24 ¶
type Ticker24 struct { PriceChange float64 PriceChangePercent float64 WeightedAvgPrice float64 PrevClosePrice float64 LastPrice float64 BidPrice float64 AskPrice float64 OpenPrice float64 HighPrice float64 LowPrice float64 Volume float64 OpenTime time.Time CloseTime time.Time FirstID int LastID int Count int }
Ticker24 represents data for 24hr ticker.
type TickerRequest ¶
type TickerRequest struct {
Symbol string
}
TickerRequest represents Ticker request data.
type Trade ¶
type Trade struct { ID int64 Price float64 Qty float64 Commission float64 CommissionAsset string Time time.Time IsBuyer bool IsMaker bool IsBestMatch bool }
Trade represents data about trade.
type TradeWebsocketRequest ¶
type TradeWebsocketRequest struct {
Symbol string
}
type UserDataWebsocketRequest ¶
type UserDataWebsocketRequest struct {
ListenKey string
}
type WithdrawRequest ¶
type WithdrawRequest struct { Asset string Address string Amount float64 Name string RecvWindow time.Duration Timestamp time.Time }
WithdrawRequest represents Withdraw request data.
type WithdrawResult ¶
WithdrawResult represents Withdraw result.