Skip to content

Go SDK for Bitkub cryptocurrency exchange API - Market data, trading, wallet management with type-safe implementation

License

Notifications You must be signed in to change notification settings

dvgamerr-app/go-bitkub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bitkub Go SDK

Testing Go Version License Discord

Go SDK for Bitkub Cryptocurrency Exchange API - Complete implementation with full V3 & V4 API support + Command Line Interface

Quick Start:

# Install via go install
go install github.com/dvgamerr-app/go-bitkub/cmd/bitkub@latest

# Get market ticker
bitkub market ticker

# Get BTC price
bitkub market ticker btc_thb

# Get historical data
bitkub market history btc_thb --resolution 1

# Output in different formats
bitkub market ticker --format json   # JSON output
bitkub market ticker --format jsonl  # JSONL output (one JSON per line)
bitkub market ticker --format text   # Text output (default)

# Get your balance (requires API keys)
bitkub -k YOUR_KEY -s YOUR_SECRET market balances

⚠️ Important Updates

This SDK implements the latest Bitkub API V3 specification (November 2025) with:

  • βœ… All deprecated endpoints removed
  • βœ… Using V3 endpoints exclusively
  • βœ… Keyset-based pagination (page-based removed)
  • βœ… Simplified function names (removed V3 suffix)
  • πŸ†• CLI Tool with Cobra & Zerolog

πŸš€ Features

πŸ–₯️ Command Line Interface (NEW!)

A powerful CLI tool for interacting with Bitkub API from the terminal:

  • βœ… All API endpoints accessible via commands
  • βœ… Beautiful logging output with zerolog
  • βœ… Multiple output formats (JSON, JSONL, Text)
  • βœ… Support for .env configuration
  • βœ… Market commands including historical data (31+ total)
  • βœ… Crypto commands (7 total)
  • βœ… Fiat commands (4 total)
  • βœ… User commands (3 total)

Documentation:

WebSocket Streaming (Real-time) πŸ”΄

  • βœ… Market trade stream
  • βœ… Market ticker stream
  • βœ… Live order book stream
  • βœ… Multiple streams subscription
  • βœ… Auto-reconnect with configurable retry
  • βœ… Graceful shutdown & error handling

CLI Streaming Examples

# Trade stream (5 messages default)
bitkub stream trade thb_btc

# Ticker stream continuous
bitkub stream ticker thb_btc -t

# JSONL output
bitkub --format jsonl stream trade thb_btc -n 2

# JSON array output
bitkub --format json stream ticker thb_btc -n 5

Market API (V3)

  • βœ… Non-secure endpoints (Market data, server status)
  • βœ… Secure endpoints (Trading, user info, fiat operations)
  • βœ… Historical data for TradingView charts
  • βœ… WebSocket token support
  • βœ… Full order management (place, cancel, history)
  • βœ… Wallet & balance operations
  • βœ… Real-time ticker and trade data

Crypto API (V4) ✨

  • πŸ“‹ List crypto addresses with pagination
  • βž• Generate new crypto addresses
  • πŸ’° View deposit history
  • πŸ’Έ View withdrawal history
  • πŸš€ Create withdrawals to trusted addresses
  • πŸͺ™ Get available coins and networks
  • 🎁 View compensations history

Core Features

  • βœ… Type-safe API responses
  • βœ… Proper error handling
  • βœ… Connection pooling & optimization
  • βœ… HMAC SHA256 signature authentication
  • βœ… Rate limit awareness

πŸ“¦ Installation

go get github.com/dvgamerr-app/go-bitkub

πŸ”§ Quick Start

Initialize

package main

import (
    "log"
    "github.com/dvgamerr-app/go-bitkub/bitkub"
    "github.com/dvgamerr-app/go-bitkub/market"
)

func main() {
    // Initialize with API credentials
    bitkub.Initlizer("YOUR_API_KEY", "YOUR_SECRET_KEY")
    // Or use environment variables BTK_APIKEY and BTK_SECRET
    bitkub.Initlizer()
    
    // Get wallet balance
    wallet, err := market.GetWallet()
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Wallet: %+v", wallet)

    // Get detailed balances
    balances, err := market.GetBalances()
    if err != nil {
        log.Fatal(err)
    }
    log.Printf("Balances: %+v", balances)
}

πŸ“š API Coverage

Non-Secure Endpoints (V3)

import (
    "github.com/dvgamerr-app/go-bitkub/bitkub"
    "github.com/dvgamerr-app/go-bitkub/market"
)

// Get system status
status, err := bitkub.GetStatus()

// Get server time
timestamp, err := bitkub.GetServerTime()

// Get all symbols
symbols, err := market.GetSymbols()

// Get ticker data
tickers, err := market.GetTicker("btc_thb")

// Get market depth
depth, err := market.GetDepth("btc_thb", 10)

// Get recent trades
trades, err := market.GetTrades("btc_thb", 10)

