The Node.js SDK for iTick API, providing REST API queries and WebSocket real-time data subscription for basics, stocks, indices, futures, funds, forex, and cryptocurrencies. Used to access real-time financial market data from the iTick API.
- Comprehensive Market Coverage: Access global financial markets including stocks, cryptocurrencies, forex, indices, futures, and funds
- Real-time Data: WebSocket-based real-time data streaming with automatic reconnection support
- RESTful API: Clean and intuitive REST API for retrieving historical data and snapshots
- Type Safety: Full TypeScript support with comprehensive type definitions
- Auto Reconnection: Built-in automatic reconnection mechanism (5-second interval, configurable unlimited attempts)
- Heartbeat Keep-alive: Automatic ping/pong mechanism (30-second interval) to maintain stable connections
- Modular Design: Independent modules organized by asset type for clearer structure
- Flexible Subscription: Support for subscribing to quotes, order book depth, trades, and candlestick data
npm install @itick/node-sdkRequirements:
- Node.js >= 18.0.0
import { StockClient } from "@itick/node-sdk";
// Initialize client with API Token
const token = process.env.ITICK_TOKEN;
const client = new StockClient(token);
// Get stock quote
async function getQuote() {
try {
const response = await client.getQuote({ region: "US", code: "AAPL" });
if (response.code === 0 && response.data) {
console.log("Latest Price:", response.data.ld);
console.log("Change %:", response.data.chp);
}
} catch (error) {
console.error("Error:", error.message);
}
}
getQuote();import { CryptoClient } from "@itick/node-sdk";
const client = new CryptoClient(token);
// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data again
const socket = client.createSocket({
maxReconnectTimes: 10, // Maximum reconnection attempts, default is 0 (unlimited)
pingInterval: 30000, // Ping interval, default 30 seconds
reconnectInterval: 5000, // Reconnection interval, default 5 seconds
subscribeData: {
codes: ["BTCUSDT$BA", "ETHUSDT$BA"],
types: ["quote", "tick"],
},
});
// Create custom WebSocket connection
const socket = client.createSocket();
// Send subscription data after successful connection or reconnection
socket.onSocketOpen(() => {
socket.subscribeData({
codes: ["BTCUSDT$BA", "ETHUSDT$BA"],
types: ["quote", "tick"],
});
});
// Handle received messages
socket.onSocketMessage((res) => {
console.log("Received data:", res);
});
// Handle errors
socket.onSocketError((error) => {
console.error("WebSocket error:", error);
});
// Disconnect when done
// socket.disconnectSocket();Financial instrument listings, market holiday information, and trading hours.
import { BaseClient } from "@itick/node-sdk";
const client = new BaseClient(token);
// Get symbol list
await client.getSymbolList({ type: "stock", region: "US" });
await client.getSymbolList({ type: "crypto", region: "BA" });
await client.getSymbolList({ type: "forex", region: "GB" });
// Get market holidays
await client.getSymbolHolidays("US");
await client.getSymbolHolidays("HK");| Method Name | Parameters | Return Type | Description | Details |
|---|---|---|---|---|
getSymbolList |
options: Object- type:enum (Product type, e.g., stock,forex,fund,future,indices) - region:string (Market region code, e.g., US, BA, GB, etc.) |
Promise<APIResponse<SymbolListData[]>> |
Get financial instrument listings (symbol list) for specified market and asset type. | iTick Symbol List |
getSymbolHolidays |
region: string (Market region code, e.g., US, HK, etc.) |
Promise<APIResponse<HolidayData[]>> |
Get holiday information for specified market, including trading hours schedule. | iTick Market Holidays |
Access global stock market data including US stocks, Hong Kong stocks, etc.
import { StockClient } from "@itick/node-sdk";
const client = new StockClient(token);
// Get single stock information
await client.getInfo({ region: "US", code: "AAPL" });
// Get real-time quote
await client.getQuote({ region: "US", code: "AAPL" });
// Get order book depth
await client.getDepth({ region: "US", code: "AAPL" });
// Get latest trade
await client.getTick({ region: "US", code: "AAPL" });
// Get candlestick data
await client.getKline({
region: "US",
code: "AAPL",
interval: "5m",
limit: 100,
});
// Batch queries
await client.getQuotes({ region: "US", codes: ["AAPL", "MSFT", "GOOGL"] });
await client.getDepths({ region: "US", codes: ["AAPL", "MSFT"] });
await client.getTicks({ region: "US", codes: ["AAPL", "MSFT"] });
await client.getKlines({
region: "US",
codes: ["AAPL", "MSFT"],
interval: "1d",
limit: 50,
});
// IPO information
await client.getIPO({ region: "US", code: "RIVN" });
// Stock split information
await client.getSplit({ region: "US", code: "AAPL" });| Method Name | Parameters | Return Type | Description | Details |
|---|---|---|---|---|
getInfo |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Stock code, e.g., AAPL)- exchange?:string (Optional, Exchange code e.g., NYSE, NASDAQ) |
Promise<APIResponse<StockInfo>> |
Get basic stock information | iTick Stock Info |
getIPO |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Stock code, e.g., AAPL) |
Promise<APIResponse<StockIPO>> |
Get stock IPO information | iTick Stock IPO |
getSplit |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Stock code, e.g., AAPL) |
Promise<APIResponse<StockSplit>> |
Get stock ex-rights and dividend information | iTick Stock Split |
getTick |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Stock code, e.g., AAPL) |
Promise<APIResponse<TickData>> |
Get latest trade data for a single stock | iTick Stock Real-time Tick |
getQuote |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Stock code, e.g., AAPL) |
Promise<APIResponse<QuoteData>> |
Get latest quote for a single stock | iTick Stock Real-time Quote |
getDepth |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Stock code, e.g., AAPL) |
Promise<APIResponse<DepthData>> |
Get latest order book depth for a single stock | iTick Stock Real-time Depth |
getKlines |
options: GetKlineOptions- region: string (Market code)- code: string (Stock code)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineData[]>> |
Get candlestick data for a single stock | iTick Stock K-line |
getTicks |
params: Object- region: string (Market code)- codes: string[] | string (Stock code list) |
Promise<APIResponse<TickDataMap>> |
Get latest trade data for multiple stocks | iTick Stock Batch Ticks |
getQuotes |
params: Object- region: string (Market code)- codes: string[] | string (Stock code list) |
Promise<APIResponse<QuoteDataMap>> |
Get latest quotes for multiple stocks | iTick Stock Batch Quotes |
getDepths |
params: Object- region: string (Market code)- codes: string[] | string (Stock code list) |
Promise<APIResponse<DepthDataMap>> |
Get latest order book depth for multiple stocks | iTick Stock Batch Depths |
getKline |
options: GetKlinesOptions- region: string (Market code)- codes: string[] | string (Stock code list)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineDataMap>> |
Get candlestick data for multiple stocks | iTick Stock Batch K-lines |
createSocket |
options?: CreateSocketOptions (Optional, WebSocket connection options) |
SocketClient |
Create WebSocket connection for real-time data subscription | iTick WebSocket Stocks |
Access cryptocurrency market data from multiple exchanges.
import { CryptoClient } from "@itick/node-sdk";
const client = new CryptoClient(token);
// Get real-time data
await client.getQuote({ region: "BA", code: "BTCUSDT" });
await client.getDepth({ region: "BA", code: "ETHUSDT" });
await client.getTick({ region: "BA", code: "BTCUSDT" });
// Get candlestick data
await client.getKline({
region: "BA",
code: "BTCUSDT",
interval: "1h",
limit: 100,
});
// Batch queries
await client.getQuotes({ region: "BA", codes: ["BTCUSDT", "ETHUSDT"] });| Method Name | Parameters | Return Type | Description | Details |
|---|---|---|---|---|
getTick |
params: Object- region: string (Market code, e.g., BA, BT, PB, etc.)- code: string (Symbol code, e.g., BTCUSDT) |
Promise<APIResponse<TickData>> |
Get latest trade data for a single cryptocurrency | iTick Crypto Real-time Tick |
getQuote |
params: Object- region: string (Market code, e.g., BA, BT, PB, etc.)- code: string (Symbol code, e.g., BTCUSDT) |
Promise<APIResponse<QuoteData>> |
Get latest quote for a single cryptocurrency | iTick Crypto Real-time Quote |
getDepth |
params: Object- region: string (Market code, e.g., BA, BT, PB, etc.)- code: string (Symbol code, e.g., BTCUSDT) |
Promise<APIResponse<DepthData>> |
Get latest order book depth for a single cryptocurrency | iTick Crypto Real-time Depth |
getKlines |
options: GetKlineOptions- region: string (Market code)- code: string (Symbol code)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineData[]>> |
Get candlestick data for a single cryptocurrency | iTick Crypto K-line |
getTicks |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<TickDataMap>> |
Get latest trade data for multiple cryptocurrencies | iTick Crypto Batch Ticks |
getQuotes |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<QuoteDataMap>> |
Get latest quotes for multiple cryptocurrencies | iTick Crypto Batch Quotes |
getDepths |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<DepthDataMap>> |
Get latest order book depth for multiple cryptocurrencies | iTick Crypto Batch Depths |
getKline |
options: GetKlinesOptions- region: string (Market code)- codes: string[] | string (Symbol code list)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineDataMap>> |
Get candlestick data for multiple cryptocurrencies | iTick Crypto Batch K-lines |
createSocket |
options?: CreateSocketOptions (Optional, WebSocket connection options) |
SocketClient |
Create WebSocket connection for real-time data subscription | iTick WebSocket Crypto |
Access foreign exchange market data.
import { ForexClient } from "@itick/node-sdk";
const client = new ForexClient(token);
await client.getQuote({ region: "GB", code: "EURUSD" });
await client.getDepth({ region: "GB", code: "GBPUSD" });
await client.getTick({ region: "GB", code: "USDJPY" });
await client.getKline({ region: "GB", code: "EURUSD", interval: "1d", limit: 50 });| Method Name | Parameters | Return Type | Description | Details |
|---|---|---|---|---|
getTick |
params: Object- region: string (Market code, e.g., GB, etc.)- code: string (Symbol code, e.g., EURUSD) |
Promise<APIResponse<TickData>> |
Get latest trade data for a single currency pair | iTick Forex Real-time Tick |
getQuote |
params: Object- region: string (Market code, e.g., GB, etc.)- code: string (Symbol code, e.g., EURUSD) |
Promise<APIResponse<QuoteData>> |
Get latest quote for a single currency pair | iTick Forex Real-time Quote |
getDepth |
params: Object- region: string (Market code, e.g., GB, etc.)- code: string (Symbol code, e.g., EURUSD) |
Promise<APIResponse<DepthData>> |
Get latest order book depth for a single currency pair | iTick Forex Real-time Depth |
getKlines |
options: GetKlineOptions- region: string (Market code)- code: string (Symbol code)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineData[]>> |
Get candlestick data for a single currency pair | iTick Forex K-line |
getTicks |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<TickDataMap>> |
Get latest trade data for multiple currency pairs | iTick Forex Batch Ticks |
getQuotes |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<QuoteDataMap>> |
Get latest quotes for multiple currency pairs | iTick Forex Batch Quotes |
getDepths |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<DepthDataMap>> |
Get latest order book depth for multiple currency pairs | iTick Forex Batch Depths |
getKline |
options: GetKlinesOptions- region: string (Market code)- codes: string[] | string (Symbol code list)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineDataMap>> |
Get candlestick data for multiple currency pairs | iTick Forex Batch K-lines |
createSocket |
options?: CreateSocketOptions (Optional, WebSocket connection options) |
SocketClient |
Create WebSocket connection for real-time data subscription | iTick WebSocket Forex |
Access global stock index data.
import { IndicesClient } from "@itick/node-sdk";
const client = new IndicesClient(token);
await client.getQuote({ region: "US", code: "SPX" });
await client.getDepth({ region: "US", code: "NDX" });
await client.getKline({ region: "US", code: "DJI", interval: "1w", limit: 20 });| Method Name | Parameters | Return Type | Description | Details |
|---|---|---|---|---|
getTick |
params: Object- region: string (Market code, e.g., US, GB, etc.)- code: string (Symbol code, e.g., DJI, SPX) |
Promise<APIResponse<TickData>> |
Get latest trade data for a single index | iTick Indices Real-time Tick |
getQuote |
params: Object- region: string (Market code, e.g., US, GB, etc.)- code: string (Symbol code, e.g., DJI, SPX) |
Promise<APIResponse<QuoteData>> |
Get latest quote for a single index | iTick Indices Real-time Quote |
getDepth |
params: Object- region: string (Market code, e.g., US, GB, etc.)- code: string (Symbol code, e.g., DJI, SPX) |
Promise<APIResponse<DepthData>> |
Get latest order book depth for a single index | iTick Indices Real-time Depth |
getKlines |
options: GetKlineOptions- region: string (Market code)- code: string (Symbol code)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineData[]>> |
Get candlestick data for a single index | iTick Indices K-line |
getTicks |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<TickDataMap>> |
Get latest trade data for multiple indices | iTick Indices Batch Ticks |
getQuotes |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<QuoteDataMap>> |
Get latest quotes for multiple indices | iTick Indices Batch Quotes |
getDepths |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<DepthDataMap>> |
Get latest order book depth for multiple indices | iTick Indices Batch Depths |
getKline |
options: GetKlinesOptions- region: string (Market code)- codes: string[] | string (Symbol code list)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineDataMap>> |
Get candlestick data for multiple indices | iTick Indices Batch K-lines |
createSocket |
options?: CreateSocketOptions (Optional, WebSocket connection options) |
SocketClient |
Create WebSocket connection for real-time data subscription | iTick WebSocket Indices |
Access futures market data.
import { FutureClient } from "@itick/node-sdk";
const client = new FutureClient(token);
await client.getQuote({ region: "US", code: "ES" });
await client.getDepth({ region: "US", code: "NQ" });
await client.getKline({ region: "US", code: "CL", interval: "5m", limit: 100 });| Method Name | Parameters | Return Type | Description | Details |
|---|---|---|---|---|
getTick |
params: Object- region: string (Market code, e.g., US, CN, HK, etc.)- code: string (Symbol code, e.g., CL, GC) |
Promise<APIResponse<TickData>> |
Get latest trade data for a single futures contract | iTick Futures Real-time Tick |
getQuote |
params: Object- region: string (Market code, e.g., US, CN, HK, etc.)- code: string (Symbol code, e.g., CL, GC) |
Promise<APIResponse<QuoteData>> |
Get latest quote for a single futures contract | iTick Futures Real-time Quote |
getDepth |
params: Object- region: string (Market code, e.g., US, CN, HK, etc.)- code: string (Symbol code, e.g., CL, GC) |
Promise<APIResponse<DepthData>> |
Get latest order book depth for a single futures contract | iTick Futures Real-time Depth |
getKlines |
options: GetKlineOptions- region: string (Market code)- code: string (Symbol code)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineData[]>> |
Get candlestick data for a single futures contract | iTick Futures K-line |
getTicks |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<TickDataMap>> |
Get latest trade data for multiple futures contracts | iTick Futures Batch Ticks |
getQuotes |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<QuoteDataMap>> |
Get latest quotes for multiple futures contracts | iTick Futures Batch Quotes |
getDepths |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<DepthDataMap>> |
Get latest order book depth for multiple futures contracts | iTick Futures Batch Depths |
getKline |
options: GetKlinesOptions- region: string (Market code)- codes: string[] | string (Symbol code list)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineDataMap>> |
Get candlestick data for multiple futures contracts | iTick Futures Batch K-lines |
createSocket |
options?: CreateSocketOptions (Optional, WebSocket connection options) |
SocketClient |
Create WebSocket connection for real-time data subscription | iTick WebSocket Futures |
Access mutual fund and ETF data.
import { FundClient } from "@itick/node-sdk";
const client = new FundClient(token);
await client.getQuote({ region: "US", code: "VOO" });
await client.getDepth({ region: "US", code: "QQQ" });
await client.getKline({ region: "US", code: "SPY", interval: "1d", limit: 100 });| Method Name | Parameters | Return Type | Description | Details |
|---|---|---|---|---|
getTick |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Symbol code, e.g., SPY, QQQ) |
Promise<APIResponse<TickData>> |
Get latest trade data for a single fund | iTick Fund Real-time Tick |
getQuote |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Symbol code, e.g., SPY, QQQ) |
Promise<APIResponse<QuoteData>> |
Get latest quote for a single fund | iTick Fund Real-time Quote |
getDepth |
params: Object- region: string (Market code, e.g., US, HK, etc.)- code: string (Symbol code, e.g., SPY, QQQ) |
Promise<APIResponse<DepthData>> |
Get latest order book depth for a single fund | iTick Fund Real-time Depth |
getKlines |
options: GetKlineOptions- region: string (Market code)- code: string (Symbol code)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineData[]>> |
Get candlestick data for a single fund | iTick Fund K-line |
getTicks |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<TickDataMap>> |
Get latest trade data for multiple funds | iTick Fund Batch Ticks |
getQuotes |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<QuoteDataMap>> |
Get latest quotes for multiple funds | iTick Fund Batch Quotes |
getDepths |
params: Object- region: string (Market code)- codes: string[] | string (Symbol code list) |
Promise<APIResponse<DepthDataMap>> |
Get latest order book depth for multiple funds | iTick Fund Batch Depths |
getKline |
options: GetKlinesOptions- region: string (Market code)- codes: string[] | string (Symbol code list)- interval: KlineType (Candlestick period type)- limit: number (Number of data points returned, max 500)- et?: string | number (Optional, end timestamp) |
Promise<APIResponse<KlineDataMap>> |
Get candlestick data for multiple funds | iTick Fund Batch K-lines |
createSocket |
options?: CreateSocketOptions (Optional, WebSocket connection options) |
SocketClient |
Create WebSocket connection for real-time data subscription | iTick WebSocket Funds |
quote: Real-time quotedepth: Order book depthtick: Latest tradekline@1morkline@1: 1-minute candlestickkline@5morkline@2: 5-minute candlestickkline@15morkline@3: 15-minute candlestickkline@30morkline@4: 30-minute candlestickkline@1horkline@5: 1-hour candlestickkline@2horkline@6: 2-hour candlestick (crypto only)kline@4horkline@7: 4-hour candlestick (crypto only)kline@1dorkline@8: Daily candlestickkline@1workline@9: Weekly candlestickkline@1Morkline@10: Monthly candlestick
const socket = client.createSocket({
maxReconnectTimes: 10, // Maximum reconnection attempts (0 = unlimited)
reconnectInterval: 5000, // Reconnection interval (milliseconds)
pingInterval: 30000, // Ping interval (milliseconds)
subscribeData: {
codes: ["AAPL$US", "MSFT$US"],
types: ["quote", "tick", "kline@1m"],
},
});// Connection opened
socket.onSocketOpen(() => {
console.log("Connected!");
});
// Receive messages
socket.onSocketMessage((data) => {
console.log("Received data:", data);
});
// Error occurred
socket.onSocketError((error) => {
console.error("Error:", error);
});
// Connection closed
socket.onSocketClose(() => {
console.log("Disconnected");
});
// Check connection status
const isConnected = socket.checkSocketConnected();
// Disconnect
socket.disconnectSocket();// Subscribe after connection
socket.subscribeSocket({
ac: "subscribe",
types: ["quote", "depth"],
codes: ["TSLA$US", "NVDA$US"],
});
// Unsubscribe
socket.subscribeSocket({
ac: "unsubscribe",
types: ["tick"],
codes: ["AAPL$US"],
});try {
const response = await client.getQuote({ region: "US", code: "AAPL" });
if (response.code !== 0) {
console.error("API Error:", response.msg);
return;
}
// Process data
console.log(response.data);
} catch (error) {
if (error instanceof Error) {
console.error("Network Error:", error.message);
}
}Full TypeScript support with comprehensive type definitions:
import type {
APIResponse,
QuoteData,
SocketKlineData,
SocketTickData,
SocketDepthData,
SocketQuoteData,
} from "@itick/node-sdk";
// Type-safe response
const response: APIResponse<QuoteData> = await client.getQuote({
region: "US",
code: "AAPL",
});
// Type-safe WebSocket messages
socket.onSocketMessage((response) => {
const { code, data, msg, resAc } = response;
if (data?.type === "quote") {
const quoteData: SocketQuoteData = data;
}
if (data?.type === "kline@1") {
const klineData: SocketKlineData = data;
}
if (data?.type === "tick") {
const tickData: SocketTickData = data;
}
if (data?.type === "depth") {
const depthData: SocketDepthData = data;
}
});- Official API Documentation - Complete API reference
- REST API Guide - Detailed REST endpoints
- WebSocket Guide - Real-time data streaming
- GitHub Repository - Source code and issue tracking
MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to submit a Pull Request.
- Website: https://itick.org
- Email: support@itick.org
- Issues: GitHub Issues
Made with ❤️ by the iTick Team