Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Repository files navigation

iTick logo

iTick Node.js SDK

npm versionnode versioninstall sizenpm bundle sizenpm peer dependencylicense badge

English | 简体中文 | 繁體中文

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.

✨ Features

  • 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

🚀 Installation

npm install @itick/node-sdk

Requirements:

  • Node.js >= 18.0.0

🎯 Quick Start

Basic Usage

import{StockClient}from"@itick/node-sdk";// Initialize client with API Tokenconsttoken=process.env.ITICK_TOKEN;constclient=newStockClient(token);// Get stock quoteasyncfunctiongetQuote(){try{constresponse=awaitclient.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();

Real-time Data via WebSocket

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Create WebSocket connection with subscription data - SDK handles connection and automatically subscribes after reconnection, no need to send subscription data againconstsocket=client.createSocket({maxReconnectTimes: 10,// Maximum reconnection attempts, default is 0 (unlimited)pingInterval: 30000,// Ping interval, default 30 secondsreconnectInterval: 5000,// Reconnection interval, default 5 secondssubscribeData: {codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],},});// Create custom WebSocket connectionconstsocket=client.createSocket();// Send subscription data after successful connection or reconnectionsocket.onSocketOpen(()=>{socket.subscribeData({codes: ["BTCUSDT$BA","ETHUSDT$BA"],types: ["quote","tick"],});});// Handle received messagessocket.onSocketMessage((res)=>{console.log("Received data:",res);});// Handle errorssocket.onSocketError((error)=>{console.error("WebSocket error:",error);});// Disconnect when done// socket.disconnectSocket();

📚 API Reference

Base Module

Financial instrument listings, market holiday information, and trading hours.

import{BaseClient}from"@itick/node-sdk";constclient=newBaseClient(token);// Get symbol listawaitclient.getSymbolList({type: "stock",region: "US"});awaitclient.getSymbolList({type: "crypto",region: "BA"});awaitclient.getSymbolList({type: "forex",region: "GB"});// Get market holidaysawaitclient.getSymbolHolidays("US");awaitclient.getSymbolHolidays("HK");

BaseClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getSymbolListoptions: 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
getSymbolHolidaysregion: 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

Stock Module

Access global stock market data including US stocks, Hong Kong stocks, etc.

import{StockClient}from"@itick/node-sdk";constclient=newStockClient(token);// Get single stock informationawaitclient.getInfo({region: "US",code: "AAPL"});// Get real-time quoteawaitclient.getQuote({region: "US",code: "AAPL"});// Get order book depthawaitclient.getDepth({region: "US",code: "AAPL"});// Get latest tradeawaitclient.getTick({region: "US",code: "AAPL"});// Get candlestick dataawaitclient.getKline({region: "US",code: "AAPL",interval: "5m",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "US",codes: ["AAPL","MSFT","GOOGL"]});awaitclient.getDepths({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getTicks({region: "US",codes: ["AAPL","MSFT"]});awaitclient.getKlines({region: "US",codes: ["AAPL","MSFT"],interval: "1d",limit: 50,});// IPO informationawaitclient.getIPO({region: "US",code: "RIVN"});// Stock split informationawaitclient.getSplit({region: "US",code: "AAPL"});

StockClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getInfoparams: 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 informationiTick Stock Info
getIPOparams: Object
- region: string (Market code, e.g., US, HK, etc.)
- code: string (Stock code, e.g., AAPL)
Promise<APIResponse<StockIPO>>Get stock IPO informationiTick Stock IPO
getSplitparams: 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 informationiTick Stock Split
getTickparams: 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 stockiTick Stock Real-time Tick
getQuoteparams: 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 stockiTick Stock Real-time Quote
getDepthparams: 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 stockiTick Stock Real-time Depth
getKlinesoptions: 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 stockiTick Stock K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple stocksiTick Stock Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple stocksiTick Stock Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Stock code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple stocksiTick Stock Batch Depths
getKlineoptions: 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 stocksiTick Stock Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Stocks

Cryptocurrency Module

Access cryptocurrency market data from multiple exchanges.

import{CryptoClient}from"@itick/node-sdk";constclient=newCryptoClient(token);// Get real-time dataawaitclient.getQuote({region: "BA",code: "BTCUSDT"});awaitclient.getDepth({region: "BA",code: "ETHUSDT"});awaitclient.getTick({region: "BA",code: "BTCUSDT"});// Get candlestick dataawaitclient.getKline({region: "BA",code: "BTCUSDT",interval: "1h",limit: 100,});// Batch queriesawaitclient.getQuotes({region: "BA",codes: ["BTCUSDT","ETHUSDT"]});

CryptoClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 cryptocurrencyiTick Crypto Real-time Tick
getQuoteparams: 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 cryptocurrencyiTick Crypto Real-time Quote
getDepthparams: 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 cryptocurrencyiTick Crypto Real-time Depth
getKlinesoptions: 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 cryptocurrencyiTick Crypto K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple cryptocurrenciesiTick Crypto Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple cryptocurrenciesiTick Crypto Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple cryptocurrenciesiTick Crypto Batch Depths
getKlineoptions: 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 cryptocurrenciesiTick Crypto Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Crypto

Forex Module

Access foreign exchange market data.

import{ForexClient}from"@itick/node-sdk";constclient=newForexClient(token);awaitclient.getQuote({region: "GB",code: "EURUSD"});awaitclient.getDepth({region: "GB",code: "GBPUSD"});awaitclient.getTick({region: "GB",code: "USDJPY"});awaitclient.getKline({region: "GB",code: "EURUSD",interval: "1d",limit: 50});

ForexClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 pairiTick Forex Real-time Tick
getQuoteparams: 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 pairiTick Forex Real-time Quote
getDepthparams: 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 pairiTick Forex Real-time Depth
getKlinesoptions: 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 pairiTick Forex K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple currency pairsiTick Forex Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple currency pairsiTick Forex Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple currency pairsiTick Forex Batch Depths
getKlineoptions: 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 pairsiTick Forex Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Forex

Indices Module

Access global stock index data.

import{IndicesClient}from"@itick/node-sdk";constclient=newIndicesClient(token);awaitclient.getQuote({region: "US",code: "SPX"});awaitclient.getDepth({region: "US",code: "NDX"});awaitclient.getKline({region: "US",code: "DJI",interval: "1w",limit: 20});

IndicesClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 indexiTick Indices Real-time Tick
getQuoteparams: 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 indexiTick Indices Real-time Quote
getDepthparams: 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 indexiTick Indices Real-time Depth
getKlinesoptions: 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 indexiTick Indices K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple indicesiTick Indices Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple indicesiTick Indices Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple indicesiTick Indices Batch Depths
getKlineoptions: 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 indicesiTick Indices Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Indices

Futures Module

Access futures market data.

import{FutureClient}from"@itick/node-sdk";constclient=newFutureClient(token);awaitclient.getQuote({region: "US",code: "ES"});awaitclient.getDepth({region: "US",code: "NQ"});awaitclient.getKline({region: "US",code: "CL",interval: "5m",limit: 100});

FutureClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 contractiTick Futures Real-time Tick
getQuoteparams: 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 contractiTick Futures Real-time Quote
getDepthparams: 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 contractiTick Futures Real-time Depth
getKlinesoptions: 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 contractiTick Futures K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple futures contractsiTick Futures Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple futures contractsiTick Futures Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple futures contractsiTick Futures Batch Depths
getKlineoptions: 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 contractsiTick Futures Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Futures

Funds Module

Access mutual fund and ETF data.

import{FundClient}from"@itick/node-sdk";constclient=newFundClient(token);awaitclient.getQuote({region: "US",code: "VOO"});awaitclient.getDepth({region: "US",code: "QQQ"});awaitclient.getKline({region: "US",code: "SPY",interval: "1d",limit: 100});

FundClient Method Reference Table

Method NameParametersReturn TypeDescriptionDetails
getTickparams: 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 fundiTick Fund Real-time Tick
getQuoteparams: 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 fundiTick Fund Real-time Quote
getDepthparams: 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 fundiTick Fund Real-time Depth
getKlinesoptions: 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 fundiTick Fund K-line
getTicksparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<TickDataMap>>Get latest trade data for multiple fundsiTick Fund Batch Ticks
getQuotesparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<QuoteDataMap>>Get latest quotes for multiple fundsiTick Fund Batch Quotes
getDepthsparams: Object
- region: string (Market code)
- codes: string[] | string (Symbol code list)
Promise<APIResponse<DepthDataMap>>Get latest order book depth for multiple fundsiTick Fund Batch Depths
getKlineoptions: 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 fundsiTick Fund Batch K-lines
createSocketoptions?: CreateSocketOptions (Optional, WebSocket connection options)SocketClientCreate WebSocket connection for real-time data subscriptioniTick WebSocket Funds

🔌 WebSocket Real-time Data

Supported Data Types

  • quote: Real-time quote
  • depth: Order book depth
  • tick: Latest trade
  • kline@1m or kline@1: 1-minute candlestick
  • kline@5m or kline@2: 5-minute candlestick
  • kline@15m or kline@3: 15-minute candlestick
  • kline@30m or kline@4: 30-minute candlestick
  • kline@1h or kline@5: 1-hour candlestick
  • kline@2h or kline@6: 2-hour candlestick (crypto only)
  • kline@4h or kline@7: 4-hour candlestick (crypto only)
  • kline@1d or kline@8: Daily candlestick
  • kline@1w or kline@9: Weekly candlestick
  • kline@1M or kline@10: Monthly candlestick

Connection Options

constsocket=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"],},});

Event Handlers

// Connection openedsocket.onSocketOpen(()=>{console.log("Connected!");});// Receive messagessocket.onSocketMessage((data)=>{console.log("Received data:",data);});// Error occurredsocket.onSocketError((error)=>{console.error("Error:",error);});// Connection closedsocket.onSocketClose(()=>{console.log("Disconnected");});// Check connection statusconstisConnected=socket.checkSocketConnected();// Disconnectsocket.disconnectSocket();

Dynamic Subscription

// Subscribe after connectionsocket.subscribeSocket({ac: "subscribe",types: ["quote","depth"],codes: ["TSLA$US","NVDA$US"],});// Unsubscribesocket.subscribeSocket({ac: "unsubscribe",types: ["tick"],codes: ["AAPL$US"],});

⚠️ Error Handling

try{constresponse=awaitclient.getQuote({region: "US",code: "AAPL"});if(response.code!==0){console.error("API Error:",response.msg);return;}// Process dataconsole.log(response.data);}catch(error){if(errorinstanceofError){console.error("Network Error:",error.message);}}

📘 TypeScript Support

Full TypeScript support with comprehensive type definitions:

importtype{APIResponse,QuoteData,SocketKlineData,SocketTickData,SocketDepthData,SocketQuoteData,}from"@itick/node-sdk";// Type-safe responseconstresponse: 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") {constquoteData: SocketQuoteData=data;}
if (data?.type === "kline@1") {constklineData: SocketKlineData=data;}
if (data?.type === "tick") {consttickData: SocketTickData=data;}
if (data?.type === "depth") {constdepthData: SocketDepthData=data;}});

📖 Documentation

📄 License

MIT License - see the LICENSE file for details.

🤝 Contributing

Contributions are welcome! Feel free to submit a Pull Request.

📧 Support


Made with ❤️ by the iTick Team

About

Node.js 版本的 iTick API SDK,提供基础数据、股票IPO、股票市场假期、股票除权除息、股票实时数据、指数实时数据、期货实时数据、基金实时数据、外汇实时数据、加密货币实时数据的 REST API 查询和 WebSocket 实时数据订阅功能。

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages