bybit

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
const BaseURL = "https://" + Host + "/v5"

BaseURL is the v5 API root every request is built from.

View Source
const DefaultUserAgent = "bybit-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to Bybit.

View Source
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

func NewClientFromConfig(cfg Config) *Client

NewClientFromConfig returns a Client from the provided Config.

func (*Client) Get

func (c *Client) Get(ctx context.Context, rawURL string) ([]byte, error)

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) GetTicker

func (c *Client) GetTicker(ctx context.Context, category, symbol string) (*Ticker, error)

GetTicker returns the current ticker for a single symbol in category.

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.

func (*Client) ListTickers

func (c *Client) ListTickers(ctx context.Context, category string, limit int) ([]*Ticker, error)

ListTickers returns up to limit tickers 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.

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL