English | 中文
Official Node.js/TypeScript SDK for the Infoway real-time financial data API.
API Documentation | Get API Key
Get your free API key at infoway.io -- 7-day free trial
npm install infoway-sdk
# or
yarn add infoway-sdk
# or
pnpm add infoway-sdkRequirements: Node.js >= 18.0.0
import { InfowayClient, KlineType } from "infoway-sdk";
const client = new InfowayClient({ apiKey: "YOUR_API_KEY" });
// Stock trade data
const trades = await client.stock.getTrade("AAPL.US");
console.log(trades);
// Multiple symbols
const multiTrades = await client.stock.getTrade("AAPL.US,TSLA.US,GOOGL.US");
// Order book depth
const depth = await client.stock.getDepth("AAPL.US");
// K-line data
const klines = await client.stock.getKline("AAPL.US", KlineType.DAY, 100);
// Crypto data
const btc = await client.crypto.getTrade("BTCUSDT");
const ethKline = await client.crypto.getKline("ETHUSDT", KlineType.HOUR_1, 50);
// Market temperature
const temp = await client.market.getTemperature("HK,US");
// Market breadth
const breadth = await client.market.getBreadth("US");
// Stock fundamentals
const valuation = await client.stockInfo.getValuation("AAPL.US");
const ratings = await client.stockInfo.getRatings("AAPL.US");
// Plate/sector data
const industries = await client.plate.getIndustry("HK");
const concepts = await client.plate.getConcept("HK");
// Basic info
const symbols = await client.basic.getSymbols("US");
const tradingDays = await client.basic.getTradingDays("US");You can set INFOWAY_API_KEY instead of passing it directly:
export INFOWAY_API_KEY=your_api_keyconst client = new InfowayClient(); // reads from INFOWAY_API_KEYimport { InfowayWebSocket, Business } from "infoway-sdk";
const ws = new InfowayWebSocket({
apiKey: "YOUR_API_KEY",
business: Business.STOCK,
});
ws.onTrade = (msg) => {
console.log("Trade:", msg);
};
ws.onDepth = (msg) => {
console.log("Depth:", msg);
};
ws.onKline = (msg) => {
console.log("Kline:", msg);
};
ws.onDisconnect = () => {
console.log("Disconnected, reconnecting...");
};
ws.onReconnect = () => {
console.log("Reconnected!");
};
// Subscribe after connection is established
await ws.subscribeTrade("AAPL.US,TSLA.US");
await ws.subscribeDepth("AAPL.US");
// Start receiving data
await ws.connect();
// To close:
// await ws.close();const ws = new InfowayWebSocket({
apiKey: "YOUR_API_KEY",
business: Business.CRYPTO,
});
ws.onTrade = (msg) => console.log("Crypto trade:", msg);
await ws.subscribeTrade("BTCUSDT,ETHUSDT");
await ws.connect();| Client | Prefix | Description |
|---|---|---|
client.stock |
stock |
HK, US, CN stock market data |
client.crypto |
crypto |
Cryptocurrency data |
client.japan |
japan |
Japan stock market data |
client.india |
india |
India stock market data |
client.common |
common |
Common market data |
client.basic |
-- | Symbols, trading days, hours |
client.market |
-- | Temperature, breadth, indexes |
client.plate |
-- | Industry/concept sectors |
client.stockInfo |
-- | Valuation, ratings, company info |
| Method | HTTP | Endpoint |
|---|---|---|
getTrade(codes) |
GET | /{prefix}/batch_trade/{codes} |
getDepth(codes) |
GET | /{prefix}/batch_depth/{codes} |
getKline(codes, klineType, count) |
POST | /{prefix}/v2/batch_kline |
| Value | Interval |
|---|---|
KlineType.MIN_1 (1) |
1 minute |
KlineType.MIN_5 (2) |
5 minutes |
KlineType.MIN_15 (3) |
15 minutes |
KlineType.MIN_30 (4) |
30 minutes |
KlineType.HOUR_1 (5) |
1 hour |
KlineType.HOUR_2 (6) |
2 hours |
KlineType.HOUR_4 (7) |
4 hours |
KlineType.DAY (8) |
1 day |
KlineType.WEEK (9) |
1 week |
KlineType.MONTH (10) |
1 month |
KlineType.QUARTER (11) |
1 quarter |
KlineType.YEAR (12) |
1 year |
| Code | Name | Description |
|---|---|---|
| 10000 | SUB_TRADE |
Subscribe to trade data |
| 10001 | PUSH_TRADE |
Push trade data |
| 10002 | UNSUB_TRADE |
Unsubscribe trade data |
| 10003 | SUB_DEPTH |
Subscribe to depth data |
| 10004 | PUSH_DEPTH |
Push depth data |
| 10005 | UNSUB_DEPTH |
Unsubscribe depth data |
| 10006 | SUB_KLINE |
Subscribe to K-line data |
| 10007 | PUSH_KLINE |
Push K-line data |
| 10008 | UNSUB_KLINE |
Unsubscribe K-line data |
| 10010 | HEARTBEAT |
Heartbeat keepalive |
import { InfowayAPIError, InfowayAuthError, InfowayTimeoutError } from "infoway-sdk";
try {
const data = await client.stock.getTrade("AAPL.US");
} catch (err) {
if (err instanceof InfowayAuthError) {
console.error("Authentication failed. Check your API key.");
} else if (err instanceof InfowayTimeoutError) {
console.error("Request timed out.");
} else if (err instanceof InfowayAPIError) {
console.error(`API error [${err.ret}]: ${err.msg}`);
}
}MIT