π Bybit Go SDK
β‘ Lightning-Fast V5 API Client for Golang


ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π― Production-Ready β’ π Secure β’ β‘ High-Performance β
β π Type-Safe β’ π Global β’ π Real-Time WebSocket β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Transform your trading ideas into reality with the most powerful Go SDK for Bybit V5 API
π Quick Start β’ π Documentation β’ π‘ Examples β’ π Features
π― Why Choose Bybit Go SDK?
π Go Native
Built from ground up for Golang, leveraging goroutines, channels, and idiomatic patterns
|
β‘ Blazing Fast
Optimized for low-latency trading with concurrent-safe operations
|
π Bank-Grade Security
HMAC-SHA256 & RSA-SHA256 signatures with best practices
|
πͺ Built for Real Traders
"Stop wrestling with API documentation. Start building profitable trading strategies."
π€ For Algorithmic Traders
- β¨ Execute complex strategies with millisecond precision
- π Real-time market data streaming via WebSocket
- π― Advanced order types: Limit, Market, Trigger, TP/SL
- π Automatic position management and risk controls
- π Built-in fee calculation for accurate P&L tracking
π¨βπ» For Developers
- π‘οΈ Type-safe operations eliminate runtime errors
- π§ͺ Testnet support for risk-free development
- π¦ Zero dependencies except gorilla/websocket
- π§ Flexible configuration with sensible defaults
- π Comprehensive examples and documentation
π’ For Production Systems
- βοΈ Thread-safe with mutex-protected operations
- π Smart reconnection with exponential backoff
- π Detailed error messages for debugging
- π Multi-region support for global deployment
- π¦ Rate limit handling built-in
π Table of Contents
β¨ Features That Set Us Apart
π¨ Complete Trading Arsenal
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Market Data β π° Trading β π Security β
β β’ Tickers β β’ Spot β β’ HMAC-SHA256 β
β β’ Orderbook β β’ Derivatives β β’ RSA-SHA256 β
β β’ Klines β β’ Limit/Market β β’ API Key Mgmt β
β β’ Trades β β’ TP/SL Orders β β’ Secure Storage β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β π WebSocket β βοΈ Management β π Global β
β β’ Real-time β β’ Positions β β’ Multi-region β
β β’ Public Streams β β’ Leverage β β’ Testnet/Mainnet β
β β’ Private Streams β β’ Risk Control β β’ Low Latency β
β β’ Auto-reconnect β β’ Wallet β β’ 24/7 Trading β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- π― Sub-millisecond latency for order execution
- π Goroutine-safe concurrent operations
- πͺ Production-tested in high-frequency environments
- π Zero-downtime with smart reconnection
- β‘ Optimized for minimal memory footprint
|
π Developer Experience
- π οΈ Plug & Play - Works out of the box
- π Rich Examples - Learn by doing
- π§ͺ Testnet First - Test before you invest
- π§ Highly Configurable - Adapt to your needs
- π Clear Documentation - No guesswork
|
π Bonus Features
| Feature |
Description |
Status |
| π Dual Authentication |
HMAC-SHA256 & RSA-SHA256 support |
β
Ready |
| π Global Endpoints |
NL, TR, KZ, GE, AE regions |
β
Ready |
| π‘ WebSocket Streams |
Real-time data with auto-reconnect |
β
Ready |
| π° Fee Calculator |
Built-in trading fee computation |
β
Ready |
| π― Smart Orders |
Advanced TP/SL with percentage/absolute |
β
Ready |
| π Position Management |
Leverage, hedging, one-way mode |
β
Ready |
π¦ Installation
Get Started in 30 Seconds β‘
Step 1: Install the package
go get github.com/tigusigalpa/bybit-go
Step 2: Import and use
import bybit "github.com/tigusigalpa/bybit-go"
Step 3: Start trading! π
π Alternative: Manual Installation
Add to your go.mod:
require github.com/tigusigalpa/bybit-go v1.0.0
Then run:
go mod tidy
βοΈ Configuration
ποΈ Flexible Configuration Options
|
π Quick Setup (Environment Variables)
export BYBIT_API_KEY="your_api_key"
export BYBIT_API_SECRET="your_secret"
export BYBIT_TESTNET="true"
export BYBIT_REGION="global"
π‘ Pro Tip: Use .env files for local development
|
βοΈ Programmatic Configuration
client, err := bybit.NewClient(
bybit.ClientConfig{
APIKey: os.Getenv("BYBIT_API_KEY"),
APISecret: os.Getenv("BYBIT_API_SECRET"),
Testnet: true,
Region: "global",
RecvWindow: 5000,
Signature: "hmac",
},
)
|
π Configuration Reference
| Parameter |
Type |
Default |
Description |
Example |
APIKey |
string |
required |
π Your Bybit API public key |
"abc123..." |
APISecret |
string |
required |
π Your Bybit API secret key |
"xyz789..." |
Testnet |
bool |
false |
π§ͺ Enable testnet environment |
true |
Region |
string |
"global" |
π Regional endpoint |
"nl", "tr", "kz" |
RecvWindow |
int |
5000 |
β±οΈ Request receive window (ms) |
10000 |
Signature |
string |
"hmac" |
π Signature type |
"hmac", "rsa" |
RSAPrivateKey |
string |
"" |
π RSA private key (PEM format) |
"-----BEGIN..." |
π Quick Start
π¬ From Zero to Trading in 3 Minutes
π― Example 1: Your First API Call
package main
import (
"fmt"
"log"
bybit "github.com/tigusigalpa/bybit-go"
)
func main() {
// π― Step 1: Initialize client
client, err := bybit.NewClient(bybit.ClientConfig{
APIKey: "your_api_key",
APISecret: "your_api_secret",
Testnet: true, // π§ͺ Safe testing environment
Region: "global",
Signature: "hmac",
})
if err != nil {
log.Fatal(err)
}
// β
Step 2: Verify connection
serverTime, err := client.GetServerTime()
if err != nil {
log.Fatal(err)
}
fmt.Printf("β
Connected! Server Time: %v\n", serverTime)
// π Step 3: Get real-time market data
tickers, err := client.GetTickers(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("π BTC Price: %v\n", tickers)
// π° Step 4: Place your first order
order, err := client.CreateOrder(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"side": "Buy",
"orderType": "Limit",
"qty": "0.01",
"price": "30000",
"timeInForce": "GTC",
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("π Order placed! ID: %v\n", order["result"].(map[string]interface{})["orderId"])
}
π Congratulations! You just made your first API call!
π‘ Example 2: Real-Time WebSocket Streaming
package main
import (
"fmt"
"log"
bybit "github.com/tigusigalpa/bybit-go"
)
func main() {
// π Create WebSocket connection
ws := bybit.NewWebSocket(bybit.WebSocketConfig{
Testnet: false,
Region: "global",
IsPrivate: false,
})
// π‘ Subscribe to real-time data
ws.SubscribeOrderbook("BTCUSDT", 50)
ws.SubscribeTrade("BTCUSDT")
ws.SubscribeTicker("BTCUSDT")
// π§ Listen to market updates
ws.OnMessage(func(data map[string]interface{}) {
if topic, ok := data["topic"].(string); ok {
fmt.Printf("π¨ Update from %s: %v\n", topic, data["data"])
}
})
// π Start streaming
fmt.Println("π¬ WebSocket streaming started! Press Ctrl+C to stop...")
if err := ws.Listen(); err != nil {
log.Fatal(err)
}
}
β‘ Real-time data streaming in just 20 lines of code!
π API Methods
π¨ Complete API Coverage
Every endpoint you need, beautifully wrapped
π Market Data
Get real-time prices, orderbooks, and historical data
|
π° Trading
Execute orders with precision and speed
|
π― Positions
Manage leverage, TP/SL, and risk
|
π Market Data APIs
Click to expand Market Data methods
// β° Get server time
time, err := client.GetServerTime()
// π Get market tickers (real-time prices)
tickers, err := client.GetTickers(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
})
// π Get orderbook depth
orderbook, err := client.GetOrderbook(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"limit": 50,
})
// π Get klines/candlesticks
klines, err := client.GetKlines(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"interval": "1", // 1 minute
"limit": 200,
})
π° Order Management APIs
Click to expand Order Management methods
// π Create a new order
order, err := client.CreateOrder(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"side": "Buy", // Buy or Sell
"orderType": "Limit", // Limit, Market, etc.
"qty": "0.01",
"price": "30000",
"timeInForce": "GTC", // Good Till Cancel
})
// π Get all open orders
openOrders, err := client.GetOpenOrders(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
})
// βοΈ Modify an existing order
amended, err := client.AmendOrder(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"orderId": "order_id_here",
"qty": "0.02", // New quantity
"price": "31000", // New price
})
// β Cancel a single order
cancelled, err := client.CancelOrder(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"orderId": "order_id_here",
})
// π§Ή Cancel all orders for a symbol
cancelledAll, err := client.CancelAllOrders(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
})
// π Get order history
history, err := client.GetHistoryOrders(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"limit": 50,
})
π― Position Management APIs
Click to expand Position Management methods
// π Get current positions
positions, err := client.GetPositions(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
})
// β‘ Set leverage (1x - 100x)
err := client.SetLeverage("linear", "BTCUSDT", 10.0, nil)
// π Switch position mode
err := client.SwitchPositionMode(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"mode": 0, // 0: One-Way Mode, 3: Hedge Mode
})
// π― Set Take Profit & Stop Loss
err := client.SetTradingStop(map[string]interface{}{
"category": "linear",
"symbol": "BTCUSDT",
"positionIdx": 0,
"takeProfit": "35000", // Take profit at $35k
"stopLoss": "28000", // Stop loss at $28k
})
πΌ Account & Wallet APIs
Click to expand Account & Wallet methods
// π° Get wallet balance
balance, err := client.GetWalletBalance(map[string]interface{}{
"accountType": "UNIFIED", // UNIFIED, CONTRACT, SPOT
"coin": "USDT",
})
// π΅ Calculate trading fees
spotFee := client.ComputeFee("spot", 1000.0, "Non-VIP", "taker")
// Returns: 1.0 USDT (0.1% fee)
derivativesFee := client.ComputeFee("derivatives", 10000.0, "VIP1", "maker")
// Returns: 6.75 USDT (0.0675% fee)
π WebSocket Streaming
Public Streams
package main
import (
"fmt"
"log"
bybit "github.com/tigusigalpa/bybit-go"
)
func main() {
// Create WebSocket instance
ws := bybit.NewWebSocket(bybit.WebSocketConfig{
Testnet: false,
Region: "global",
IsPrivate: false,
})
// Subscribe to orderbook
ws.SubscribeOrderbook("BTCUSDT", 50)
// Subscribe to trades
ws.SubscribeTrade("BTCUSDT")
// Subscribe to ticker
ws.SubscribeTicker("BTCUSDT")
// Subscribe to klines
ws.SubscribeKline("BTCUSDT", "1") // 1m candles
// Handle messages
ws.OnMessage(func(data map[string]interface{}) {
if topic, ok := data["topic"].(string); ok {
fmt.Printf("Topic: %s\n", topic)
fmt.Printf("Data: %v\n", data["data"])
}
})
// Start listening (blocking)
if err := ws.Listen(); err != nil {
log.Fatal(err)
}
}
Private Streams
package main
import (
"fmt"
"log"
bybit "github.com/tigusigalpa/bybit-go"
)
func main() {
ws := bybit.NewWebSocket(bybit.WebSocketConfig{
APIKey: "your_api_key",
APISecret: "your_api_secret",
Testnet: false,
Region: "global",
IsPrivate: true,
})
// Subscribe to position updates
ws.SubscribePosition()
// Subscribe to order updates
ws.SubscribeOrder()
// Subscribe to execution updates
ws.SubscribeExecution()
// Subscribe to wallet updates
ws.SubscribeWallet()
ws.OnMessage(func(data map[string]interface{}) {
topic, _ := data["topic"].(string)
switch topic {
case "position":
handlePositionUpdate(data)
case "order":
handleOrderUpdate(data)
case "execution":
handleExecutionUpdate(data)
case "wallet":
handleWalletUpdate(data)
}
})
if err := ws.Listen(); err != nil {
log.Fatal(err)
}
}
π‘ Advanced Usage
Universal Order Placement
// Spot limit order
price := 30000.0
order, err := client.PlaceOrder(bybit.PlaceOrderParams{
Type: "spot",
Symbol: "BTCUSDT",
Execution: "limit",
Price: &price,
Side: stringPtr("Buy"),
Size: 0.01,
})
// Derivatives market order with leverage
leverage := 10.0
tp := 0.02 // 2%
sl := 0.01 // 1%
order, err := client.PlaceOrder(bybit.PlaceOrderParams{
Type: "derivatives",
Symbol: "BTCUSDT",
Execution: "market",
Side: stringPtr("Buy"),
Leverage: &leverage,
Size: 100.0, // margin in USDT
SlTp: &bybit.SlTpParams{
Type: "percent",
TakeProfit: &tp,
StopLoss: &sl,
},
})
// Trigger order with absolute TP/SL
triggerPrice := 29500.0
tpAbs := 31000.0
slAbs := 29000.0
order, err := client.PlaceOrder(bybit.PlaceOrderParams{
Type: "derivatives",
Symbol: "BTCUSDT",
Execution: "trigger",
Price: &triggerPrice,
Side: stringPtr("Buy"),
Leverage: &leverage,
Size: 150.0,
SlTp: &bybit.SlTpParams{
Type: "absolute",
TakeProfit: &tpAbs,
StopLoss: &slAbs,
},
Extra: map[string]interface{}{
"timeInForce": "GTC",
},
})
func stringPtr(s string) *string {
return &s
}
Trading Fee Calculation
// Spot trading fee
feeSpot := client.ComputeFee("spot", 1000.0, "Non-VIP", "taker")
// Result: 1.0 USDT (0.1%)
// Derivatives with leverage
margin := 100.0
leverage := 10.0
volume := margin * leverage // 1000
feeDeriv := client.ComputeFee("derivatives", volume, "VIP1", "maker")
π Regional Endpoints
| Region |
Code |
Endpoint |
| π Global |
global |
https://api.bybit.com |
| π³π± Netherlands |
nl |
https://api.bybit.nl |
| πΉπ· Turkey |
tr |
https://api.bybit-tr.com |
| π°πΏ Kazakhstan |
kz |
https://api.bybit.kz |
| π¬πͺ Georgia |
ge |
https://api.bybitgeorgia.ge |
| π¦πͺ UAE |
ae |
https://api.bybit.ae |
| π§ͺ Testnet |
- |
https://api-testnet.bybit.com |
π Authentication
Signature Generation
Bybit V5 API uses HMAC-SHA256 or RSA-SHA256 for request signing:
For GET requests:
signature_payload = timestamp + api_key + recv_window + queryString
For POST requests:
signature_payload = timestamp + api_key + recv_window + jsonBody
HMAC-SHA256: Returns lowercase hex
RSA-SHA256: Returns base64
X-BAPI-API-KEY: your_api_key
X-BAPI-TIMESTAMP: 1234567890000
X-BAPI-RECV-WINDOW: 5000
X-BAPI-SIGN: generated_signature
X-BAPI-SIGN-TYPE: 2 (for HMAC)
Content-Type: application/json (for POST)
π Official Documentation: https://bybit-exchange.github.io/docs/v5/guide
π Examples
See the examples/ directory for complete working examples:
basic_client.go - Basic client initialization and usage
market_data.go - Market data retrieval
order_management.go - Order placement and management
websocket_public.go - Public WebSocket streams
websocket_private.go - Private WebSocket streams
οΏ½ Examples
π Learn by Example
Comprehensive examples to get you started quickly
Explore the examples/ directory for complete, runnable examples:
Run any example:
cd examples
go run basic_client.go
π€ Contributing
π‘ We Love Contributions!
Want to make Bybit Go SDK even better? We welcome contributions of all kinds!
Quick Contribution Guide:
- π΄ Fork the repository
- πΏ Create your feature branch:
git checkout -b feature/AmazingFeature
- βοΈ Commit your changes:
git commit -m 'Add some AmazingFeature'
- π€ Push to the branch:
git push origin feature/AmazingFeature
- π Open a Pull Request
π License
MIT License
Free to use, modify, and distribute
Copyright (c) 2026 Igor Sazonov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
π Show Your Support
If this project helped you, please consider giving it a β star!

π¬ Connect With Us
Author: Igor Sazonov (tigusigalpa)
Email: sovletig@gmail.com
GitHub: @tigusigalpa
π Useful Links
π Official Bybit API Docs β’ π Report Bug β’ π‘ Request Feature β’ π¬ Discussions
Made with β€οΈ and β for the crypto trading community
Happy Trading! ππ
β οΈ Disclaimer: Trading cryptocurrencies carries risk. This SDK is provided as-is without warranty. Always test on testnet first and never invest more than you can afford to lose.