// Get historical data for TradingView
history, err := market.GetHistory(market.HistoryRequest{
    Symbol:     "btc_thb",
    Resolution: "60",  // 1, 5, 15, 60, 240, 1D
    From:       1234567890,
    To:         1234567890,
})

// Get buy orders (bids)
bids, err := market.GetBids("btc_thb", 10)

// Get sell orders (asks)
asks, err := market.GetAsks("btc_thb", 10)

Trading Endpoints (V3 - Secure)

import "github.com/dvgamerr-app/go-bitkub/market"

// Get wallet balances
wallet, err := market.GetWallet()

// Get detailed balances
balances, err := market.GetBalances()

// Place buy order
bidReq := market.PlaceBidRequest{
    Symbol:   "btc_thb",
    Amount:   1000,
    Rate:     2500000,
    Type:     "limit",
    ClientID: "order-1",
}
bidResult, err := market.PlaceBid(bidReq)

// Place sell order
askReq := market.PlaceAskRequest{
    Symbol: "btc_thb",
    Amount: 0.001,
    Rate:   2600000,
    Type:   "limit",
}
askResult, err := market.PlaceAsk(askReq)

// Cancel order
cancelReq := market.CancelOrderRequest{
    Symbol: "btc_thb",
    ID:     "12345",
    Side:   "buy",
}
err = market.CancelOrder(cancelReq)

// Get open orders
orders, err := market.GetOpenOrders("btc_thb")

// Get order history (with keyset pagination)
historyParams := market.OrderHistoryParams{
    Symbol: "BTC_THB",
    Limit:  "10",
}
orderHistory, err := market.GetOrderHistory(historyParams)

// Get order info
orderInfo, err := market.GetOrderInfo("btc_thb", "12345", "buy")

// Get WebSocket token
token, err := market.GetWSToken()

User Endpoints (V3 - Secure)

import "github.com/dvgamerr-app/go-bitkub/user"

// Get trading credits
credits, err := user.GetTradingCredits()

// Get user limits
limits, err := user.GetUserLimits()

// Get coin convert history
convertParams := user.CoinHistoryParams{
    Page:   1,
    Limit:  100,
    Status: "success",
}
convertHistory, err := user.GetCoinConvertHistory(convertParams)

Fiat Endpoints (V3 - Secure)

import "github.com/dvgamerr-app/go-bitkub/fiat"

// Get bank accounts
accountsParams := fiat.AccountsParams{
    Page:  1,
    Limit: 10,
}
accounts, err := fiat.GetAccounts(accountsParams)

// Withdraw fiat
withdrawReq := fiat.WithdrawRequest{
    ID:     "bank-account-id",
    Amount: 1000.0,
}
withdrawResult, err := fiat.Withdraw(withdrawReq)

// Get deposit history
depositParams := fiat.DepositHistoryParams{
    Page:  1,
    Limit: 10,
}
deposits, err := fiat.GetDepositHistory(depositParams)

// Get withdrawal history
withdrawParams := fiat.WithdrawHistoryParams{
    Page:  1,
    Limit: 10,
}
withdrawals, err := fiat.GetWithdrawHistory(withdrawParams)

Crypto API (V4) Examples

import "github.com/dvgamerr-app/go-bitkub/crypto"

// List crypto addresses with pagination
addresses, err := crypto.GetAddresses(crypto.Addresses{
    Page:    1,
    Limit:   10,
    Symbol:  "ATOM",
    Network: "ATOM",
})

// Create new crypto address
newAddresses, err := crypto.CreateAddress(crypto.CreateAddressRequest{
    Symbol:  "BTC",
    Network: "BTC",
})

// Get deposit history with filters
deposits, err := crypto.GetDeposits(crypto.Deposits{
    Page:   1,
    Limit:  10,
    Symbol: "BTC",
    Status: "complete",
})

// Get withdrawal history
withdrawals, err := crypto.GetWithdraws(crypto.Withdraws{
    Page:   1,
    Limit:  10,
    Symbol: "BTC",
})

// Get available coins
coins, err := crypto.GetCoins(crypto.Coins{
    Symbol: "BTC",
})

// Withdraw crypto
withdrawReq := crypto.CreateWithdrawRequest{
    Symbol:  "BTC",
    Network: "BTC",
    Address: "bc1q...",
    Amount:  0.001,
    Memo:    "",
}
txn, err := crypto.CreateWithdraw(withdrawReq)

// Get compensations history
compensations, err := crypto.GetCompensations(crypto.Compensations{
    Page:  1,
    Limit: 10,
})

πŸ“– Documentation

πŸ”’ Security Best Practices

  1. Never commit API keys to version control
  2. Use environment variables for credentials:
    export BTK_APIKEY="your_api_key"
    export BTK_SECRET="your_secret_key"
  3. Use IP whitelist in Bitkub API settings
  4. Implement rate limiting in your application
  5. Monitor API usage regularly

⚑ Rate Limits

Endpoint Type Rate Limit
Market Data V3 (ticker, trades, etc.) 100 req/sec
Trading Operations 150-200 req/sec
Fiat/User Operations 20 req/sec
Crypto V4 Operations 250 req/10sec

