Documentation
¶
Overview ¶
Package huobi is the library behind the huobi command line: the HTTP client, request shaping, and the typed data models for Huobi (HTX) 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) GetKlines(ctx context.Context, symbol, period string, count int) ([]*Candle, error)
- func (c *Client) GetSymbols(ctx context.Context, state string, limit int) ([]*Symbol, error)
- func (c *Client) GetTicker(ctx context.Context, symbol string) (*Ticker, error)
- type Domain
- type Symbol
- type Ticker
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "huobi-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to Huobi.
const Host = "api.huobi.pro"
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 {
ID int64 `kit:"id" json:"id"` // unix timestamp
Open float64 `json:"open"`
High float64 `json:"high"`
Low float64 `json:"low"`
Close float64 `json:"close"`
Vol float64 `json:"vol"`
}
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 Huobi public API over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 15s timeout, a 200ms minimum gap between requests, and three retries on transient errors.
func (*Client) Get ¶
Get fetches rawURL and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetKlines ¶
func (c *Client) GetKlines(ctx context.Context, symbol, period string, count int) ([]*Candle, error)
GetKlines fetches candlestick data for a symbol.
func (*Client) GetSymbols ¶
GetSymbols fetches all trading pairs from the exchange, optionally filtered by state and limited in count. Both filters are applied client-side.
type Domain ¶
type Domain struct{}
Domain is the Huobi 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"`
Base string `json:"base"`
Quote string `json:"quote"`
State string `json:"state"`
PricePrecision int `json:"price_precision"`
}
Symbol describes a trading pair listed on Huobi.
type Ticker ¶
type Ticker struct {
Symbol string `kit:"id" json:"symbol"`
Last float64 `json:"last"` // close price
Bid float64 `json:"bid"` // best bid price
Ask float64 `json:"ask"` // best ask price
Open float64 `json:"open_24h"`
High float64 `json:"high_24h"`
Low float64 `json:"low_24h"`
Vol float64 `json:"vol_24h"` // quote volume
}
Ticker holds current price and 24-hour stats for a symbol.