Documentation
¶
Overview ¶
Package bybit is the library behind the bybit command line: the HTTP client, request shaping, and the typed data models for the Bybit public market data API (https://api.bybit.com/v5).
The Client sets an honest User-Agent, paces requests to stay polite, and retries transient failures (429 and 5xx). Build endpoint calls and JSON decoding on top of it.
Index ¶
- Constants
- type Candle
- type Client
- func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)
- func (c *Client) GetKline(ctx context.Context, category, symbol, interval string, count int) ([]*Candle, error)
- func (c *Client) GetTicker(ctx context.Context, category, symbol string) (*Ticker, error)
- func (c *Client) ListInstruments(ctx context.Context, category string, limit int) ([]*Instrument, error)
- func (c *Client) ListTickers(ctx context.Context, category string, limit int) ([]*Ticker, error)
- type Config
- type Domain
- type Instrument
- type Ticker
Constants ¶
const BaseURL = "https://" + Host + "/v5"
BaseURL is the v5 API root every request is built from.
const DefaultUserAgent = "bybit-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to Bybit.
const Host = "api.bybit.com"
Host is the API hostname for Bybit public market data.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Candle ¶
type Candle struct {
Timestamp string `kit:"id" json:"timestamp"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
Volume string `json:"volume"`
}
Candle holds one OHLCV bar for a symbol.
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
BaseURL 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 Bybit v5 public market API over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with the default configuration.
func NewClientFromConfig ¶
NewClientFromConfig returns a Client from the provided Config.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client settings. The body is read fully and closed here.
func (*Client) GetKline ¶
func (c *Client) GetKline(ctx context.Context, category, symbol, interval string, count int) ([]*Candle, error)
GetKline returns candlestick data for a symbol.
func (*Client) ListInstruments ¶
func (c *Client) ListInstruments(ctx context.Context, category string, limit int) ([]*Instrument, error)
ListInstruments returns up to limit instruments for the given category.
type Config ¶
type Config struct {
BaseURL string
UserAgent string
Rate time.Duration
Timeout time.Duration
Retries int
}
Config holds tunable client parameters.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns sensible defaults for talking to the Bybit public API.
type Domain ¶
type Domain struct{}
Domain is the bybit driver.
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme and identity used for the binary and any host.
type Instrument ¶
type Instrument struct {
Symbol string `kit:"id" json:"symbol"`
Base string `json:"base"`
Quote string `json:"quote"`
Status string `json:"status"`
}
Instrument holds the basic info for a tradeable instrument.
type Ticker ¶
type Ticker struct {
Symbol string `kit:"id" json:"symbol"`
Last string `json:"last"`
Bid string `json:"bid"`
Ask string `json:"ask"`
High24h string `json:"high_24h"`
Low24h string `json:"low_24h"`
Volume24h string `json:"volume_24h"`
Change24h string `json:"change_24h_pct"`
}
Ticker holds the current price and 24 h stats for one symbol.