infoway-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +214 -0
- package/dist/index.d.mts +317 -0
- package/dist/index.d.ts +317 -0
- package/dist/index.js +615 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +561 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
# Infoway SDK for Node.js / TypeScript
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/infoway-sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/infoway-sdk)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
**English** | [中文](README_CN.md)
|
|
8
|
+
|
|
9
|
+
Official Node.js/TypeScript SDK for the [Infoway](https://infoway.io) real-time financial data API.
|
|
10
|
+
|
|
11
|
+
[API Documentation](https://docs.infoway.io) | [Get API Key](https://infoway.io)
|
|
12
|
+
|
|
13
|
+
> Get your free API key at [infoway.io](https://infoway.io) -- 7-day free trial
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install infoway-sdk
|
|
19
|
+
# or
|
|
20
|
+
yarn add infoway-sdk
|
|
21
|
+
# or
|
|
22
|
+
pnpm add infoway-sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**Requirements:** Node.js >= 18.0.0
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### REST API
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { InfowayClient, KlineType } from "infoway-sdk";
|
|
33
|
+
|
|
34
|
+
const client = new InfowayClient({ apiKey: "YOUR_API_KEY" });
|
|
35
|
+
|
|
36
|
+
// Stock trade data
|
|
37
|
+
const trades = await client.stock.getTrade("AAPL.US");
|
|
38
|
+
console.log(trades);
|
|
39
|
+
|
|
40
|
+
// Multiple symbols
|
|
41
|
+
const multiTrades = await client.stock.getTrade("AAPL.US,TSLA.US,GOOGL.US");
|
|
42
|
+
|
|
43
|
+
// Order book depth
|
|
44
|
+
const depth = await client.stock.getDepth("AAPL.US");
|
|
45
|
+
|
|
46
|
+
// K-line data
|
|
47
|
+
const klines = await client.stock.getKline("AAPL.US", KlineType.DAY, 100);
|
|
48
|
+
|
|
49
|
+
// Crypto data
|
|
50
|
+
const btc = await client.crypto.getTrade("BTCUSDT");
|
|
51
|
+
const ethKline = await client.crypto.getKline("ETHUSDT", KlineType.HOUR_1, 50);
|
|
52
|
+
|
|
53
|
+
// Market temperature
|
|
54
|
+
const temp = await client.market.getTemperature("HK,US");
|
|
55
|
+
|
|
56
|
+
// Market breadth
|
|
57
|
+
const breadth = await client.market.getBreadth("US");
|
|
58
|
+
|
|
59
|
+
// Stock fundamentals
|
|
60
|
+
const valuation = await client.stockInfo.getValuation("AAPL.US");
|
|
61
|
+
const ratings = await client.stockInfo.getRatings("AAPL.US");
|
|
62
|
+
|
|
63
|
+
// Plate/sector data
|
|
64
|
+
const industries = await client.plate.getIndustry("HK");
|
|
65
|
+
const concepts = await client.plate.getConcept("HK");
|
|
66
|
+
|
|
67
|
+
// Basic info
|
|
68
|
+
const symbols = await client.basic.getSymbols("US");
|
|
69
|
+
const tradingDays = await client.basic.getTradingDays("US");
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Environment Variable
|
|
73
|
+
|
|
74
|
+
You can set `INFOWAY_API_KEY` instead of passing it directly:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
export INFOWAY_API_KEY=your_api_key
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const client = new InfowayClient(); // reads from INFOWAY_API_KEY
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### WebSocket Real-time Data
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
import { InfowayWebSocket, Business } from "infoway-sdk";
|
|
88
|
+
|
|
89
|
+
const ws = new InfowayWebSocket({
|
|
90
|
+
apiKey: "YOUR_API_KEY",
|
|
91
|
+
business: Business.STOCK,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
ws.onTrade = (msg) => {
|
|
95
|
+
console.log("Trade:", msg);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
ws.onDepth = (msg) => {
|
|
99
|
+
console.log("Depth:", msg);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
ws.onKline = (msg) => {
|
|
103
|
+
console.log("Kline:", msg);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
ws.onDisconnect = () => {
|
|
107
|
+
console.log("Disconnected, reconnecting...");
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
ws.onReconnect = () => {
|
|
111
|
+
console.log("Reconnected!");
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Subscribe after connection is established
|
|
115
|
+
await ws.subscribeTrade("AAPL.US,TSLA.US");
|
|
116
|
+
await ws.subscribeDepth("AAPL.US");
|
|
117
|
+
|
|
118
|
+
// Start receiving data
|
|
119
|
+
await ws.connect();
|
|
120
|
+
|
|
121
|
+
// To close:
|
|
122
|
+
// await ws.close();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Crypto WebSocket
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
const ws = new InfowayWebSocket({
|
|
129
|
+
apiKey: "YOUR_API_KEY",
|
|
130
|
+
business: Business.CRYPTO,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
ws.onTrade = (msg) => console.log("Crypto trade:", msg);
|
|
134
|
+
await ws.subscribeTrade("BTCUSDT,ETHUSDT");
|
|
135
|
+
await ws.connect();
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## API Reference
|
|
139
|
+
|
|
140
|
+
### REST Clients
|
|
141
|
+
|
|
142
|
+
| Client | Prefix | Description |
|
|
143
|
+
|--------|--------|-------------|
|
|
144
|
+
| `client.stock` | `stock` | HK, US, CN stock market data |
|
|
145
|
+
| `client.crypto` | `crypto` | Cryptocurrency data |
|
|
146
|
+
| `client.japan` | `japan` | Japan stock market data |
|
|
147
|
+
| `client.india` | `india` | India stock market data |
|
|
148
|
+
| `client.common` | `common` | Common market data |
|
|
149
|
+
| `client.basic` | -- | Symbols, trading days, hours |
|
|
150
|
+
| `client.market` | -- | Temperature, breadth, indexes |
|
|
151
|
+
| `client.plate` | -- | Industry/concept sectors |
|
|
152
|
+
| `client.stockInfo` | -- | Valuation, ratings, company info |
|
|
153
|
+
|
|
154
|
+
### Market Data Methods (stock/crypto/japan/india/common)
|
|
155
|
+
|
|
156
|
+
| Method | HTTP | Endpoint |
|
|
157
|
+
|--------|------|----------|
|
|
158
|
+
| `getTrade(codes)` | GET | `/{prefix}/batch_trade/{codes}` |
|
|
159
|
+
| `getDepth(codes)` | GET | `/{prefix}/batch_depth/{codes}` |
|
|
160
|
+
| `getKline(codes, klineType, count)` | POST | `/{prefix}/v2/batch_kline` |
|
|
161
|
+
|
|
162
|
+
### KlineType Enum
|
|
163
|
+
|
|
164
|
+
| Value | Interval |
|
|
165
|
+
|-------|----------|
|
|
166
|
+
| `KlineType.MIN_1` (1) | 1 minute |
|
|
167
|
+
| `KlineType.MIN_5` (2) | 5 minutes |
|
|
168
|
+
| `KlineType.MIN_15` (3) | 15 minutes |
|
|
169
|
+
| `KlineType.MIN_30` (4) | 30 minutes |
|
|
170
|
+
| `KlineType.HOUR_1` (5) | 1 hour |
|
|
171
|
+
| `KlineType.HOUR_2` (6) | 2 hours |
|
|
172
|
+
| `KlineType.HOUR_4` (7) | 4 hours |
|
|
173
|
+
| `KlineType.DAY` (8) | 1 day |
|
|
174
|
+
| `KlineType.WEEK` (9) | 1 week |
|
|
175
|
+
| `KlineType.MONTH` (10) | 1 month |
|
|
176
|
+
| `KlineType.QUARTER` (11) | 1 quarter |
|
|
177
|
+
| `KlineType.YEAR` (12) | 1 year |
|
|
178
|
+
|
|
179
|
+
### WebSocket Codes
|
|
180
|
+
|
|
181
|
+
| Code | Name | Description |
|
|
182
|
+
|------|------|-------------|
|
|
183
|
+
| 10000 | `SUB_TRADE` | Subscribe to trade data |
|
|
184
|
+
| 10001 | `PUSH_TRADE` | Push trade data |
|
|
185
|
+
| 10002 | `UNSUB_TRADE` | Unsubscribe trade data |
|
|
186
|
+
| 10003 | `SUB_DEPTH` | Subscribe to depth data |
|
|
187
|
+
| 10004 | `PUSH_DEPTH` | Push depth data |
|
|
188
|
+
| 10005 | `UNSUB_DEPTH` | Unsubscribe depth data |
|
|
189
|
+
| 10006 | `SUB_KLINE` | Subscribe to K-line data |
|
|
190
|
+
| 10007 | `PUSH_KLINE` | Push K-line data |
|
|
191
|
+
| 10008 | `UNSUB_KLINE` | Unsubscribe K-line data |
|
|
192
|
+
| 10010 | `HEARTBEAT` | Heartbeat keepalive |
|
|
193
|
+
|
|
194
|
+
### Error Handling
|
|
195
|
+
|
|
196
|
+
```typescript
|
|
197
|
+
import { InfowayAPIError, InfowayAuthError, InfowayTimeoutError } from "infoway-sdk";
|
|
198
|
+
|
|
199
|
+
try {
|
|
200
|
+
const data = await client.stock.getTrade("AAPL.US");
|
|
201
|
+
} catch (err) {
|
|
202
|
+
if (err instanceof InfowayAuthError) {
|
|
203
|
+
console.error("Authentication failed. Check your API key.");
|
|
204
|
+
} else if (err instanceof InfowayTimeoutError) {
|
|
205
|
+
console.error("Request timed out.");
|
|
206
|
+
} else if (err instanceof InfowayAPIError) {
|
|
207
|
+
console.error(`API error [${err.ret}]: ${err.msg}`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level HTTP client with retry and error handling.
|
|
3
|
+
* Uses native fetch (Node 18+).
|
|
4
|
+
*/
|
|
5
|
+
declare class HttpClient {
|
|
6
|
+
private readonly _apiKey;
|
|
7
|
+
private readonly _baseUrl;
|
|
8
|
+
private readonly _timeout;
|
|
9
|
+
private readonly _maxRetries;
|
|
10
|
+
constructor(options?: {
|
|
11
|
+
apiKey?: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
maxRetries?: number;
|
|
15
|
+
});
|
|
16
|
+
/** Expose apiKey for testing. */
|
|
17
|
+
get apiKey(): string;
|
|
18
|
+
get(path: string, params?: Record<string, string | number | undefined>): Promise<unknown>;
|
|
19
|
+
post(path: string, body?: Record<string, unknown>): Promise<unknown>;
|
|
20
|
+
private _buildUrl;
|
|
21
|
+
private _request;
|
|
22
|
+
private _handleResponse;
|
|
23
|
+
private _sleep;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Shared market data methods for trade/depth/kline.
|
|
28
|
+
* Base class for StockClient, CryptoClient, JapanClient, IndiaClient, CommonClient.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
declare abstract class MarketDataClient {
|
|
32
|
+
protected abstract readonly _prefix: string;
|
|
33
|
+
protected readonly _http: HttpClient;
|
|
34
|
+
constructor(http: HttpClient);
|
|
35
|
+
/**
|
|
36
|
+
* Get real-time trade data.
|
|
37
|
+
* @param codes - Comma-separated symbol codes (e.g. "AAPL.US" or "AAPL.US,TSLA.US")
|
|
38
|
+
*/
|
|
39
|
+
getTrade(codes: string): Promise<unknown>;
|
|
40
|
+
/**
|
|
41
|
+
* Get real-time order book depth.
|
|
42
|
+
* @param codes - Comma-separated symbol codes
|
|
43
|
+
*/
|
|
44
|
+
getDepth(codes: string): Promise<unknown>;
|
|
45
|
+
/**
|
|
46
|
+
* Get candlestick/K-line data.
|
|
47
|
+
* @param codes - Comma-separated symbol codes
|
|
48
|
+
* @param klineType - K-line interval (use KlineType enum or number 1-12)
|
|
49
|
+
* @param count - Number of candles to return
|
|
50
|
+
*/
|
|
51
|
+
getKline(codes: string, klineType: number, count: number): Promise<unknown>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Stock market data client (HK, US, CN). */
|
|
55
|
+
|
|
56
|
+
declare class StockClient extends MarketDataClient {
|
|
57
|
+
protected readonly _prefix = "stock";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Crypto market data client. */
|
|
61
|
+
|
|
62
|
+
declare class CryptoClient extends MarketDataClient {
|
|
63
|
+
protected readonly _prefix = "crypto";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Japan market data client. */
|
|
67
|
+
|
|
68
|
+
declare class JapanClient extends MarketDataClient {
|
|
69
|
+
protected readonly _prefix = "japan";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** India market data client. */
|
|
73
|
+
|
|
74
|
+
declare class IndiaClient extends MarketDataClient {
|
|
75
|
+
protected readonly _prefix = "india";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Common market data client. */
|
|
79
|
+
|
|
80
|
+
declare class CommonClient extends MarketDataClient {
|
|
81
|
+
protected readonly _prefix = "common";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Basic information client (symbols, trading days, hours). */
|
|
85
|
+
|
|
86
|
+
declare class BasicClient {
|
|
87
|
+
private readonly _http;
|
|
88
|
+
constructor(http: HttpClient);
|
|
89
|
+
getSymbols(market?: string): Promise<unknown>;
|
|
90
|
+
getSymbolInfo(codes: string): Promise<unknown>;
|
|
91
|
+
getAdjustmentFactors(codes: string): Promise<unknown>;
|
|
92
|
+
getTradingDays(market: string): Promise<unknown>;
|
|
93
|
+
getTradingHours(market?: string): Promise<unknown>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Market overview client (temperature, breadth, indexes, leaders). */
|
|
97
|
+
|
|
98
|
+
declare class MarketClient {
|
|
99
|
+
private readonly _http;
|
|
100
|
+
constructor(http: HttpClient);
|
|
101
|
+
getTemperature(market?: string): Promise<unknown>;
|
|
102
|
+
getBreadth(market: string): Promise<unknown>;
|
|
103
|
+
getIndexes(): Promise<unknown>;
|
|
104
|
+
getLeaders(market: string, limit?: number): Promise<unknown>;
|
|
105
|
+
getRankConfig(market: string): Promise<unknown>;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Plate (sector) data client. */
|
|
109
|
+
|
|
110
|
+
declare class PlateClient {
|
|
111
|
+
private readonly _http;
|
|
112
|
+
constructor(http: HttpClient);
|
|
113
|
+
getIndustry(market: string, limit?: number): Promise<unknown>;
|
|
114
|
+
getConcept(market: string, limit?: number): Promise<unknown>;
|
|
115
|
+
getMembers(plateSymbol: string, offset?: number, limit?: number): Promise<unknown>;
|
|
116
|
+
getIntro(plateSymbol: string): Promise<unknown>;
|
|
117
|
+
getChart(market: string, limit?: number): Promise<unknown>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Stock fundamental data client. */
|
|
121
|
+
|
|
122
|
+
declare class StockInfoClient {
|
|
123
|
+
private readonly _http;
|
|
124
|
+
constructor(http: HttpClient);
|
|
125
|
+
getValuation(symbol: string): Promise<unknown>;
|
|
126
|
+
getRatings(symbol: string): Promise<unknown>;
|
|
127
|
+
getCompany(symbol: string): Promise<unknown>;
|
|
128
|
+
getPanorama(symbol: string): Promise<unknown>;
|
|
129
|
+
getConcepts(symbol: string): Promise<unknown>;
|
|
130
|
+
getEvents(symbol: string, limit?: number): Promise<unknown>;
|
|
131
|
+
getDrivers(symbol: string): Promise<unknown>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Shared type definitions and enums for the Infoway SDK.
|
|
136
|
+
*/
|
|
137
|
+
/** K-line (candlestick) interval types. */
|
|
138
|
+
declare enum KlineType {
|
|
139
|
+
MIN_1 = 1,
|
|
140
|
+
MIN_5 = 2,
|
|
141
|
+
MIN_15 = 3,
|
|
142
|
+
MIN_30 = 4,
|
|
143
|
+
HOUR_1 = 5,
|
|
144
|
+
HOUR_2 = 6,
|
|
145
|
+
HOUR_4 = 7,
|
|
146
|
+
DAY = 8,
|
|
147
|
+
WEEK = 9,
|
|
148
|
+
MONTH = 10,
|
|
149
|
+
QUARTER = 11,
|
|
150
|
+
YEAR = 12
|
|
151
|
+
}
|
|
152
|
+
/** Business types for WebSocket connections. */
|
|
153
|
+
declare const Business: {
|
|
154
|
+
readonly STOCK: "stock";
|
|
155
|
+
readonly JAPAN: "japan";
|
|
156
|
+
readonly INDIA: "india";
|
|
157
|
+
readonly CRYPTO: "crypto";
|
|
158
|
+
readonly COMMON: "common";
|
|
159
|
+
};
|
|
160
|
+
type Business = (typeof Business)[keyof typeof Business];
|
|
161
|
+
/** WebSocket message codes. */
|
|
162
|
+
declare enum WsCode {
|
|
163
|
+
SUB_TRADE = 10000,
|
|
164
|
+
PUSH_TRADE = 10001,
|
|
165
|
+
UNSUB_TRADE = 10002,
|
|
166
|
+
SUB_DEPTH = 10003,
|
|
167
|
+
PUSH_DEPTH = 10004,
|
|
168
|
+
UNSUB_DEPTH = 10005,
|
|
169
|
+
SUB_KLINE = 10006,
|
|
170
|
+
PUSH_KLINE = 10007,
|
|
171
|
+
UNSUB_KLINE = 10008,
|
|
172
|
+
HEARTBEAT = 10010
|
|
173
|
+
}
|
|
174
|
+
/** Options for creating an InfowayClient. */
|
|
175
|
+
interface InfowayClientOptions {
|
|
176
|
+
/** Your Infoway API key. Falls back to INFOWAY_API_KEY env var. */
|
|
177
|
+
apiKey?: string;
|
|
178
|
+
/** Base URL for REST API. Default: https://data.infoway.io */
|
|
179
|
+
baseUrl?: string;
|
|
180
|
+
/** Request timeout in milliseconds. Default: 15000 */
|
|
181
|
+
timeout?: number;
|
|
182
|
+
/** Max retry attempts for failed requests. Default: 3 */
|
|
183
|
+
maxRetries?: number;
|
|
184
|
+
}
|
|
185
|
+
/** Options for creating an InfowayWebSocket. */
|
|
186
|
+
interface InfowayWebSocketOptions {
|
|
187
|
+
/** Your Infoway API key. */
|
|
188
|
+
apiKey: string;
|
|
189
|
+
/** Business type (stock, crypto, japan, india, common). */
|
|
190
|
+
business: Business;
|
|
191
|
+
/** Base WebSocket URL. Default: wss://data.infoway.io/ws */
|
|
192
|
+
baseUrl?: string;
|
|
193
|
+
/** Maximum reconnect attempts. Unlimited if not set. */
|
|
194
|
+
maxReconnectAttempts?: number;
|
|
195
|
+
}
|
|
196
|
+
/** Standard API response envelope. */
|
|
197
|
+
interface ApiResponse<T = unknown> {
|
|
198
|
+
ret: number;
|
|
199
|
+
/** Some endpoints return `code` instead of `ret`. */
|
|
200
|
+
code?: number;
|
|
201
|
+
msg: string;
|
|
202
|
+
traceId?: string;
|
|
203
|
+
data: T;
|
|
204
|
+
}
|
|
205
|
+
/** WebSocket message structure. */
|
|
206
|
+
interface WsMessage {
|
|
207
|
+
code: number;
|
|
208
|
+
trace: string;
|
|
209
|
+
data?: Record<string, unknown>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Main entry point for the Infoway SDK.
|
|
214
|
+
*/
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Infoway API client.
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```ts
|
|
221
|
+
* import { InfowayClient } from "infoway-sdk";
|
|
222
|
+
*
|
|
223
|
+
* const client = new InfowayClient({ apiKey: "YOUR_API_KEY" });
|
|
224
|
+
* const trades = await client.stock.getTrade("AAPL.US");
|
|
225
|
+
* const klines = await client.crypto.getKline("BTCUSDT", 8, 100);
|
|
226
|
+
* const temp = await client.market.getTemperature("HK,US");
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
declare class InfowayClient {
|
|
230
|
+
/** @internal */
|
|
231
|
+
readonly _http: HttpClient;
|
|
232
|
+
readonly stock: StockClient;
|
|
233
|
+
readonly crypto: CryptoClient;
|
|
234
|
+
readonly japan: JapanClient;
|
|
235
|
+
readonly india: IndiaClient;
|
|
236
|
+
readonly common: CommonClient;
|
|
237
|
+
readonly basic: BasicClient;
|
|
238
|
+
readonly market: MarketClient;
|
|
239
|
+
readonly plate: PlateClient;
|
|
240
|
+
readonly stockInfo: StockInfoClient;
|
|
241
|
+
constructor(options?: InfowayClientOptions);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* WebSocket client with auto-reconnect, heartbeat, and subscription management.
|
|
246
|
+
*/
|
|
247
|
+
|
|
248
|
+
type MessageHandler = (msg: Record<string, unknown>) => void;
|
|
249
|
+
type ErrorHandler = (err: Error) => void;
|
|
250
|
+
type VoidHandler = () => void;
|
|
251
|
+
declare class InfowayWebSocket {
|
|
252
|
+
/** @internal */
|
|
253
|
+
readonly _url: string;
|
|
254
|
+
private readonly _maxReconnect;
|
|
255
|
+
private _ws;
|
|
256
|
+
/** @internal */
|
|
257
|
+
readonly _subscriptions: Set<string>;
|
|
258
|
+
private _running;
|
|
259
|
+
private _backoff;
|
|
260
|
+
private _heartbeatTimer;
|
|
261
|
+
/** Called when a trade push message is received. */
|
|
262
|
+
onTrade: MessageHandler | null;
|
|
263
|
+
/** Called when a depth push message is received. */
|
|
264
|
+
onDepth: MessageHandler | null;
|
|
265
|
+
/** Called when a kline push message is received. */
|
|
266
|
+
onKline: MessageHandler | null;
|
|
267
|
+
/** Called when an error occurs. */
|
|
268
|
+
onError: ErrorHandler | null;
|
|
269
|
+
/** Called after a successful reconnection. */
|
|
270
|
+
onReconnect: VoidHandler | null;
|
|
271
|
+
/** Called when the connection is lost. */
|
|
272
|
+
onDisconnect: VoidHandler | null;
|
|
273
|
+
constructor(options: InfowayWebSocketOptions);
|
|
274
|
+
/**
|
|
275
|
+
* Build a WebSocket message JSON string.
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
_buildMessage(code: WsCode | number, codes?: string): string;
|
|
279
|
+
/**
|
|
280
|
+
* Connect and start listening. Returns a Promise that resolves
|
|
281
|
+
* when the connection is closed intentionally or max reconnects exceeded.
|
|
282
|
+
*/
|
|
283
|
+
connect(): Promise<void>;
|
|
284
|
+
private _connectOnce;
|
|
285
|
+
private _startHeartbeat;
|
|
286
|
+
private _stopHeartbeat;
|
|
287
|
+
private _resubscribe;
|
|
288
|
+
subscribeTrade(codes: string): Promise<void>;
|
|
289
|
+
subscribeDepth(codes: string): Promise<void>;
|
|
290
|
+
subscribeKline(codes: string): Promise<void>;
|
|
291
|
+
unsubscribeTrade(codes: string): Promise<void>;
|
|
292
|
+
unsubscribeDepth(codes: string): Promise<void>;
|
|
293
|
+
unsubscribeKline(codes: string): Promise<void>;
|
|
294
|
+
close(): Promise<void>;
|
|
295
|
+
private _sleep;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Infoway SDK exception types.
|
|
300
|
+
*/
|
|
301
|
+
/** Raised when a request times out. */
|
|
302
|
+
declare class InfowayTimeoutError extends Error {
|
|
303
|
+
constructor(message?: string);
|
|
304
|
+
}
|
|
305
|
+
/** Raised when the API returns a non-success response. */
|
|
306
|
+
declare class InfowayAPIError extends Error {
|
|
307
|
+
readonly ret: number;
|
|
308
|
+
readonly msg: string;
|
|
309
|
+
readonly traceId?: string;
|
|
310
|
+
constructor(ret: number, msg: string, traceId?: string);
|
|
311
|
+
}
|
|
312
|
+
/** Raised on 401 Unauthorized. */
|
|
313
|
+
declare class InfowayAuthError extends InfowayAPIError {
|
|
314
|
+
constructor(msg?: string);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export { type ApiResponse, BasicClient, Business, CommonClient, CryptoClient, HttpClient, IndiaClient, InfowayAPIError, InfowayAuthError, InfowayClient, type InfowayClientOptions, InfowayTimeoutError, InfowayWebSocket, type InfowayWebSocketOptions, JapanClient, KlineType, MarketClient, PlateClient, StockClient, StockInfoClient, WsCode, type WsMessage };
|