See official documentation for complete information.

πŸ§ͺ Testing

Run Tests (Requires API credentials)

# Set your credentials
export BTK_APIKEY="your_api_key"
export BTK_SECRET="your_secret_key"

# Run tests
go test ./... -v

πŸ“ Project Structure

go-bitkub/
β”œβ”€β”€ bitkub/          # Core API client and authentication
β”‚   β”œβ”€β”€ bitkub.go    # Initialization and configuration
β”‚   β”œβ”€β”€ fetch.go     # HTTP client with v3 & v4 support
β”‚   β”œβ”€β”€ error.go     # Error code mappings
β”‚   β”œβ”€β”€ status.go    # System status endpoints
β”‚   └── types.go     # Common type definitions
β”œβ”€β”€ market/          # Market API (V3) endpoints
β”‚   β”œβ”€β”€ symbols.go
β”‚   β”œβ”€β”€ ticker.go
β”‚   β”œβ”€β”€ depth.go
β”‚   β”œβ”€β”€ trades.go
β”‚   β”œβ”€β”€ bids.go
β”‚   β”œβ”€β”€ asks.go
β”‚   β”œβ”€β”€ place-bid.go
β”‚   β”œβ”€β”€ place-ask.go
β”‚   β”œβ”€β”€ cancel-order.go
β”‚   β”œβ”€β”€ order-history.go
β”‚   β”œβ”€β”€ order-info.go
β”‚   β”œβ”€β”€ balances.go
β”‚   β”œβ”€β”€ wallet.go
β”‚   └── wstoken.go
β”œβ”€β”€ user/            # User API (V3) endpoints
β”‚   β”œβ”€β”€ trading-credits.go
β”‚   β”œβ”€β”€ limits.go
β”‚   └── coin-convert-history.go
β”œβ”€β”€ fiat/            # Fiat API (V3) endpoints
β”‚   β”œβ”€β”€ accounts.go
β”‚   β”œβ”€β”€ withdraw.go
β”‚   β”œβ”€β”€ deposit-history.go
β”‚   └── withdraw-history.go
β”œβ”€β”€ crypto/          # Crypto API (V4) endpoints
β”‚   β”œβ”€β”€ addresses.go
β”‚   β”œβ”€β”€ deposits.go
β”‚   β”œβ”€β”€ withdraws.go
β”‚   β”œβ”€β”€ coins.go
β”‚   β”œβ”€β”€ compensations.go
β”‚   └── types.go
β”œβ”€β”€ stream/          # WebSocket streaming (Real-time)
β”‚   β”œβ”€β”€ stream.go          # Main stream client
β”‚   β”œβ”€β”€ types.go           # Message types
β”‚   β”œβ”€β”€ stream_test.go     # Tests
β”‚   β”œβ”€β”€ README.md          # Stream documentation
β”‚   └── examples/          # Usage examples
β”‚       β”œβ”€β”€ market/        # Market stream example
β”‚       β”œβ”€β”€ orderbook/     # Order book example
β”‚       └── timeout/       # Timeout example
β”œβ”€β”€ utils/           # Utility functions
β”‚   β”œβ”€β”€ error.go
β”‚   └── helper.go
β”œβ”€β”€ balances.go      # Balance aggregation helper
β”œβ”€β”€ wallet.go        # Wallet helper functions
└── docs/            # Documentation

πŸ“‘ WebSocket Streaming

Real-time market data streaming with auto-reconnect support.

Basic Usage

import "github.com/dvgamerr-app/go-bitkub/stream"

// Create stream with default config
s := stream.New(nil)

// Connect to market streams
if err := s.ConnectMarket("market.trade.thb_btc", "market.ticker.thb_btc"); err != nil {
    panic(err)
}
defer s.Close()

// Read messages in loop
for msg := range s.Messages() {
    if msg.Error != nil {
        fmt.Printf("Error: %v\n", msg.Error)
        continue
    }
    
    fmt.Printf("[%s] %+v\n", msg.Type, msg.Data)
}

Advanced Configuration

config := &stream.StreamConfig{
    ReconnectInterval: 5 * time.Second,  // Wait before reconnect
    MaxReconnect:      10,                // Max reconnect attempts
    PingInterval:      30 * time.Second,  // Ping interval
    ReadTimeout:       60 * time.Second,  // Read timeout
}

s := stream.New(config)

Available Streams

Market Streams:

  • market.trade.<symbol> - Real-time trades
  • market.ticker.<symbol> - Real-time ticker

Order Book:

// Connect to order book (symbol ID: 1 = THB_BTC)
s.ConnectOrderBook(1)

See stream/README.md for complete documentation and examples.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License

πŸ”— Links

⚠️ Disclaimer

This is an unofficial SDK. Use at your own risk. Always test thoroughly before using in production.


Note: This SDK implements the Bitkub API specification as of November 2025. API specifications are subject to change by Bitkub.

About

Go SDK for Bitkub cryptocurrency exchange API - Market data, trading, wallet management with type-safe implementation

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages