Java SDK - Financial Data API REST & WebSocket Real-Time Streaming iTick Documentation SDK & Developer Tools 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.
Java SDK Documentation
The Java 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
Maven
Add the following dependency to your pom.xml:
<dependency>
<groupId>io.itick</groupId>
<artifactId>sdk</artifactId>
<version>0.1.1</version>
</dependency>
Gradle
Add the following dependency to your build.gradle:
implementation 'io.itick:sdk:0.1.1'
Build from Source
cd java
mvn clean install
Quick Start
Initialize Client
import io.itick.sdk.Client;
public class Example {
public static void main(String[] args) {
String token = "your_api_token";
Client client = new Client(token);
}
}
REST API Usage
Forex Data Query
// Get forex real-time trade
var tick = client.getForexTick("GB", "EURUSD");
System.out.println(tick);
// Get forex real-time quote
var quote = client.getForexQuote("GB", "EURUSD");
System.out.println(quote);
// Get forex real-time order book
var depth = client.getForexDepth("GB", "EURUSD");
System.out.println(depth);
// Get forex historical K-line
var kline = client.getForexKline("GB", "EURUSD", 2, 10, null);
for (var k : kline) {
System.out.println(k);
}
Stock Data Query
// Get stock real-time trade
var tick = client.getStockTick("US", "AAPL");
System.out.println(tick);
// Get stock real-time quote
var quote = client.getStockQuote("US", "AAPL");
System.out.println(quote);
// Get stock real-time order book
var depth = client.getStockDepth("US", "AAPL");
System.out.println(depth);
// Get stock historical K-line
var kline = client.getStockKline("US", "AAPL", 2, 10, null);
for (var k : kline) {
System.out.println(k);
}
Cryptocurrency Data Query
// Get cryptocurrency real-time trade
var tick = client.getCryptoTick("BA", "BTCUSDT");
System.out.println(tick);
// Get cryptocurrency real-time quote
var quote = client.getCryptoQuote("BA", "BTCUSDT");
System.out.println(quote);
// Get cryptocurrency real-time order book
var depth = client.getCryptoDepth("BA", "BTCUSDT");
System.out.println(depth);
// Get cryptocurrency historical K-line
var kline = client.getCryptoKline("BA", "BTCUSDT", 2, 10, null);
for (var k : kline) {
System.out.println(k);
}
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(message -> {
System.out.println("Received WebSocket message: " + message);
});
// Set error handler
client.setErrorHandler(error -> {
System.err.println("WebSocket error: " + error.getMessage());
});
// Set open handler
client.setOpenHandler(() -> {
System.out.println("WebSocket connected");
});
// Set close handler
client.setCloseHandler(() -> {
System.out.println("WebSocket closed");
});
Connect and Subscribe
// Connect to forex WebSocket
client.connectForexWebSocket();
// Send subscription message
client.sendWebSocketMessage("{\"action\": \"subscribe\", \"codes\": [\"EURUSD\"]}");
// Wait to receive messages
Thread.sleep(5000);
// Check connection status
System.out.println("WebSocket connected: " + client.isWebSocketConnected());
// Close WebSocket
client.closeWebSocket();
Other WebSocket Connections
// Connect to stock WebSocket
client.connectStockWebSocket();
// Connect to cryptocurrency WebSocket
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
boolean connected = client.isWebSocketConnected();
Complete Example
import io.itick.sdk.Client;
public class Main {
public static void main(String[] args) {
try {
// Initialize client
String token = "your_api_token";
Client client = new Client(token);
// Set WebSocket message handler
client.setMessageHandler(message -> {
System.out.println("Received WebSocket message: " + message);
});
// Set WebSocket error handler
client.setErrorHandler(error -> {
System.err.println("WebSocket error: " + error.getMessage());
});
// Test REST API
System.out.println("Testing forex tick...");
var tick = client.getForexTick("GB", "EURUSD");
System.out.println(tick);
// Test WebSocket
System.out.println("\nTesting WebSocket...");
client.connectForexWebSocket();
// Send subscription message
client.sendWebSocketMessage("{\"action\": \"subscribe\", \"codes\": [\"EURUSD\"]}");
// Wait to receive messages
Thread.sleep(5000);
// Check connection status
System.out.println("WebSocket connected: " + client.isWebSocketConnected());
// Close WebSocket
client.closeWebSocket();
} catch (Exception e) {
e.printStackTrace();
}
}
}
System Requirements
- Java 11 or higher
- Maven 3.6 or higher (for building)
Dependencies
- OkHttp 4.10.0 - HTTP client
- Java-WebSocket 1.5.3 - WebSocket client
- Gson 2.10.1 - JSON parser
- Python SDK
Official iTick Python SDK, providing REST API queries and WebSocket real-time data subscription for basic, stock, index, futures, fund, forex, and cryptocurrency data.
- Go SDK
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.