Documentation
¶
Index ¶
- Constants
- func BinanceApiProxy(w http.ResponseWriter, r *http.Request)
- func NewBinanceApiProxyHandler() http.Handler
- type AccountInfoBalance
- type AccountInfoResponse
- type AggTradeStream
- type AggTradeStreamEvent
- type CancelOrderResponse
- type CombinedStream24TickerAll
- type CombinedStreamAggTrade
- type CombinedStreamMessage
- type CombinedStreamUnknown
- type ExchangeInfoResponse
- type ExchangeInfoService
- func (s *ExchangeInfoService) GetMinNotional(symbol string) (float64, error)
- func (s *ExchangeInfoService) GetStepSize(symbol string) (float64, error)
- func (s *ExchangeInfoService) GetSymbol(symbol string) (info SymbolInfo, err error)
- func (s *ExchangeInfoService) GetTickSize(symbol string) (float64, error)
- func (s *ExchangeInfoService) Update() error
- type OrderBookTickerResponse
- type OrderParameters
- type OrderSide
- type OrderStatus
- type OrderType
- type PostOrderResponse
- type PriceTickerResponse
- type QueryOrderResponse
- type RestApiError
- type RestClient
- func (c *RestClient) BuildQueryString(params map[string]interface{}) string
- func (c *RestClient) CancelOrder(symbol string, orderId int64) (*CancelOrderResponse, error)
- func (c *RestClient) Delete(endpoint string, params map[string]interface{}) (*http.Response, error)
- func (c *RestClient) DoPut(path string) (*http.Response, error)
- func (c *RestClient) Get(endpoint string, params map[string]interface{}) (*http.Response, error)
- func (c *RestClient) GetAccount() (*AccountInfoResponse, error)
- func (c *RestClient) GetAllPriceTicker() ([]PriceTickerResponse, error)
- func (c *RestClient) GetAllSymbols() ([]string, error)
- func (c *RestClient) GetMytrades(symbol string, limit int64, fromId int64) ([]TradeResponse, error)
- func (c *RestClient) GetOrderBookTicker(symbol string) (OrderBookTickerResponse, error)
- func (c *RestClient) GetOrderByClientId(symbol string, clientId string) (QueryOrderResponse, error)
- func (c *RestClient) GetOrderByOrderId(symbol string, orderId int64) (QueryOrderResponse, error)
- func (c *RestClient) GetPriceTicker(symbol string) (PriceTickerResponse, error)
- func (c *RestClient) GetUserDataStream() (string, error)
- func (c *RestClient) GetWithAuth(endpoint string, params map[string]interface{}) (*http.Response, error)
- func (c *RestClient) Post(endpoint string, params map[string]interface{}) (*http.Response, error)
- func (c *RestClient) PostOrder(order OrderParameters) (*http.Response, error)
- func (c *RestClient) PostWithApiKey(endpoint string, params map[string]interface{}) (*http.Response, error)
- func (c *RestClient) PutUserStreamKeepAlive(listenKey string) error
- type Stream24Ticker
- type Stream24TickerAll
- type StreamAccountInfoBalance
- type StreamAggTrade
- type StreamClient
- type StreamExecutionReport
- type StreamOutboundAccountInfo
- type SymbolFilterResponse
- type SymbolInfo
- type SymbolInfoResponse
- type TimeInForce
- type TradeResponse
- type UserDataStreamResponse
Constants ¶
const API_ROOT = "https://api.binance.com"
const WS_STREAM_URL = "wss://stream.binance.com:9443"
Variables ¶
This section is empty.
Functions ¶
func BinanceApiProxy ¶
func BinanceApiProxy(w http.ResponseWriter, r *http.Request)
BinanceApiProxy is a standard web handler function that will proxy requests to the Binance API.
func NewBinanceApiProxyHandler ¶
NewBinanceApiProxyHandler return the Binance API proxy as a http.Handler.
Useful if you need to strip the prefix, for example:
router.PathPrefix("/proxy/binance").Handler(
http.StripPrefix("/proxy/binance", NewBinanceApiProxyHandler()))
Types ¶
type AccountInfoBalance ¶
type AccountInfoResponse ¶
type AccountInfoResponse struct {
MakerCommission int64 `json:"makerCommission"`
TakerCommission int64 `json:"takerCommission"`
BuyerCommission int64 `json:"buyerCommission"`
SellCommission int64 `json:"sellCommission"`
CanTrade bool `json:"canTrade"`
CanWithdraw bool `json:"canWithdraw"`
CanDeposit bool `json:"canDeposit"`
UpdateTimeMillis int64 `json:"updateTime"`
Balances []AccountInfoBalance `json:"balances"`
}
type AggTradeStream ¶
type AggTradeStream struct {
// contains filtered or unexported fields
}
func OpenAggTradeStream ¶
func OpenAggTradeStream(symbol string) (*AggTradeStream, error)
func (*AggTradeStream) Close ¶
func (c *AggTradeStream) Close()
Close closes the AggTradeStream. If there is a subscribed channel it will no longer be sent any data. So it is up to the subscriber to stop attempting to read from the channel.
func (*AggTradeStream) Next ¶
func (c *AggTradeStream) Next() (trade *StreamAggTrade, err error)
func (*AggTradeStream) Subscribe ¶
func (c *AggTradeStream) Subscribe(channel chan AggTradeStreamEvent)
type AggTradeStreamEvent ¶
type AggTradeStreamEvent struct {
Err error
Trade *StreamAggTrade
}
type CancelOrderResponse ¶
type CombinedStream24TickerAll ¶
type CombinedStream24TickerAll struct {
Stream string `json:"stream"`
Tickers Stream24TickerAll `json:"data"`
}
type CombinedStreamAggTrade ¶
type CombinedStreamAggTrade struct {
Stream string `json:"stream"`
AggTrade StreamAggTrade `json:"data"`
}
type CombinedStreamMessage ¶
type CombinedStreamMessage struct {
Stream string
// Data for !ticker@arr messages.
Tickers []Stream24Ticker
// Data for <symbol>@aggTrade messages.
AggTrade *StreamAggTrade
// For a stream that is unknown, decode the data into an interface{}.
UnknownData interface{}
Bytes []byte
}
func DecodeRawStreamMessage ¶
func DecodeRawStreamMessage(b []byte) (CombinedStreamMessage, error)
func (*CombinedStreamMessage) UnmarshalJSON ¶
func (r *CombinedStreamMessage) UnmarshalJSON(b []byte) error
type CombinedStreamUnknown ¶
type CombinedStreamUnknown struct {
Stream string `json:"stream"`
Data interface{} `json:"data"`
}
Generic data type for a combined stream when it is not known how to decode the stream.
type ExchangeInfoResponse ¶
type ExchangeInfoResponse struct {
Timezone string `json:"timezone"`
ServerTimeMillis int64 `json:"serverTime"`
RateLimits []struct {
RateLimitType string `json:"rateLimitType"`
RateLimitInterval string `json"rateLimitInterval"`
Limit int64 `json"limit"`
}
Symbols []SymbolInfoResponse `json:"symbols"`
RawResponse []byte `json:"-"`
}
func GetExchangeInfo ¶
func GetExchangeInfo() (*ExchangeInfoResponse, error)
type ExchangeInfoService ¶
type ExchangeInfoService struct {
Symbols map[string]SymbolInfo
}
func NewExchangeInfoService ¶
func NewExchangeInfoService() *ExchangeInfoService
func (*ExchangeInfoService) GetMinNotional ¶
func (s *ExchangeInfoService) GetMinNotional(symbol string) (float64, error)
GetMinNotional returns the minimum notional value for the requested symbol.
func (*ExchangeInfoService) GetStepSize ¶
func (s *ExchangeInfoService) GetStepSize(symbol string) (float64, error)
GetStepSize returns the step size for the requested symbol.
func (*ExchangeInfoService) GetSymbol ¶
func (s *ExchangeInfoService) GetSymbol(symbol string) (info SymbolInfo, err error)
GetSymbol returns the symbol info object for the requested symbol.
func (*ExchangeInfoService) GetTickSize ¶
func (s *ExchangeInfoService) GetTickSize(symbol string) (float64, error)
GetTickSize returns the tick size for the requested symbol.
func (*ExchangeInfoService) Update ¶
func (s *ExchangeInfoService) Update() error
type OrderBookTickerResponse ¶
type OrderParameters ¶
type OrderStatus ¶
type OrderStatus string
Order status / execution type.
const ( OrderStatusNew OrderStatus = "NEW" OrderStatusCanceled OrderStatus = "CANCELED" OrderStatusFilled OrderStatus = "FILLED" OrderStatusPartiallyFilled OrderStatus = "PARTIALLY_FILLED" )
type PostOrderResponse ¶
type PostOrderResponse struct {
Symbol string `json:"symbol"`
OrderId int64 `json:"orderId"`
ClientOrderId string `json:"clientOrderId"`
TransactionTimeMillis int64 `json:"transactTime"`
}
TODO: Implement RESULT and FULL response types. Currently only ACK implemented.
type PriceTickerResponse ¶
type QueryOrderResponse ¶
type QueryOrderResponse struct {
Symbol string `json:"symbol"`
OrderId int64 `json:"orderId"`
ClientOrderId string `json:"clientOrderId"`
Price float64 `json:"price,string"`
OrigQty float64 `json:"origQty,string"`
ExecutedQty float64 `json:"executeQty,string"`
Status OrderStatus `json:"status"`
TimeInForce TimeInForce `json:"timeInForce"`
Type OrderType `json:"type"`
Side OrderSide `json:"side"`
StopPrice float64 `json:"stopPrice,string"`
IcebergQty float64 `json:"icebergQty,string"`
TimeMillis int64 `json:"time"`
IsWorking bool `json:"isWorking"`
}
type RestApiError ¶
func NewRestApiErrorFromResponse ¶
func NewRestApiErrorFromResponse(r *http.Response) *RestApiError
func (*RestApiError) Error ¶
func (e *RestApiError) Error() string
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
func NewAnonymousClient ¶
func NewAnonymousClient() *RestClient
func NewAuthenticatedClient ¶
func NewAuthenticatedClient(key string, secret string) *RestClient
func (*RestClient) BuildQueryString ¶
func (c *RestClient) BuildQueryString(params map[string]interface{}) string
func (*RestClient) CancelOrder ¶
func (c *RestClient) CancelOrder(symbol string, orderId int64) (*CancelOrderResponse, error)
func (*RestClient) GetAccount ¶
func (c *RestClient) GetAccount() (*AccountInfoResponse, error)
func (*RestClient) GetAllPriceTicker ¶
func (c *RestClient) GetAllPriceTicker() ([]PriceTickerResponse, error)
Return the latest prices for all symbols.
func (*RestClient) GetAllSymbols ¶
func (c *RestClient) GetAllSymbols() ([]string, error)
func (*RestClient) GetMytrades ¶
func (c *RestClient) GetMytrades(symbol string, limit int64, fromId int64) ([]TradeResponse, error)
func (*RestClient) GetOrderBookTicker ¶
func (c *RestClient) GetOrderBookTicker(symbol string) (OrderBookTickerResponse, error)
func (*RestClient) GetOrderByClientId ¶
func (c *RestClient) GetOrderByClientId(symbol string, clientId string) (QueryOrderResponse, error)
func (*RestClient) GetOrderByOrderId ¶
func (c *RestClient) GetOrderByOrderId(symbol string, orderId int64) (QueryOrderResponse, error)
func (*RestClient) GetPriceTicker ¶
func (c *RestClient) GetPriceTicker(symbol string) (PriceTickerResponse, error)
func (*RestClient) GetUserDataStream ¶
func (c *RestClient) GetUserDataStream() (string, error)
GetUserDataStream makes the get request for a user data stream listen key.
func (*RestClient) GetWithAuth ¶
func (c *RestClient) GetWithAuth(endpoint string, params map[string]interface{}) (*http.Response, error)
Perform a fully authenticated GET request.
func (*RestClient) PostOrder ¶
func (c *RestClient) PostOrder(order OrderParameters) (*http.Response, error)
func (*RestClient) PostWithApiKey ¶
func (c *RestClient) PostWithApiKey(endpoint string, params map[string]interface{}) (*http.Response, error)
Send a POST request with only the API key and no other authentication.
func (*RestClient) PutUserStreamKeepAlive ¶
func (c *RestClient) PutUserStreamKeepAlive(listenKey string) error
type Stream24Ticker ¶
type Stream24Ticker struct {
EventType string `json:"e"`
EventTime int64 `json:"E"`
Symbol string `json:"s"`
PriceChange float64 `json:"p,string"`
PriceChangePercent float64 `json:"P,string"`
WeightedAveragePrice float64 `json:"w,string"`
PreviousDayClose float64 `json:"x,string"`
CurrentDayClose float64 `json:"c,string"`
CloseTradeQuantity float64 `json:"Q,string"`
Bid float64 `json:"b,string"`
BidQuantity float64 `json:"B,string"`
Ask float64 `json:"a,string"`
AskQuantity float64 `json:"A,string"`
OpenPrice float64 `json:"o,string"`
HighPrice float64 `json:"h,string"`
LowPrice float64 `json:"l,string"`
TotalBaseVolume float64 `json:"v,string"`
TotalQuoteVolume float64 `json:"q,string"`
StatsOpenTime int64 `json:"O"`
StatsCloseTime int64 `json:"C"`
FirstTradeID int64 `json:"F"`
LastTradeID int64 `json:"L"`
TotalNumberTrades int64 `json:"n"`
}
Stream name: <symbol>@ticker.
func (*Stream24Ticker) Timestamp ¶
func (t *Stream24Ticker) Timestamp() time.Time
type StreamAggTrade ¶
type StreamAggTrade struct {
EventType string `json:"e"`
EventTimeMillis int64 `json:"E"`
Symbol string `json:"s"`
TradeID int64 `json:"a"`
Price float64 `json:"p,string"`
Quantity float64 `json:"q,string"`
FirstTradeID int64 `json:"f"`
LastTradeID int64 `json:"l"`
TradeTimeMillis int64 `json:"T"`
BuyerMaker bool `json:"m"`
Ignored bool `json:"M"`
}
Stream name: <symbol>@aggTrade.
func (*StreamAggTrade) QuoteQuantity ¶
func (t *StreamAggTrade) QuoteQuantity() float64
func (*StreamAggTrade) Timestamp ¶
func (t *StreamAggTrade) Timestamp() time.Time
type StreamClient ¶
func NewStreamClient ¶
func NewStreamClient() *StreamClient
func OpenSingleStream ¶
func OpenSingleStream(stream string) (*StreamClient, error)
func OpenUserStream ¶
func OpenUserStream(restClient *RestClient) (*StreamClient, error)
func (*StreamClient) Close ¶
func (c *StreamClient) Close()
func (*StreamClient) Connect ¶
func (c *StreamClient) Connect(streams ...string) (err error)
func (*StreamClient) ConnectSingle ¶
func (c *StreamClient) ConnectSingle(stream string) (err error)
func (*StreamClient) NextJSON ¶
func (c *StreamClient) NextJSON() (interface{}, error)
Next reads the next message into a generic map.
type StreamExecutionReport ¶
type StreamExecutionReport struct {
EventType string `json:"e"`
EventTimeMillis int64 `json:"E"`
Symbol string `json:"s"`
ClientOrderID string `json:"c"`
Side OrderSide `json:"S"`
OrderType string `json:"o"`
TimeInForce string `json:"f"`
Quantity float64 `json:"q,string"`
Price float64 `json:"p,string"`
StopPrice float64 `json:"P,string"`
IcebergQuantity float64 `json:"F,string"`
OriginalClientOrderID string `json:"C"`
CurrentExecutionType OrderStatus `json:"x"`
CurrentOrderStatus OrderStatus `json:"X"`
OrderRejectReason string `json:"r"`
OrderID int64 `json:"i"`
LastExecutedQuantity float64 `json:"l,string"`
CumulativeFilledQuantity float64 `json:"z,string"`
LastExecutedPrice float64 `json:"L,string"`
CommissionAmount float64 `json:"n,string"`
CommissionAsset string `json:"N"`
TransactionTimeMillis int64 `json:"T"`
TradeID int64 `json:"t"`
IsWorking bool `json:"w"`
IsMaker bool `json:"m"`
// Ignore values that we have to include here due to the case insensitivity
// of the Go JSON unmarshaller.
Ignore0 int64 `json:"O,-"`
Ignore1 interface{} `json:"I,-"`
}
type StreamOutboundAccountInfo ¶
type StreamOutboundAccountInfo struct {
EventType string `json:"e"`
EventTimeMillis int64 `json:"E"`
MakerCommissionRate int64 `json:"m"`
TakerCommissionRate int64 `json:"t"`
BuyerCommissionRate int64 `json:"b"`
SellerCommissionRate int64 `json:"s"`
CanTrade bool `json:"T"`
CanWithdraw bool `json:"W"`
CanDeposit bool `json:"D"`
LastAccountUpdateTime int64 `json:"u"`
Balances []StreamAccountInfoBalance `json:"B"`
}
type SymbolFilterResponse ¶
type SymbolFilterResponse struct {
FilterType string `json:"filterType"`
MinPrice float64 `json:"minPrice,string"`
MaxPrice float64 `json:"maxPrice,string"`
TickSize float64 `json:"tickSize,string"`
MinQty float64 `json:"minQty,string"`
MaxQty float64 `json:"maxQty,string"`
StepSize float64 `json:"stepSize,string"`
MinNotional float64 `json:"minNotional,string"`
}
type SymbolInfo ¶
type SymbolInfoResponse ¶
type SymbolInfoResponse struct {
Symbol string `json:"symbol"`
Status string `json:"status"`
BaseAsset string `json:"baseAsset"`
BaseAssetPrecision int64 `json:"baseAssetPrecision`
QuoteAsset string `json:"quoteAsset"`
QuoteAssetPrecision int64 `json:"quoteAssetPrecision"`
OrderTypes []string `json:"orderTypes"`
IcebergAllowed bool `json:"icebergAllowed"`
Filters []SymbolFilterResponse `json:"filters"`
}
type TimeInForce ¶
type TimeInForce string
const ( TimeInForceGTC TimeInForce = "GTC" TimeInForceIOC TimeInForce = "IOC" TimeInForceFOK TimeInForce = "FOK" )
type TradeResponse ¶
type TradeResponse struct {
ID int64 `json:"id"`
OrderID int64 `json:"orderId"`
Price float64 `json:"price,string"`
Quantity float64 `json:"qty,string"`
Commission float64 `json:"commission,string"`
CommissionAsset string `json:"commissionAsset"`
TimeMillis int64 `json:"time"`
IsBuyer bool `json:"isBuyer"`
IsMaker bool `json:"isMaker"`
IsBestMatch bool `json:"isBestMatch"`
}
GET /api/v3/myTrades
type UserDataStreamResponse ¶
type UserDataStreamResponse struct {
ListenKey string `json:"listenKey"`
}