Go SDK - Financial Data API REST & WebSocket Real-Time Streaming iTick Documentation SDK & Developer Tools Official iTick Go SDK providing REST API queries and WebSocket real-time data subscription for basic, stock, index, futures, fund, forex, and cryptocurrency market data.
Go SDK Documentation
The Go version of iTick API SDK provides REST API queries and WebSocket real-time data subscription for basic, stock, index, futures, fund, forex, and cryptocurrency data.
Features
- Supports REST API queries for basic, stock, index, futures, fund, forex, and cryptocurrency data
- Supports WebSocket real-time data subscription
- Automatic reconnection mechanism
- Heartbeat to maintain connection
- Callback-based event handling
Installation
go get -u github.com/itick-org/go-sdk@latest
Quick Start
Initialize Client
package main
import (
"github.com/itick-org/go-sdk/sdk"
)
func main() {
token := "your_api_token"
client := sdk.NewClient(token)
}
REST API Usage
Forex Data Query
// Get forex real-time trade
tick, err := client.GetForexTick("GB", "EURUSD")
if err != nil {
log.Fatalf("GetForexTick error: %v", err)
}
tickBy, _ := json.Marshal(tick)
fmt.Printf("Forex Tick: %+v\n", string(tickBy))
// Get forex batch real-time trade
ticks, err := client.GetForexTicks("GB", []string{"EURUSD", "GBPUSD"})
if err != nil {
log.Fatalf("GetForexTicks error: %v", err)
}
ticksBy, _ := json.Marshal(ticks)
fmt.Printf("Forex Ticks: %+v\n", string(ticksBy))
// Get forex real-time Quote
quote, err := client.GetForexQuote("GB", "GBPUSD")
if err != nil {
log.Fatalf("GetForexQuote error: %v", err)
}
quoteBy, _ := json.Marshal(quote)
fmt.Printf("Forex Quote: %+v\n", string(quoteBy))
// Get forex batch real-time Quote
quotes, err := client.GetForexQuotes("GB", []string{"EURUSD", "GBPUSD"})
if err != nil {
log.Fatalf("GetForexQuotes error: %v", err)
}
quotesBy, _ := json.Marshal(quotes)
fmt.Printf("Forex Quotes: %+v\n", string(quotesBy))
// Get forex real-time order book
depth, err := client.GetForexDepth("GB", "EURUSD")
if err != nil {
log.Fatalf("GetForexDepth error: %v", err)
}
depthBy, _ := json.Marshal(depth)
fmt.Printf("Forex Depth: %+v\n", string(depthBy))
// Get forex batch real-time order book
depths, err := client.GetForexDepths("GB", []string{"EURUSD", "GBPUSD"})
if err != nil {
log.Fatalf("GetForexDepths error: %v", err)
}
depthsBy, _ := json.Marshal(depths)
fmt.Printf("Forex Depths: %+v\n", string(depthsBy))
// Get forex historical K-line
kline, err := client.GetForexKline("GB", "EURUSD", 2, 10, nil)
if err != nil {
log.Fatalf("GetForexKlines error: %v", err)
}
klineBy, _ := json.Marshal(kline)
fmt.Printf("Forex Klines: %+v\n", string(klineBy))
// Get forex batch historical K-line
klines, err := client.GetForexKlines("GB", []string{"EURUSD", "GBPUSD"}, 2, 10, nil)
if err != nil {
log.Fatalf("GetForexKlines error: %v", err)
}
klinesBy, _ := json.Marshal(klines)
fmt.Printf("Forex Klines: %+v\n", string(klinesBy))
Stock Data Query
// Get stock real-time trade
tick, err := client.GetStockTick("US", "AAPL")
if err != nil {
log.Fatal(err)
}
// Get stock real-time quote
quote, err := client.GetStockQuote("US", "AAPL")
if err != nil {
log.Fatal(err)
}
// Get stock real-time order book
depth, err := client.GetStockDepth("US", "AAPL")
if err != nil {
log.Fatal(err)
}
// Get stock historical K-line
kline, err := client.GetStockKline("US", "AAPL", 2, 10, nil)
if err != nil {
log.Fatal(err)
}
Crypto Data Query
// Get crypto real-time trade
tick, err := client.GetCryptoTick("BA", "BTCUSDT")
if err != nil {
log.Fatal(err)
}
// Get crypto real-time quote
quote, err := client.GetCryptoQuote("BA", "BTCUSDT")
if err != nil {
log.Fatal(err)
}
// Get crypto real-time order book
depth, err := client.GetCryptoDepth("BA", "BTCUSDT")
if err != nil {
log.Fatal(err)
}
// Get crypto historical K-line
kline, err := client.GetCryptoKline("BA", "BTCUSDT", 2, 10, nil)
if err != nil {
log.Fatal(err)
}
WebSocket Usage
The SDK provides enhanced WebSocket functionality including automatic reconnection and heartbeat maintenance, eliminating the need for manual connection management.
Set Callback Functions
// Set message handler
client.SetMessageHandler(func(message []byte) {
fmt.Printf("Received WebSocket message: %s\n", message)
})
// Set error handler
client.SetErrorHandler(func(err error) {
log.Printf("WebSocket error: %v\n", err)
})
Connect and Subscribe
// Connect to forex WebSocket
err := client.ConnectForexWebSocket()
if err != nil {
log.Fatal(err)
}
defer client.CloseWebSocket()
// Send subscription message
subscribeMsg := []byte(`{"ac": "subscribe", "params": "EURUSD$GB","types":"quote"}`)
err = client.SendWebSocketMessage(subscribeMsg)
if err != nil {
log.Fatal(err)
}
// Wait to receive messages
time.Sleep(10 * time.Second)
// Check connection status
fmt.Printf("WebSocket connected: %v\n", client.IsWebSocketConnected())
Other WebSocket Connections
// Connect to stock WebSocket
err := client.ConnectStockWebSocket()
// Connect to cryptocurrency WebSocket
err := client.ConnectCryptoWebSocket()
API Interface List
Basics
| Method | Description |
|---|---|
| GetSymbolList | Get symbol list |
| GetSymbolHolidays | Get holiday information |
Stock
| Method | Description |
|---|---|
| GetStockInfo | Get stock information |
| GetStockIPO | Get stock IPO information |
| GetStockSplit | Get stock split information |
| GetStockTick | Get stock real-time trade |
| GetStockQuote | Get stock real-time quote |
| GetStockDepth | Get stock real-time order book |
| GetStockKline | Get stock historical K-line |
| GetStockTicks | Get stock batch real-time trades |
| GetStockQuotes | Get stock batch real-time quotes |
| GetStockDepths | Get stock batch real-time order books |
| GetStockKlines | Get stock batch historical K-lines |
| ConnectStockWebSocket | Connect to stock WebSocket |
Indices
| Method | Description |
|---|---|
| GetIndicesTick | Get index real-time trade |
| GetIndicesQuote | Get index real-time quote |
| GetIndicesDepth | Get index real-time order book |
| GetIndicesKline | Get index historical K-line |
| GetIndicesTicks | Get index batch real-time trades |
| GetIndicesQuotes | Get index batch real-time quotes |
| GetIndicesDepths | Get index batch real-time order books |
| GetIndicesKlines | Get index batch historical K-lines |
| ConnectIndicesWebSocket | Connect to index WebSocket |
Futures
| Method | Description |
|---|---|
| GetFutureTick | Get futures real-time trade |
| GetFutureQuote | Get futures real-time quote |
| GetFutureDepth | Get futures real-time order book |
| GetFutureKline | Get futures historical K-line |
| GetFutureTicks | Get futures batch real-time trades |
| GetFutureQuotes | Get futures batch real-time quotes |
| GetFutureDepths | Get futures batch real-time order books |
| GetFutureKlines | Get futures batch historical K-lines |
| ConnectFutureWebSocket | Connect to futures WebSocket |
Funds
| Method | Description |
|---|---|
| GetFundTick | Get fund real-time trade |
| GetFundQuote | Get fund real-time quote |
| GetFundDepth | Get fund real-time order book |
| GetFundKline | Get fund historical K-line |
| GetFundTicks | Get fund batch real-time trades |
| GetFundQuotes | Get fund batch real-time quotes |
| GetFundDepths | Get fund batch real-time order books |
| GetFundKlines | Get fund batch historical K-lines |
| ConnectFundWebSocket | Connect to fund WebSocket |
Forex
| Method | Description |
|---|---|
| GetForexTick | Get forex real-time trade |
| GetForexQuote | Get forex real-time quote |
| GetForexDepth | Get forex real-time order book |
| GetForexKline | Get forex historical K-line |
| GetForexTicks | Get forex batch real-time trades |
| GetForexQuotes | Get forex batch real-time quotes |
| GetForexDepths | Get forex batch real-time order books |
| GetForexKlines | Get forex batch historical K-lines |
| ConnectForexWebSocket | Connect to forex WebSocket |
Crypto
| Method | Description |
|---|---|
| GetCryptoTick | Get cryptocurrency real-time trade |
| GetCryptoQuote | Get cryptocurrency real-time quote |
| GetCryptoDepth | Get cryptocurrency real-time order book |
| GetCryptoKline | Get cryptocurrency historical K-line |
| GetCryptoTicks | Get cryptocurrency batch real-time trades |
| GetCryptoQuotes | Get cryptocurrency batch real-time quotes |
| GetCryptoDepths | Get cryptocurrency batch real-time order books |
| GetCryptoKlines | Get cryptocurrency batch historical K-lines |
| ConnectCryptoWebSocket | Connect to cryptocurrency WebSocket |
WebSocket Functionality
Automatic Reconnection
The SDK has a built-in automatic reconnection mechanism that automatically attempts to reconnect when network exceptions or disconnections occur:
- Reconnection interval: 5 seconds
- Maximum reconnection attempts: 10 times
- Automatically restore subscriptions after successful reconnection
Heartbeat Maintenance
The SDK automatically maintains WebSocket connection heartbeats:
- Heartbeat interval: 30 seconds
- Automatically sends ping messages to keep the connection active
Connection Status Check
// Check if WebSocket is connected
connected := client.IsWebSocketConnected()
Complete Example
package main
import (
"fmt"
"log"
"time"
"github.com/itick-org/go-sdk/sdk"
)
func main() {
// Initialize client
token := "your_api_token"
client := sdk.NewClient(token)
// Set WebSocket message handler
client.SetMessageHandler(func(message []byte) {
fmt.Printf("Received WebSocket message: %s\n", message)
})
// Set WebSocket error handler
client.SetErrorHandler(func(err error) {
log.Printf("WebSocket error: %v\n", err)
})
// Test REST API
tick, err := client.GetForexTick("GB", "EURUSD")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Forex Tick: %+v\n", tick)
// Test WebSocket
err = client.ConnectForexWebSocket()
if err != nil {
log.Fatal(err)
}
defer client.CloseWebSocket()
// Send subscription message
subscribeMsg := []byte(`{"ac": "subscribe", "params": "EURUSD$GB","types":"quote"}`)
err = client.SendWebSocketMessage(subscribeMsg)
if err != nil {
log.Fatal(err)
}
// Wait to receive messages
time.Sleep(10 * time.Second)
}
- Java SDK
Official iTick Java SDK for REST API and WebSocket real-time data streaming. Access financial market data including stocks, forex, crypto, indices, futures, and funds with automatic reconnection and heartbeat support.
- Node.js SDK
Official iTick Node.js SDK providing REST API queries and WebSocket real-time data subscription for basic, stock, index, futures, fund, forex, and cryptocurrency market data with TypeScript support.