Documentation ¶
Index ¶
- Constants
- Variables
- type APIError
- type AccountInfo
- type AccountTrades
- type AccountTradesReq
- type AggregatedTrade
- type AggregatedTradeReq
- type AllOrdersReq
- type AvgPrice
- type AvgPriceReq
- type Balance
- type BookTicker
- type BookTickerReq
- type CancelOpenOrdersReq
- type CancelOrder
- type CancelOrderReq
- type Client
- func (c *Client) Account() (*AccountInfo, error)
- func (c *Client) AccountTrades(req *AccountTradesReq) (*AccountTrades, error)
- func (c *Client) AggregatedTrades(req *AggregatedTradeReq) ([]*AggregatedTrade, error)
- func (c *Client) AllOrders(req *AllOrdersReq) ([]*QueryOrder, error)
- func (c *Client) AvgPrice(req *AvgPriceReq) (*AvgPrice, error)
- func (c *Client) BookTicker(req *BookTickerReq) (*BookTicker, error)
- func (c *Client) BookTickers() ([]*BookTicker, error)
- func (c *Client) CancelOpenOrders(req *CancelOpenOrdersReq) ([]*CancelOrder, error)
- func (c *Client) CancelOrder(req *CancelOrderReq) (*CancelOrder, error)
- func (c *Client) DataStream() (string, error)
- func (c *Client) DataStreamClose(listenKey string) error
- func (c *Client) DataStreamKeepAlive(listenKey string) error
- func (c *Client) Depth(req *DepthReq) (*Depth, error)
- func (c *Client) ExchangeInfo() (*ExchangeInfo, error)
- func (c *Client) Klines(req *KlinesReq) ([]*Klines, error)
- func (c *Client) NewOrder(req *OrderReq) (*OrderRespAck, error)
- func (c *Client) NewOrderFull(req *OrderReq) (*OrderRespFull, error)
- func (c *Client) NewOrderResult(req *OrderReq) (*OrderRespResult, error)
- func (c *Client) NewOrderTest(req *OrderReq) error
- func (c *Client) OpenOrders(req *OpenOrdersReq) ([]*QueryOrder, error)
- func (c *Client) Ping() error
- func (c *Client) Price(req *TickerPriceReq) (*SymbolPrice, error)
- func (c *Client) Prices() ([]*SymbolPrice, error)
- func (c *Client) QueryOrder(req *QueryOrderReq) (*QueryOrder, error)
- func (c *Client) ReqWindow(window int) *Client
- func (c *Client) Ticker(req *TickerReq) (*TickerStats, error)
- func (c *Client) Tickers() ([]*TickerStats, error)
- func (c *Client) Time() (*ServerTime, error)
- func (c *Client) Trades(req *TradeReq) ([]*Trade, error)
- type DatastreamReq
- type Depth
- type DepthElem
- type DepthReq
- type ExchangeInfo
- type FilterType
- type KlineInterval
- type Klines
- type KlinesReq
- type OpenOrdersReq
- type OrderFailure
- type OrderReq
- type OrderRespAck
- type OrderRespFull
- type OrderRespFullFill
- type OrderRespResult
- type OrderRespType
- type OrderSide
- type OrderStatus
- type OrderType
- type QueryOrder
- type QueryOrderReq
- type ServerTime
- type SymbolInfo
- type SymbolInfoFilter
- type SymbolPrice
- type SymbolStatus
- type TickerPriceReq
- type TickerReq
- type TickerStats
- type TimeInForce
- type Trade
- type TradeReq
Constants ¶
const ( BaseHost = "api.binance.com" DefaultUserAgent = "Binance/client" )
const ( EndpointPing = "/api/v3/ping" EndpointTime = "/api/v3/time" EndpointExchangeInfo = "/api/v3/exchangeInfo" EndpointDepth = "/api/v3/depth" EndpointTrades = "/api/v3/trades" EndpointAggTrades = "/api/v3/aggTrades" EndpointKlines = "/api/v3/klines" EndpointAvgPrice = "/api/v3/avgPrice" EndpointTicker24h = "/api/v3/ticker/24hr" EndpointTickerPrice = "/api/v3/ticker/price" EndpointTickerBook = "/api/v3/ticker/bookTicker" EndpointOrder = "/api/v3/order" EndpointOrderTest = "/api/v3/order/test" EndpointOpenOrders = "/api/v3/openOrders" EndpointOrdersAll = "/api/v3/allOrders" EndpointAccount = "/api/v3/account" EndpointAccountTrades = "/api/v3/myTrades" EndpointDataStream = "/api/v3/userDataStream" )
const ( OrderRespTypeAsk = "ASK" OrderRespTypeResult = "RESULT" OrderRespTypeFull = "FULL" )
Variables ¶
var ( ErrNilRequest = errors.New("request is nil") ErrEmptySymbol = errors.New("symbol are missing") ErrEmptyOrderID = errors.New("order id must be set") ErrEmptyLimit = errors.New("empty price or quantity") ErrEmptyMarket = errors.New("quantity or quote quantity expected") ErrNilUnmarshal = errors.New("UnmarshalJSON on nil pointer") ErrInvalidJson = errors.New("invalid json") )
Functions ¶
This section is empty.
Types ¶
type AccountInfo ¶
type AccountInfo struct { MakerCommission int `json:"makerCommission"` TakerCommission int `json:"takerCommission"` BuyerCommission int `json:"buyerCommission"` SellerCommission int `json:"sellerCommission"` CanTrade bool `json:"canTrade"` CanWithdraw bool `json:"canWithdraw"` CanDeposit bool `json:"canDeposit"` Balances []*Balance `json:"balances"` }
type AccountTrades ¶
type AccountTrades struct { ID int `json:"id"` Price string `json:"price"` Qty string `json:"qty"` Commission string `json:"commission"` CommissionAsset string `json:"commissionAsset"` Time uint64 `json:"time"` Buyer bool `json:"isBuyer"` Maker bool `json:"isMaker"` BestMatch bool `json:"isBestMatch"` }
type AccountTradesReq ¶
type AggregatedTrade ¶
type AggregatedTrade struct { TradeID int `json:"a"` // TradeID is the aggregate trade ID Price string `json:"p"` // Price is the trade price Quantity string `json:"q"` // Quantity is the trade quantity FirstTradeID int `json:"f"` LastTradeID int `json:"l"` Time uint64 `json:"T"` Maker bool `json:"m"` // Maker indicates if the buyer is the maker BestMatch bool `json:"M"` // BestMatch indicates if the trade was at the best price match }
type AggregatedTradeReq ¶
type AggregatedTradeReq struct { Symbol string `url:"symbol"` // Symbol is the symbol to fetch data for FromID int `url:"fromId"` // FromID to get aggregate trades from INCLUSIVE. Limit int `url:"limit"` // Limit is the maximal number of elements to receive. Max 500 StartTime uint64 `url:"startTime,omitempty"` EndTime uint64 `url:"endTime,omitempty"` }
type AllOrdersReq ¶
type AllOrdersReq struct { Symbol string `url:"symbol"` // Symbol is the symbol to fetch orders for OrderID int `url:"orderId"` // OrderID, if set, will filter all recent orders newer from the given ID Limit int `url:"limit"` // Limit is the maximal number of elements to receive. Max 500 }
AllOrdersReq represents the request used for querying orders of the given symbol Remark: If orderId is set, it will get orders >= that orderId. Otherwise most recent orders are returned
type AvgPriceReq ¶
type AvgPriceReq struct {
Symbol string `url:"symbol"`
}
type BookTicker ¶
type BookTickerReq ¶
type BookTickerReq struct {
Symbol string `url:"symbol"`
}
type CancelOpenOrdersReq ¶
type CancelOpenOrdersReq struct {
Symbol string `url:"symbol"`
}
type CancelOrder ¶
type CancelOrder struct { Symbol string `json:"symbol"` OrigClientOrderID string `json:"origClientOrderId"` OrderID int `json:"orderId"` OrderListID int `json:"orderListId"` ClientOrderID string `json:"clientOrderId"` Price string `json:"price"` OrigQty string `json:"origQty"` ExecutedQty string `json:"executedQty"` CummulativeQuoteQty string `json:"cummulativeQuoteQty"` Status OrderStatus `json:"status"` TimeInForce string `json:"timeInForce"` Type OrderType `json:"type"` Side OrderSide `json:"side"` }
type CancelOrderReq ¶
type CancelOrderReq struct { Symbol string `url:"symbol"` OrderID int `url:"orderId,omitempty"` OrigClientOrderId string `url:"origClientOrderId,omitempty"` NewClientOrderId string `url:"newClientOrderId,omitempty"` }
Remark: Either OrderID or OrigOrderID must be set
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Account ¶
func (c *Client) Account() (*AccountInfo, error)
Account get current account information
func (*Client) AccountTrades ¶
func (c *Client) AccountTrades(req *AccountTradesReq) (*AccountTrades, error)
AccountTrades get trades for a specific account and symbol
func (*Client) AggregatedTrades ¶
func (c *Client) AggregatedTrades(req *AggregatedTradeReq) ([]*AggregatedTrade, error)
AggregatedTrades gets compressed, aggregate trades. AccountTrades that fill at the time, from the same order, with the same price will have the quantity aggregated Remark: If both startTime and endTime are sent, limit should not be sent AND the distance between startTime and endTime must be less than 24 hours. Remark: If frondId, startTime, and endTime are not sent, the most recent aggregate trades will be returned.
func (*Client) AllOrders ¶
func (c *Client) AllOrders(req *AllOrdersReq) ([]*QueryOrder, error)
AllOrders get all account orders; active, canceled, or filled
func (*Client) AvgPrice ¶
func (c *Client) AvgPrice(req *AvgPriceReq) (*AvgPrice, error)
Ticker returns 24 hour price change statistics
func (*Client) BookTicker ¶
func (c *Client) BookTicker(req *BookTickerReq) (*BookTicker, error)
BookTicker returns best price/qty on the order book for all symbols
func (*Client) BookTickers ¶
func (c *Client) BookTickers() ([]*BookTicker, error)
BookTickers returns best price/qty on the order book for all symbols
func (*Client) CancelOpenOrders ¶
func (c *Client) CancelOpenOrders(req *CancelOpenOrdersReq) ([]*CancelOrder, error)
CancelOpenOrders cancel all open orders on a symbol
func (*Client) CancelOrder ¶
func (c *Client) CancelOrder(req *CancelOrderReq) (*CancelOrder, error)
CancelOrder cancel an active order
func (*Client) DataStream ¶
DatastreamReq starts a new user datastream
func (*Client) DataStreamClose ¶
DataStreamClose closes the datastream key
func (*Client) DataStreamKeepAlive ¶
DataStreamKeepAlive pings the datastream key to prevent timeout
func (*Client) ExchangeInfo ¶
func (c *Client) ExchangeInfo() (*ExchangeInfo, error)
func (*Client) Klines ¶
Klines returns kline/candlestick bars for a symbol. Klines are uniquely identified by their open time
func (*Client) NewOrder ¶
func (c *Client) NewOrder(req *OrderReq) (*OrderRespAck, error)
NewOrder sends in a new order
func (*Client) NewOrderFull ¶
func (c *Client) NewOrderFull(req *OrderReq) (*OrderRespFull, error)
NewOrderFull sends in a new order and return created full order info
func (*Client) NewOrderResult ¶
func (c *Client) NewOrderResult(req *OrderReq) (*OrderRespResult, error)
NewOrderResult sends in a new order and return created order
func (*Client) NewOrderTest ¶
NewOrderTest tests new order creation and signature/recvWindow long. Creates and validates a new order but does not send it into the matching engine
func (*Client) OpenOrders ¶
func (c *Client) OpenOrders(req *OpenOrdersReq) ([]*QueryOrder, error)
OpenOrders get all open orders on a symbol
func (*Client) Price ¶
func (c *Client) Price(req *TickerPriceReq) (*SymbolPrice, error)
Prices calculates the latest price for all symbols
func (*Client) Prices ¶
func (c *Client) Prices() ([]*SymbolPrice, error)
Prices calculates the latest price for all symbols
func (*Client) QueryOrder ¶
func (c *Client) QueryOrder(req *QueryOrderReq) (*QueryOrder, error)
QueryOrder checks an order's status
func (*Client) Ticker ¶
func (c *Client) Ticker(req *TickerReq) (*TickerStats, error)
Ticker returns 24 hour price change statistics
func (*Client) Tickers ¶
func (c *Client) Tickers() ([]*TickerStats, error)
Tickers returns 24 hour price change statistics
func (*Client) Time ¶
func (c *Client) Time() (*ServerTime, error)
Time tests connectivity to the Rest API and get the current server time
type DatastreamReq ¶
type DatastreamReq struct {
ListenKey string `json:"listenKey" url:"listenKey"`
}
type DepthElem ¶
type DepthElem struct { Quantity decimal.Decimal `json:"quantity"` Price decimal.Decimal `json:"price"` }
DepthElem represents a specific order in the order book
func (*DepthElem) UnmarshalJSON ¶
UnmarshalJSON unmarshal the given depth raw data and converts to depth struct
type DepthReq ¶
type DepthReq struct { Symbol string `url:"symbol"` // Symbol is the symbol to fetch data for Limit int `url:"limit"` // Limit is the number of order book items to retrieve. Max 100 }
DepthReq are used to specify symbol to retrieve order book for
type ExchangeInfo ¶
type ExchangeInfo struct {
Symbols []SymbolInfo
}
type FilterType ¶
type FilterType string
const ( FilterTypePrice FilterType = "PRICE_FILTER" FilterTypeLotSize FilterType = "LOT_SIZE" FilterTypeMinNotional FilterType = "MIN_NOTIONAL" )
type KlineInterval ¶
type KlineInterval string
const ( KlineInterval1min KlineInterval = "1m" KlineInterval3min KlineInterval = "3m" KlineInterval5min KlineInterval = "5m" KlineInterval15min KlineInterval = "15m" KlineInterval30min KlineInterval = "30m" KlineInterval1hour KlineInterval = "1h" KlineInterval2hour KlineInterval = "2h" KlineInterval4hour KlineInterval = "4h" KlineInterval6hour KlineInterval = "6h" KlineInterval8hour KlineInterval = "8h" KlineInterval12hour KlineInterval = "12h" KlineInterval1day KlineInterval = "1d" KlineInterval3day KlineInterval = "3d" KlineInterval1week KlineInterval = "1w" KlineInterval1month KlineInterval = "1M" )
type Klines ¶
type Klines struct { OpenTime uint64 OpenPrice decimal.Decimal High decimal.Decimal Low decimal.Decimal ClosePrice decimal.Decimal Volume decimal.Decimal CloseTime uint64 QuoteAssetVolume decimal.Decimal Trades int TakerBuyBaseAssetVolume decimal.Decimal TakerBuyQuoteAssetVolume decimal.Decimal }
func (*Klines) UnmarshalJSON ¶
UnmarshalJSON unmarshal the given depth raw data and converts to depth struct
type KlinesReq ¶
type KlinesReq struct { Symbol string `url:"symbol"` // Symbol is the symbol to fetch data for Interval KlineInterval `url:"interval"` // Interval is the interval for each kline/candlestick Limit int `url:"limit"` // Limit is the maximal number of elements to receive. Max 500 StartTime uint64 `url:"startTime,omitempty"` EndTime uint64 `url:"endTime,omitempty"` }
type OpenOrdersReq ¶
type OpenOrdersReq struct {
Symbol string `url:"symbol"`
}
type OrderFailure ¶
type OrderFailure string
const ( OrderFailureNone OrderFailure = "NONE" OrderFailureUnknownInstrument OrderFailure = "UNKNOWN_INSTRUMENT" OrderFailureMarketClosed OrderFailure = "MARKET_CLOSED" OrderFailurePriceExceed OrderFailure = "PRICE_QTY_EXCEED_HARD_LIMITS" OrderFailureUnknownOrder OrderFailure = "UNKNOWN_ORDER" OrderFailureDuplicate OrderFailure = "DUPLICATE_ORDER" OrderFailureUnknownAccount OrderFailure = "UNKNOWN_ACCOUNT" OrderFailureInsufficientFunds OrderFailure = "INSUFFICIENT_BALANCE" OrderFailureAccountInaactive OrderFailure = "ACCOUNT_INACTIVE" OrderFailureAccountSettle OrderFailure = "ACCOUNT_CANNOT_SETTLE" )
type OrderReq ¶
type OrderReq struct { Symbol string `url:"symbol"` Side OrderSide `url:"side"` Type OrderType `url:"type"` Quantity string `url:"quantity,omitempty"` QuoteQuantity string `url:"quoteOrderQty,omitempty"` Price string `url:"price,omitempty"` TimeInForce TimeInForce `url:"timeInForce,omitempty"` NewClientOrderId string `url:"newClientOrderId,omitempty"` StopPrice string `url:"stopPrice,omitempty"` IcebergQty string `url:"icebergQty,omitempty"` OrderRespType OrderRespType `url:"newOrderRespType,omitempty"` }
type OrderRespAck ¶
type OrderRespFull ¶
type OrderRespFull struct { Symbol string `json:"symbol"` OrderID int `json:"orderId"` OrderListID int `json:"orderListId"` ClientOrderID string `json:"clientOrderId"` TransactTime int64 `json:"transactTime"` Price string `json:"price"` OrigQty string `json:"origQty"` ExecutedQty string `json:"executedQty"` CummulativeQuoteQty string `json:"cummulativeQuoteQty"` Status OrderStatus `json:"status"` TimeInForce string `json:"timeInForce"` Type OrderType `json:"type"` Side OrderSide `json:"side"` Fills []OrderRespFullFill `json:"fills"` }
type OrderRespFullFill ¶
type OrderRespResult ¶
type OrderRespResult struct { Symbol string `json:"symbol"` OrderID int `json:"orderId"` OrderListID int `json:"orderListId"` ClientOrderID string `json:"clientOrderId"` TransactTime int64 `json:"transactTime"` Price string `json:"price"` OrigQty string `json:"origQty"` ExecutedQty string `json:"executedQty"` CummulativeQuoteQty string `json:"cummulativeQuoteQty"` Status OrderStatus `json:"status"` TimeInForce string `json:"timeInForce"` Type OrderType `json:"type"` Side OrderSide `json:"side"` }
type OrderRespType ¶
type OrderRespType string
type OrderStatus ¶
type OrderStatus string
const ( OrderStatusNew OrderStatus = "NEW" OrderStatusPartial OrderStatus = "PARTIALLY_FILLED" OrderStatusFilled OrderStatus = "FILLED" OrderStatusCanceled OrderStatus = "CANCELED" OrderStatusPending OrderStatus = "PENDING_CANCEL" OrderStatusRejected OrderStatus = "REJECTED" OrderStatusExpired OrderStatus = "EXPIRED" OrderStatusReplaced OrderStatus = "REPLACED" OrderStatusTrade OrderStatus = "TRADE" )
type OrderType ¶
type OrderType string
OrderType represents the order type
const ( OrderTypeMarket OrderType = "MARKET" OrderTypeLimit OrderType = "LIMIT" OrderTypeStopLoss OrderType = "STOP_LOSS" OrderTypeStopLossLimit OrderType = "STOP_LOSS_LIMIT" OrderTypeTakeProfit OrderType = "TAKE_PROFIT" OrderTypeTakeProfitLimit OrderType = "TAKE_PROFIT_LIMIT" OrderTypeLimitMaker OrderType = "LIMIT_MAKER" )
type QueryOrder ¶
type QueryOrder struct { Symbol string `json:"symbol"` OrderID int `json:"orderId"` OrderListID int `json:"orderListId"` ClientOrderID string `json:"clientOrderId"` Price string `json:"price"` OrigQty string `json:"origQty"` ExecutedQty string `json:"executedQty"` CummulativeQuoteQty string `json:"cummulativeQuoteQty"` Status OrderStatus `json:"status"` TimeInForce TimeInForce `json:"timeInForce"` Type OrderType `json:"type"` Side OrderSide `json:"side"` StopPrice string `json:"stopPrice"` IcebergQty string `json:"IcebergQty"` Time uint64 `json:"time"` UpdateTime uint64 `json:"updateTime"` OrigQuoteOrderQty string `json:"origQuoteOrderQty"` }
type QueryOrderReq ¶
type QueryOrderReq struct { Symbol string `url:"symbol"` OrderID int `url:"orderId,omitempty"` OrigClientOrderId string `url:"origClientOrderId,omitempty"` }
QueryOrderReq represents the request for querying an order Remark: Either OrderID or OrigOrderiD must be set
type ServerTime ¶
type ServerTime struct {
ServerTime uint64 `json:"serverTime"`
}
type SymbolInfo ¶
type SymbolInfo struct { Symbol string `json:"symbol"` Status SymbolStatus `json:"status"` BaseAsset string `json:"baseAsset"` BaseAssetPrecision int `json:"baseAssetPrecision"` QuoteAsset string `json:"quoteAsset"` QuoteAssetPrecision int `json:"quoteAssetPrecision"` BaseCommissionPrecision int `json:"baseCommissionPrecision"` QuoteCommissionPrecision int `json:"quoteCommissionPrecision"` OrderTypes []OrderType `json:"orderTypes"` IcebergAllowed bool `json:"icebergAllowed"` OCOAllowed bool `json:"ocoAllowed"` QuoteQtyAllowed bool `json:"quoteOrderQtyMarketAllowed"` Filters []SymbolInfoFilter `json:"filters"` }
type SymbolInfoFilter ¶
type SymbolInfoFilter struct { Type FilterType `json:"filterType"` // PRICE_FILTER parameters MinPrice string `json:"minPrice"` MaxPrice string `json:"maxPrice"` TickSize string `json:"tickSize"` // LOT_SIZE parameters MinQty string `json:"minQty"` MaxQty string `json:"maxQty"` StepSize string `json:"stepSize"` // MIN_NOTIONAL parameters MinNotional string `json:"minNotional"` }
type SymbolPrice ¶
type TickerPriceReq ¶
type TickerPriceReq struct {
Symbol string `url:"symbol"`
}
type TickerReq ¶
type TickerReq struct {
Symbol string `url:"symbol"`
}
TickerReq represents the request for a specified ticker
type TickerStats ¶
type TickerStats struct { Symbol string `json:"symbol"` PriceChange string `json:"priceChange"` PriceChangePercentage string `json:"priceChangePercent"` WeightedAvgPrice string `json:"weightedAvgPrice"` PrevClosePrice string `json:"prevClosePrice"` LastPrice string `json:"lastPrice"` BidPrice string `json:"bidPrice"` AskPrice string `json:"askPrice"` OpenPrice string `json:"openPrice"` HighPrice string `json:"highPrice"` // HighPrice is 24hr high price LowPrice string `json:"lowPrice"` // LowPrice is 24hr low price Volume string `json:"volume"` QuoteVolume string `json:"quoteVolume"` OpenTime uint64 `json:"openTime"` CloseTime uint64 `json:"closeTime"` FirstID int `json:"firstId"` LastID int `json:"lastId"` Count int `json:"count"` }
TickerStats is the stats for a specific symbol
type TimeInForce ¶
type TimeInForce string
const ( TimeInForceGTC TimeInForce = "GTC" // Good Till Cancel TimeInForceIOC TimeInForce = "IOC" // Immediate or Cancel TimeInForceFOK TimeInForce = "FOK" // Fill or Kill )