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

MethodDescription
getSymbolListGet symbol list
getSymbolHolidaysGet holiday information

Stock

MethodDescription
getStockInfoGet stock information
getStockIPOGet stock IPO information
getStockSplitGet stock split information
getStockTickGet stock real-time trade
getStockQuoteGet stock real-time quote
getStockDepthGet stock real-time order book
getStockKlineGet stock historical K-line
getStockTicksGet stock batch real-time trades
getStockQuotesGet stock batch real-time quotes
getStockDepthsGet stock batch real-time order books
getStockKlinesGet stock batch historical K-lines
connectStockWebSocketConnect to stock WebSocket

Indices

MethodDescription
getIndicesTickGet index real-time trade
getIndicesQuoteGet index real-time quote
getIndicesDepthGet index real-time order book
getIndicesKlineGet index historical K-line
getIndicesTicksGet index batch real-time trades
getIndicesQuotesGet index batch real-time quotes
getIndicesDepthsGet index batch real-time order books
getIndicesKlinesGet index batch historical K-lines
connectIndicesWebSocketConnect to index WebSocket

Futures

MethodDescription
getFutureTickGet futures real-time trade
getFutureQuoteGet futures real-time quote
getFutureDepthGet futures real-time order book
getFutureKlineGet futures historical K-line
getFutureTicksGet futures batch real-time trades
getFutureQuotesGet futures batch real-time quotes
getFutureDepthsGet futures batch real-time order books
getFutureKlinesGet futures batch historical K-lines
connectFutureWebSocketConnect to futures WebSocket

Funds

MethodDescription
getFundTickGet fund real-time trade
getFundQuoteGet fund real-time quote
getFundDepthGet fund real-time order book
getFundKlineGet fund historical K-line
getFundTicksGet fund batch real-time trades
getFundQuotesGet fund batch real-time quotes
getFundDepthsGet fund batch real-time order books
getFundKlinesGet fund batch historical K-lines
connectFundWebSocketConnect to fund WebSocket

Forex

MethodDescription
getForexTickGet forex real-time trade
getForexQuoteGet forex real-time quote
getForexDepthGet forex real-time order book
getForexKlineGet forex historical K-line
getForexTicksGet forex batch real-time trades
getForexQuotesGet forex batch real-time quotes
getForexDepthsGet forex batch real-time order books
getForexKlinesGet forex batch historical K-lines
connectForexWebSocketConnect to forex WebSocket

Crypto

MethodDescription
getCryptoTickGet cryptocurrency real-time trade
getCryptoQuoteGet cryptocurrency real-time quote
getCryptoDepthGet cryptocurrency real-time order book
getCryptoKlineGet cryptocurrency historical K-line
getCryptoTicksGet cryptocurrency batch real-time trades
getCryptoQuotesGet cryptocurrency batch real-time quotes
getCryptoDepthsGet cryptocurrency batch real-time order books
getCryptoKlinesGet cryptocurrency batch historical K-lines
connectCryptoWebSocketConnect 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
  1. 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.

  2. 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.