This directory contains working examples demonstrating how to use the Bybit Go SDK.
- Set up environment variables for authenticated examples (public market-data and kline receipt examples require no API keys):
export BYBIT_API_KEY="your_api_key"
export BYBIT_API_SECRET="your_api_secret"- Install dependencies:
cd ..
go mod tidyEach example is a standalone Go program. Run them individually:
Demonstrates basic client initialization and server time retrieval.
go run basic_client/main.goShows how to fetch market data for multiple symbols.
go run market_data/main.goCaptures one GET /v5/market/kline response with a context and a 4 MiB body limit. No API credentials are needed. Captured body bytes go to stdout without re-encoding or an added newline, while a safe summary and SHA-256 digest go to stderr. Failure responses may still produce partial evidence; inspect the exit status and completeness before using the data.
go run kline_receipt/main.goThis command makes a real public request when run manually. The package tests use only injected transports and local HTTP servers. See the receipt API documentation for bounds, errors, timestamps, and provider-result validation.
Demonstrates order placement, retrieval, and management.
go run order_management/main.goNote: This example requires valid API credentials with trading permissions.
Shows how to subscribe to public WebSocket streams (orderbook, trades, ticker, klines).
go run websocket_public/main.goPress Ctrl+C to stop the WebSocket listener.
Demonstrates authenticated WebSocket connections for account updates.
go run websocket_private/main.goNote: Requires valid API credentials.
Press Ctrl+C to stop the WebSocket listener.
- Demo Trading vs Mainnet: Most examples use demo trading by default. Change
Demo: falseto use mainnet. - API Permissions: Some examples require specific API key permissions (trading, wallet access).
- Rate Limits: Be mindful of Bybit's API rate limits when running examples repeatedly.
- WebSocket Examples: These run indefinitely until you press
Ctrl+C.
Each example follows this pattern:
- Load environment variables
- Initialize client/websocket
- Perform operations
- Display results
- Handle errors gracefully
Feel free to modify these examples to suit your needs. They serve as templates for building your own trading applications.