Documentation
¶
Overview ¶
Package binance is the library behind the binance command line: the HTTP client, request shaping, and the typed data models for Binance public market data.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.
Index ¶
- Constants
- type Candle
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetAllPrices(ctx context.Context) ([]*Price, error)
- func (c *Client) GetAllTickers(ctx context.Context) ([]*Ticker, error)
- func (c *Client) GetKlines(ctx context.Context, symbol, interval string, limit int) ([]*Candle, error)
- func (c *Client) GetPrice(ctx context.Context, symbol string) (*Price, error)
- func (c *Client) GetSymbols(ctx context.Context, limit int) ([]*Symbol, error)
- func (c *Client) GetTicker(ctx context.Context, symbol string) (*Ticker, error)
- func (c *Client) GetTopGainers(ctx context.Context, limit int) ([]*Ticker, error)
- type Domain
- type Price
- type Symbol
- type Ticker
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "binance-cli/dev (+https://github.com/tamnd/binance-cli)"
DefaultUserAgent identifies the client to Binance.
const Host = "api.binance.com"
Host is the API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Candle ¶
type Candle struct {
Symbol string `kit:"id" json:"symbol"`
OpenTime int64 `json:"open_time"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
Volume string `json:"volume"`
CloseTime int64 `json:"close_time"`
Trades int `json:"trades"`
}
Candle is one OHLCV candlestick bar.
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to the Binance public API over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 200ms minimum gap between requests, and five retries on transient errors.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.
func (*Client) GetAllPrices ¶
GetAllPrices fetches current prices for all symbols.
func (*Client) GetAllTickers ¶
GetAllTickers fetches 24-hour rolling stats for every symbol.
func (*Client) GetKlines ¶
func (c *Client) GetKlines(ctx context.Context, symbol, interval string, limit int) ([]*Candle, error)
GetKlines fetches candlestick data for a symbol.
func (*Client) GetSymbols ¶
GetSymbols fetches all trading pairs from exchangeInfo.
type Domain ¶
type Domain struct{}
Domain is the Binance driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type Symbol ¶
type Symbol struct {
Symbol string `kit:"id" json:"symbol"`
BaseAsset string `json:"base_asset"`
QuoteAsset string `json:"quote_asset"`
Status string `json:"status"`
}
Symbol describes a trading pair listed on Binance.
type Ticker ¶
type Ticker struct {
Symbol string `kit:"id" json:"symbol"`
PriceChange string `json:"price_change"`
PriceChangePct string `json:"price_change_pct"`
LastPrice string `json:"last_price"`
HighPrice string `json:"high_price"`
LowPrice string `json:"low_price"`
Volume string `json:"volume"`
QuoteVolume string `json:"quote_volume"`
}
Ticker holds 24-hour rolling-window statistics for a symbol.