@tigeropenapi/tigeropen 0.1.0 → 0.4.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 +475 -104
- package/dist/cjs/client/api-request.js +16 -10
- package/dist/cjs/client/api-response.js +23 -3
- package/dist/cjs/client/case-convert.js +35 -0
- package/dist/cjs/client/http-client.js +47 -21
- package/dist/cjs/client/index.js +6 -2
- package/dist/cjs/config/client-config.js +130 -49
- package/dist/cjs/config/domain.js +21 -2
- package/dist/cjs/config/index.js +3 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/model/contract.js +1 -2
- package/dist/cjs/model/enums.js +89 -7
- package/dist/cjs/model/order-helpers.js +9 -9
- package/dist/cjs/model/order-status.js +46 -0
- package/dist/cjs/model/order.js +5 -2
- package/dist/cjs/model/position.js +1 -2
- package/dist/cjs/model/quote-requests.js +11 -0
- package/dist/cjs/model/quote.js +7 -0
- package/dist/cjs/model/trade-requests.js +13 -0
- package/dist/cjs/model/trade.js +2 -0
- package/dist/cjs/push/index.js +6 -3
- package/dist/cjs/push/pb/AssetData.js +208 -0
- package/dist/cjs/push/pb/KlineData.js +184 -0
- package/dist/cjs/push/pb/OptionTopData.js +427 -0
- package/dist/cjs/push/pb/OrderStatusData.js +592 -0
- package/dist/cjs/push/pb/OrderTransactionData.js +256 -0
- package/dist/cjs/push/pb/PositionData.js +316 -0
- package/dist/cjs/push/pb/PushData.js +219 -0
- package/dist/cjs/push/pb/QuoteBBOData.js +160 -0
- package/dist/cjs/push/pb/QuoteBasicData.js +329 -0
- package/dist/cjs/push/pb/QuoteData.js +507 -0
- package/dist/cjs/push/pb/QuoteDepthData.js +220 -0
- package/dist/cjs/push/pb/Request.js +278 -0
- package/dist/cjs/push/pb/Response.js +97 -0
- package/dist/cjs/push/pb/SocketCommon.js +86 -0
- package/dist/cjs/push/pb/StockTopData.js +199 -0
- package/dist/cjs/push/pb/TickData.js +202 -0
- package/dist/cjs/push/pb/TradeTickData.js +308 -0
- package/dist/cjs/push/pb/index.js +49 -0
- package/dist/cjs/push/proto-message.js +135 -0
- package/dist/cjs/push/push-client.js +361 -163
- package/dist/cjs/push/push-message.js +8 -60
- package/dist/cjs/push/varint.js +76 -0
- package/dist/cjs/quote/index.js +3 -2
- package/dist/cjs/quote/quote-client.js +440 -94
- package/dist/cjs/signer/signer.js +10 -10
- package/dist/cjs/trade/trade-client.js +197 -62
- package/dist/esm/client/api-request.js +14 -8
- package/dist/esm/client/api-response.js +22 -3
- package/dist/esm/client/case-convert.js +31 -0
- package/dist/esm/client/http-client.js +48 -22
- package/dist/esm/client/index.js +3 -2
- package/dist/esm/config/client-config.js +131 -51
- package/dist/esm/config/domain.js +20 -2
- package/dist/esm/config/index.js +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/model/contract.js +1 -2
- package/dist/esm/model/enums.js +87 -6
- package/dist/esm/model/order-helpers.js +9 -9
- package/dist/esm/model/order-status.js +43 -0
- package/dist/esm/model/order.js +5 -2
- package/dist/esm/model/position.js +1 -2
- package/dist/esm/model/quote-requests.js +10 -0
- package/dist/esm/model/quote.js +6 -0
- package/dist/esm/model/trade-requests.js +12 -0
- package/dist/esm/model/trade.js +1 -0
- package/dist/esm/push/index.js +4 -2
- package/dist/esm/push/pb/AssetData.js +205 -0
- package/dist/esm/push/pb/KlineData.js +181 -0
- package/dist/esm/push/pb/OptionTopData.js +424 -0
- package/dist/esm/push/pb/OrderStatusData.js +589 -0
- package/dist/esm/push/pb/OrderTransactionData.js +253 -0
- package/dist/esm/push/pb/PositionData.js +313 -0
- package/dist/esm/push/pb/PushData.js +216 -0
- package/dist/esm/push/pb/QuoteBBOData.js +157 -0
- package/dist/esm/push/pb/QuoteBasicData.js +326 -0
- package/dist/esm/push/pb/QuoteData.js +504 -0
- package/dist/esm/push/pb/QuoteDepthData.js +217 -0
- package/dist/esm/push/pb/Request.js +275 -0
- package/dist/esm/push/pb/Response.js +94 -0
- package/dist/esm/push/pb/SocketCommon.js +83 -0
- package/dist/esm/push/pb/StockTopData.js +196 -0
- package/dist/esm/push/pb/TickData.js +199 -0
- package/dist/esm/push/pb/TradeTickData.js +305 -0
- package/dist/esm/push/pb/index.js +25 -0
- package/dist/esm/push/proto-message.js +127 -0
- package/dist/esm/push/push-client.js +329 -164
- package/dist/esm/push/push-message.js +7 -56
- package/dist/esm/push/varint.js +72 -0
- package/dist/esm/quote/index.js +2 -2
- package/dist/esm/quote/quote-client.js +439 -94
- package/dist/esm/signer/signer.js +10 -10
- package/dist/esm/trade/trade-client.js +197 -62
- package/dist/types/client/api-request.d.ts +12 -11
- package/dist/types/client/api-response.d.ts +15 -7
- package/dist/types/client/case-convert.d.ts +16 -0
- package/dist/types/client/http-client.d.ts +26 -14
- package/dist/types/client/index.d.ts +3 -2
- package/dist/types/config/client-config.d.ts +29 -13
- package/dist/types/config/domain.d.ts +9 -0
- package/dist/types/config/index.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/model/contract.d.ts +13 -29
- package/dist/types/model/enums.d.ts +60 -6
- package/dist/types/model/order-helpers.d.ts +21 -20
- package/dist/types/model/order-status.d.ts +14 -0
- package/dist/types/model/order.d.ts +101 -55
- package/dist/types/model/position.d.ts +26 -24
- package/dist/types/model/quote-requests.d.ts +344 -0
- package/dist/types/model/quote.d.ts +572 -0
- package/dist/types/model/trade-requests.d.ts +195 -0
- package/dist/types/model/trade.d.ts +235 -0
- package/dist/types/push/callbacks.d.ts +32 -51
- package/dist/types/push/index.d.ts +5 -3
- package/dist/types/push/pb/AssetData.d.ts +47 -0
- package/dist/types/push/pb/KlineData.d.ts +43 -0
- package/dist/types/push/pb/OptionTopData.d.ts +76 -0
- package/dist/types/push/pb/OrderStatusData.d.ts +100 -0
- package/dist/types/push/pb/OrderTransactionData.d.ts +51 -0
- package/dist/types/push/pb/PositionData.d.ts +63 -0
- package/dist/types/push/pb/PushData.d.ts +46 -0
- package/dist/types/push/pb/QuoteBBOData.d.ts +35 -0
- package/dist/types/push/pb/QuoteBasicData.d.ts +66 -0
- package/dist/types/push/pb/QuoteData.d.ts +94 -0
- package/dist/types/push/pb/QuoteDepthData.d.ts +37 -0
- package/dist/types/push/pb/Request.d.ts +44 -0
- package/dist/types/push/pb/Response.d.ts +30 -0
- package/dist/types/push/pb/SocketCommon.d.ts +64 -0
- package/dist/types/push/pb/StockTopData.d.ts +37 -0
- package/dist/types/push/pb/TickData.d.ts +44 -0
- package/dist/types/push/pb/TradeTickData.d.ts +53 -0
- package/dist/types/push/pb/index.d.ts +39 -0
- package/dist/types/push/proto-message.d.ts +33 -0
- package/dist/types/push/push-client.d.ts +100 -68
- package/dist/types/push/push-message.d.ts +7 -147
- package/dist/types/push/varint.d.ts +23 -0
- package/dist/types/quote/index.d.ts +2 -2
- package/dist/types/quote/quote-client.d.ts +154 -47
- package/dist/types/signer/signer.d.ts +6 -6
- package/dist/types/trade/trade-client.d.ts +106 -38
- package/package.json +11 -6
|
@@ -1,110 +1,456 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuoteClient = void 0;
|
|
4
|
+
exports.parseOptionIdentifier = parseOptionIdentifier;
|
|
4
5
|
const api_request_1 = require("../client/api-request");
|
|
6
|
+
const api_response_1 = require("../client/api-response");
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
8
|
+
* Parse an OCC-style option identifier like "AAPL 260619C00150000"
|
|
9
|
+
* into its component parts.
|
|
7
10
|
*/
|
|
11
|
+
function parseOptionIdentifier(identifier) {
|
|
12
|
+
const trimmed = identifier.trim();
|
|
13
|
+
const spaceIdx = trimmed.indexOf(' ');
|
|
14
|
+
if (spaceIdx === -1) {
|
|
15
|
+
throw new Error(`invalid option identifier: ${identifier}`);
|
|
16
|
+
}
|
|
17
|
+
const symbol = trimmed.substring(0, spaceIdx);
|
|
18
|
+
const rest = trimmed.substring(spaceIdx + 1).trim();
|
|
19
|
+
if (rest.length < 15) {
|
|
20
|
+
throw new Error(`option code too short: ${rest}`);
|
|
21
|
+
}
|
|
22
|
+
const datePart = rest.substring(0, 6);
|
|
23
|
+
const rightChar = rest.substring(6, 7);
|
|
24
|
+
const strikePart = rest.substring(7);
|
|
25
|
+
const yy = parseInt(datePart.substring(0, 2), 10);
|
|
26
|
+
const mm = parseInt(datePart.substring(2, 4), 10);
|
|
27
|
+
const dd = parseInt(datePart.substring(4, 6), 10);
|
|
28
|
+
const expiryMs = Date.UTC(2000 + yy, mm - 1, dd);
|
|
29
|
+
const right = rightChar === 'C' ? 'CALL' : rightChar === 'P' ? 'PUT' : '';
|
|
30
|
+
if (!right)
|
|
31
|
+
throw new Error(`invalid right character: ${rightChar}`);
|
|
32
|
+
const strikeInt = parseInt(strikePart, 10);
|
|
33
|
+
if (Number.isNaN(strikeInt))
|
|
34
|
+
throw new Error(`invalid strike digits: ${strikePart}`);
|
|
35
|
+
const strike = strikeInt / 1000;
|
|
36
|
+
return { symbol, expiryMs, right, strike };
|
|
37
|
+
}
|
|
38
|
+
/** Market data client wrapping all quote-related APIs. */
|
|
8
39
|
class QuoteClient {
|
|
9
40
|
constructor(httpClient) {
|
|
10
41
|
this.httpClient = httpClient;
|
|
11
42
|
}
|
|
43
|
+
async callInto(method, bizParams, version) {
|
|
44
|
+
const request = (0, api_request_1.createApiRequest)(method, bizParams, version);
|
|
45
|
+
const response = await this.httpClient.executeRequest(request);
|
|
46
|
+
return (0, api_response_1.unmarshalData)(response.data);
|
|
47
|
+
}
|
|
12
48
|
/**
|
|
13
|
-
*
|
|
49
|
+
* Some endpoints return either a list or a single object depending on the
|
|
50
|
+
* server response shape (future_contract_by_contract_code /
|
|
51
|
+
* future_continuous_contracts). Unify into an array.
|
|
14
52
|
*/
|
|
15
|
-
async
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
async
|
|
48
|
-
return this.
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async
|
|
52
|
-
return this.
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
async
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return this.
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async
|
|
98
|
-
return this.
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
53
|
+
async callIntoListOrObject(method, bizParams, version) {
|
|
54
|
+
const raw = await this.callInto(method, bizParams, version);
|
|
55
|
+
if (raw == null)
|
|
56
|
+
return [];
|
|
57
|
+
if (Array.isArray(raw))
|
|
58
|
+
return raw;
|
|
59
|
+
return [raw];
|
|
60
|
+
}
|
|
61
|
+
/** Unwrap server {"items":[...]} envelope. */
|
|
62
|
+
async callIntoItems(method, bizParams, version) {
|
|
63
|
+
const wrap = await this.callInto(method, bizParams, version);
|
|
64
|
+
return wrap?.items ?? [];
|
|
65
|
+
}
|
|
66
|
+
// === Basic market data ===
|
|
67
|
+
async getMarketState(market) {
|
|
68
|
+
return this.callInto('market_state', { market });
|
|
69
|
+
}
|
|
70
|
+
/** Real-time stock briefs. wire: quote_real_time */
|
|
71
|
+
async getBrief(req) {
|
|
72
|
+
return this.callInto('quote_real_time', req);
|
|
73
|
+
}
|
|
74
|
+
async getKline(symbol, period) {
|
|
75
|
+
return this.callInto('kline', { symbols: [symbol], period });
|
|
76
|
+
}
|
|
77
|
+
async getTimeline(symbols) {
|
|
78
|
+
return this.callInto('timeline', { symbols });
|
|
79
|
+
}
|
|
80
|
+
/** Tick-by-tick trades. wire: trade_tick */
|
|
81
|
+
async getTradeTick(req) {
|
|
82
|
+
return this.callInto('trade_tick', req);
|
|
83
|
+
}
|
|
84
|
+
/** Depth snapshot. wire: quote_depth */
|
|
85
|
+
async getQuoteDepth(req) {
|
|
86
|
+
return this.callInto('quote_depth', req);
|
|
87
|
+
}
|
|
88
|
+
// === Options ===
|
|
89
|
+
async getOptionExpiration(symbol) {
|
|
90
|
+
return this.callInto('option_expiration', { symbols: [symbol] });
|
|
91
|
+
}
|
|
92
|
+
/** Option chain; `expiry` is "YYYY-MM-DD". */
|
|
93
|
+
async getOptionChain(symbol, expiry) {
|
|
94
|
+
const d = new Date(expiry + 'T00:00:00Z');
|
|
95
|
+
const expiryMs = d.getTime();
|
|
96
|
+
if (Number.isNaN(expiryMs)) {
|
|
97
|
+
throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
|
|
98
|
+
}
|
|
99
|
+
return this.callInto('option_chain', { option_basic: [{ symbol, expiry: expiryMs }] }, '3.0');
|
|
100
|
+
}
|
|
101
|
+
async getOptionBrief(identifiers) {
|
|
102
|
+
const optionBasic = identifiers.map((id) => {
|
|
103
|
+
const p = parseOptionIdentifier(id);
|
|
104
|
+
return { symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike };
|
|
105
|
+
});
|
|
106
|
+
return this.callInto('option_brief', { option_basic: optionBasic }, '2.0');
|
|
107
|
+
}
|
|
108
|
+
async getOptionKline(identifier, period) {
|
|
109
|
+
const p = parseOptionIdentifier(identifier);
|
|
110
|
+
return this.callInto('option_kline', {
|
|
111
|
+
option_query: [{ symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike, period }],
|
|
112
|
+
}, '2.0');
|
|
113
|
+
}
|
|
114
|
+
// === Futures ===
|
|
115
|
+
async getFutureExchange() {
|
|
116
|
+
return this.callInto('future_exchange', { secType: 'FUT' });
|
|
117
|
+
}
|
|
118
|
+
async getFutureContracts(exchange) {
|
|
119
|
+
return this.callInto('future_contract_by_exchange_code', { exchangeCode: exchange });
|
|
120
|
+
}
|
|
121
|
+
/** Real-time futures quotes. wire: future_real_time_quote */
|
|
122
|
+
async getFutureRealTimeQuote(req) {
|
|
123
|
+
return this.callInto('future_real_time_quote', req);
|
|
124
|
+
}
|
|
125
|
+
/** Futures K-line; use -1 for unbounded beginTime / endTime. */
|
|
126
|
+
async getFutureKline(req) {
|
|
127
|
+
const body = {
|
|
128
|
+
...req,
|
|
129
|
+
beginTime: req.beginTime ?? -1,
|
|
130
|
+
endTime: req.endTime ?? -1,
|
|
131
|
+
};
|
|
132
|
+
return this.callInto('future_kline', body);
|
|
133
|
+
}
|
|
134
|
+
// === Fundamentals ===
|
|
135
|
+
async getFinancialDaily(req) {
|
|
136
|
+
return this.callInto('financial_daily', req);
|
|
137
|
+
}
|
|
138
|
+
async getFinancialReport(req) {
|
|
139
|
+
return this.callInto('financial_report', req);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Corporate actions. Server returns {symbol: [...]}, this method flattens into a single list.
|
|
143
|
+
*/
|
|
144
|
+
async getCorporateAction(req) {
|
|
145
|
+
const grouped = await this.callInto('corporate_action', req);
|
|
146
|
+
if (!grouped || typeof grouped !== 'object')
|
|
147
|
+
return [];
|
|
148
|
+
return Object.values(grouped).flat();
|
|
149
|
+
}
|
|
150
|
+
// === Capital flow ===
|
|
151
|
+
async getCapitalFlow(symbol, market, period) {
|
|
152
|
+
return this.callInto('capital_flow', { symbol, market, period });
|
|
153
|
+
}
|
|
154
|
+
async getCapitalDistribution(symbol, market) {
|
|
155
|
+
return this.callInto('capital_distribution', { symbol, market });
|
|
156
|
+
}
|
|
157
|
+
// === Scanner & permission ===
|
|
158
|
+
async marketScanner(req) {
|
|
159
|
+
return this.callInto('market_scanner', req);
|
|
160
|
+
}
|
|
106
161
|
async grabQuotePermission() {
|
|
107
|
-
return this.
|
|
162
|
+
return this.callInto('grab_quote_permission');
|
|
163
|
+
}
|
|
164
|
+
// ==========================================================================
|
|
165
|
+
// Batch 3: stock basics + time series
|
|
166
|
+
// ==========================================================================
|
|
167
|
+
/** All symbol codes (string list). wire: all_symbols */
|
|
168
|
+
async getSymbols(req) {
|
|
169
|
+
return this.callInto('all_symbols', req);
|
|
170
|
+
}
|
|
171
|
+
/** All symbols with names. wire: all_symbol_names */
|
|
172
|
+
async getSymbolNames(req) {
|
|
173
|
+
return this.callInto('all_symbol_names', req);
|
|
174
|
+
}
|
|
175
|
+
/** Trade meta (lot size / tick size). wire: quote_stock_trade */
|
|
176
|
+
async getTradeMetas(req) {
|
|
177
|
+
return this.callInto('quote_stock_trade', req);
|
|
178
|
+
}
|
|
179
|
+
/** Stock details. wire: stock_detail. Server returns {items:[...]}. */
|
|
180
|
+
async getStockDetails(req) {
|
|
181
|
+
return this.callIntoItems('stock_detail', req);
|
|
182
|
+
}
|
|
183
|
+
/** Delayed stock briefs. wire: quote_delay */
|
|
184
|
+
async getStockDelayBriefs(req) {
|
|
185
|
+
return this.callInto('quote_delay', req);
|
|
186
|
+
}
|
|
187
|
+
/** K-line bars (full request). wire: kline */
|
|
188
|
+
async getBars(req) {
|
|
189
|
+
return this.callInto('kline', req);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Client-side paginated K-line fetch — loops over getBars until TotalSize
|
|
193
|
+
* bars are collected. Items are returned oldest-first, matching
|
|
194
|
+
* Python/Go get_bars_by_page behaviour.
|
|
195
|
+
*/
|
|
196
|
+
async getBarsByPage(req) {
|
|
197
|
+
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
198
|
+
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
199
|
+
let beginTime = req.beginTime ?? -1;
|
|
200
|
+
let endTime = req.endTime ?? -1;
|
|
201
|
+
if (beginTime === 0)
|
|
202
|
+
beginTime = -1;
|
|
203
|
+
if (endTime === 0)
|
|
204
|
+
endTime = -1;
|
|
205
|
+
const acc = [];
|
|
206
|
+
while (acc.length < totalSize) {
|
|
207
|
+
const sub = {
|
|
208
|
+
symbols: req.symbol ? [req.symbol] : undefined,
|
|
209
|
+
period: req.period,
|
|
210
|
+
right: req.right,
|
|
211
|
+
beginTime,
|
|
212
|
+
endTime,
|
|
213
|
+
limit: pageSize,
|
|
214
|
+
tradeSession: req.tradeSession,
|
|
215
|
+
lang: req.lang,
|
|
216
|
+
};
|
|
217
|
+
const pageOut = await this.callInto('kline', sub);
|
|
218
|
+
if (!pageOut || pageOut.length === 0 || !pageOut[0].items || pageOut[0].items.length === 0) {
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
const items = pageOut[0].items;
|
|
222
|
+
acc.push(...items);
|
|
223
|
+
if (items.length < pageSize)
|
|
224
|
+
break;
|
|
225
|
+
// next page endTime = oldest bar time - 1
|
|
226
|
+
let oldest = items[0].time;
|
|
227
|
+
for (const it of items) {
|
|
228
|
+
if (it.time < oldest)
|
|
229
|
+
oldest = it.time;
|
|
230
|
+
}
|
|
231
|
+
endTime = oldest - 1;
|
|
232
|
+
}
|
|
233
|
+
return acc;
|
|
234
|
+
}
|
|
235
|
+
/** Historical intraday timeline. wire: history_timeline */
|
|
236
|
+
async getTimelineHistory(req) {
|
|
237
|
+
return this.callInto('history_timeline', req);
|
|
238
|
+
}
|
|
239
|
+
/** Trade rank (top movers / volume). wire: trade_rank */
|
|
240
|
+
async getTradeRank(req) {
|
|
241
|
+
return this.callInto('trade_rank', req);
|
|
242
|
+
}
|
|
243
|
+
/** Short interest / shortable. wire: quote_shortable_stocks */
|
|
244
|
+
async getShortInterest(req) {
|
|
245
|
+
return this.callInto('quote_shortable_stocks', req);
|
|
246
|
+
}
|
|
247
|
+
/** Broker queue. wire: stock_broker */
|
|
248
|
+
async getStockBroker(req) {
|
|
249
|
+
return this.callInto('stock_broker', req);
|
|
250
|
+
}
|
|
251
|
+
/** Stock fundamentals (server returns grouped map). wire: stock_fundamental */
|
|
252
|
+
async getStockFundamental(req) {
|
|
253
|
+
const out = await this.callInto('stock_fundamental', req);
|
|
254
|
+
return out ?? {};
|
|
255
|
+
}
|
|
256
|
+
/** Stock industry classification (array). wire: stock_industry */
|
|
257
|
+
async getStockIndustry(req) {
|
|
258
|
+
return this.callInto('stock_industry', req);
|
|
259
|
+
}
|
|
260
|
+
/** Quote permission detail. wire: get_quote_permission */
|
|
261
|
+
async getQuotePermission(req) {
|
|
262
|
+
return this.callInto('get_quote_permission', req);
|
|
263
|
+
}
|
|
264
|
+
/** K-line quota usage. wire: kline_quota */
|
|
265
|
+
async getKlineQuota(req) {
|
|
266
|
+
return this.callInto('kline_quota', req);
|
|
267
|
+
}
|
|
268
|
+
// ==========================================================================
|
|
269
|
+
// Batch 4: option / future extensions
|
|
270
|
+
// ==========================================================================
|
|
271
|
+
/** Option K-line. wire: option_kline (v2.0) */
|
|
272
|
+
async getOptionBars(req) {
|
|
273
|
+
return this.callInto('option_kline', req, '2.0');
|
|
274
|
+
}
|
|
275
|
+
/** Option tick trades. wire: option_trade_tick */
|
|
276
|
+
async getOptionTradeTicks(req) {
|
|
277
|
+
return this.callInto('option_trade_tick', req);
|
|
278
|
+
}
|
|
279
|
+
/** Option intraday timeline. wire: option_timeline */
|
|
280
|
+
async getOptionTimeline(req) {
|
|
281
|
+
return this.callInto('option_timeline', req);
|
|
282
|
+
}
|
|
283
|
+
/** Option depth. wire: option_depth */
|
|
284
|
+
async getOptionDepth(req) {
|
|
285
|
+
return this.callInto('option_depth', req);
|
|
286
|
+
}
|
|
287
|
+
/** Available option symbols. wire: option_symbol */
|
|
288
|
+
async getOptionSymbols(req) {
|
|
289
|
+
return this.callInto('option_symbol', req);
|
|
290
|
+
}
|
|
291
|
+
/** Option analysis (volatility). wire: option_analysis */
|
|
292
|
+
async getOptionAnalysis(req) {
|
|
293
|
+
return this.callInto('option_analysis', req);
|
|
294
|
+
}
|
|
295
|
+
/** Single futures contract by code. wire: future_contract_by_contract_code */
|
|
296
|
+
async getFutureContract(req) {
|
|
297
|
+
return this.callIntoListOrObject('future_contract_by_contract_code', req);
|
|
298
|
+
}
|
|
299
|
+
/** All futures contracts. wire: future_contracts */
|
|
300
|
+
async getAllFutureContracts(req) {
|
|
301
|
+
return this.callInto('future_contracts', req);
|
|
302
|
+
}
|
|
303
|
+
/** Current main contract. wire: future_current_contract */
|
|
304
|
+
async getCurrentFutureContract(req) {
|
|
305
|
+
return this.callInto('future_current_contract', req);
|
|
306
|
+
}
|
|
307
|
+
/** Continuous main contracts. wire: future_continuous_contracts */
|
|
308
|
+
async getFutureContinuousContracts(req) {
|
|
309
|
+
return this.callIntoListOrObject('future_continuous_contracts', req);
|
|
310
|
+
}
|
|
311
|
+
/** Historical main contracts. wire: future_main_contract */
|
|
312
|
+
async getFutureHistoryMainContract(req) {
|
|
313
|
+
return this.callInto('future_main_contract', req);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Futures K-line (full request with index pagination). wire: future_kline
|
|
317
|
+
* begin_time / end_time default to -1 when unset (server requires them present).
|
|
318
|
+
*/
|
|
319
|
+
async getFutureBars(req) {
|
|
320
|
+
const body = {
|
|
321
|
+
...req,
|
|
322
|
+
beginTime: req.beginTime ?? -1,
|
|
323
|
+
endTime: req.endTime ?? -1,
|
|
324
|
+
};
|
|
325
|
+
return this.callInto('future_kline', body);
|
|
326
|
+
}
|
|
327
|
+
/** Client-side paginated futures K-line fetch. */
|
|
328
|
+
async getFutureBarsByPage(req) {
|
|
329
|
+
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
330
|
+
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
331
|
+
let beginTime = req.beginTime ?? -1;
|
|
332
|
+
let endTime = req.endTime ?? -1;
|
|
333
|
+
if (beginTime === 0)
|
|
334
|
+
beginTime = -1;
|
|
335
|
+
if (endTime === 0)
|
|
336
|
+
endTime = -1;
|
|
337
|
+
const acc = [];
|
|
338
|
+
while (acc.length < totalSize) {
|
|
339
|
+
const sub = {
|
|
340
|
+
contractCode: req.contractCode,
|
|
341
|
+
period: req.period,
|
|
342
|
+
beginTime,
|
|
343
|
+
endTime,
|
|
344
|
+
limit: pageSize,
|
|
345
|
+
lang: req.lang,
|
|
346
|
+
};
|
|
347
|
+
const pageOut = await this.callInto('future_kline', sub);
|
|
348
|
+
if (!pageOut || pageOut.length === 0 || !pageOut[0].items || pageOut[0].items.length === 0) {
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
const items = pageOut[0].items;
|
|
352
|
+
acc.push(...items);
|
|
353
|
+
if (items.length < pageSize)
|
|
354
|
+
break;
|
|
355
|
+
let oldest = items[0].time;
|
|
356
|
+
for (const it of items) {
|
|
357
|
+
if (it.time < oldest)
|
|
358
|
+
oldest = it.time;
|
|
359
|
+
}
|
|
360
|
+
endTime = oldest - 1;
|
|
361
|
+
}
|
|
362
|
+
return acc;
|
|
363
|
+
}
|
|
364
|
+
/** Futures tick trades. wire: future_tick (API v3.0) */
|
|
365
|
+
async getFutureTradeTicks(req) {
|
|
366
|
+
return this.callInto('future_tick', req, '3.0');
|
|
367
|
+
}
|
|
368
|
+
/** Futures depth. wire: future_depth */
|
|
369
|
+
async getFutureDepth(req) {
|
|
370
|
+
return this.callInto('future_depth', req);
|
|
371
|
+
}
|
|
372
|
+
/** Futures trading times (single-object response). wire: future_trading_date */
|
|
373
|
+
async getFutureTradingTimes(req) {
|
|
374
|
+
return this.callInto('future_trading_date', req);
|
|
375
|
+
}
|
|
376
|
+
// ==========================================================================
|
|
377
|
+
// Batch 5: fund / warrant / industry / corporate / financial / calendar
|
|
378
|
+
// ==========================================================================
|
|
379
|
+
/** Fund symbols. wire: fund_all_symbols */
|
|
380
|
+
async getFundSymbols(req) {
|
|
381
|
+
return this.callInto('fund_all_symbols', req);
|
|
382
|
+
}
|
|
383
|
+
/** Fund contracts. wire: fund_contracts */
|
|
384
|
+
async getFundContracts(req) {
|
|
385
|
+
return this.callInto('fund_contracts', req);
|
|
386
|
+
}
|
|
387
|
+
/** Fund real-time NAV. wire: fund_quote */
|
|
388
|
+
async getFundQuote(req) {
|
|
389
|
+
return this.callInto('fund_quote', req);
|
|
390
|
+
}
|
|
391
|
+
/** Fund historical NAV. wire: fund_history_quote */
|
|
392
|
+
async getFundHistoryQuote(req) {
|
|
393
|
+
return this.callInto('fund_history_quote', req);
|
|
394
|
+
}
|
|
395
|
+
/** Warrant briefs. wire: warrant_briefs */
|
|
396
|
+
async getWarrantBriefs(req) {
|
|
397
|
+
return this.callInto('warrant_briefs', req);
|
|
398
|
+
}
|
|
399
|
+
/** Warrant filter (paged). wire: warrant_filter */
|
|
400
|
+
async getWarrantFilter(req) {
|
|
401
|
+
return this.callInto('warrant_filter', req);
|
|
402
|
+
}
|
|
403
|
+
/** Industry list. wire: industry_list */
|
|
404
|
+
async getIndustryList(req) {
|
|
405
|
+
return this.callInto('industry_list', req);
|
|
406
|
+
}
|
|
407
|
+
/** Stocks inside an industry. wire: industry_stock_list */
|
|
408
|
+
async getIndustryStocks(req) {
|
|
409
|
+
return this.callInto('industry_stock_list', req);
|
|
410
|
+
}
|
|
411
|
+
/** Corporate split (flattened). wire: corporate_action (action_type=split) */
|
|
412
|
+
async getCorporateSplit(req) {
|
|
413
|
+
const body = { ...req, actionType: 'split' };
|
|
414
|
+
const grouped = await this.callInto('corporate_action', body);
|
|
415
|
+
if (!grouped || typeof grouped !== 'object')
|
|
416
|
+
return [];
|
|
417
|
+
return Object.values(grouped).flat();
|
|
418
|
+
}
|
|
419
|
+
/** Corporate dividend (flattened). wire: corporate_action (action_type=dividend) */
|
|
420
|
+
async getCorporateDividend(req) {
|
|
421
|
+
const body = { ...req, actionType: 'dividend' };
|
|
422
|
+
const grouped = await this.callInto('corporate_action', body);
|
|
423
|
+
if (!grouped || typeof grouped !== 'object')
|
|
424
|
+
return [];
|
|
425
|
+
return Object.values(grouped).flat();
|
|
426
|
+
}
|
|
427
|
+
/** Corporate earnings calendar (flattened). wire: corporate_action (action_type=earning) */
|
|
428
|
+
async getCorporateEarningsCalendar(req) {
|
|
429
|
+
const body = { ...req, actionType: 'earning' };
|
|
430
|
+
const grouped = await this.callInto('corporate_action', body);
|
|
431
|
+
if (!grouped || typeof grouped !== 'object')
|
|
432
|
+
return [];
|
|
433
|
+
return Object.values(grouped).flat();
|
|
434
|
+
}
|
|
435
|
+
/** Financial currency per symbol. wire: financial_currency */
|
|
436
|
+
async getFinancialCurrency(req) {
|
|
437
|
+
return this.callInto('financial_currency', req);
|
|
438
|
+
}
|
|
439
|
+
/** FX rates. wire: financial_exchange_rate */
|
|
440
|
+
async getFinancialExchangeRate(req) {
|
|
441
|
+
return this.callInto('financial_exchange_rate', req);
|
|
442
|
+
}
|
|
443
|
+
/** Trading calendar. wire: trading_calendar */
|
|
444
|
+
async getTradingCalendar(req) {
|
|
445
|
+
return this.callInto('trading_calendar', req);
|
|
446
|
+
}
|
|
447
|
+
/** Available market-scanner tags. wire: market_scanner_tags */
|
|
448
|
+
async getMarketScannerTags(req) {
|
|
449
|
+
return this.callInto('market_scanner_tags', req);
|
|
450
|
+
}
|
|
451
|
+
/** Overnight quote. wire: quote_overnight */
|
|
452
|
+
async getQuoteOvernight(req) {
|
|
453
|
+
return this.callInto('quote_overnight', req);
|
|
108
454
|
}
|
|
109
455
|
}
|
|
110
456
|
exports.QuoteClient = QuoteClient;
|
|
@@ -78,16 +78,16 @@ function signWithRSA(privateKeyStr, content) {
|
|
|
78
78
|
return sign.sign(key, 'base64');
|
|
79
79
|
}
|
|
80
80
|
/**
|
|
81
|
-
*
|
|
81
|
+
* Verify a SHA1WithRSA signature using an RSA public key.
|
|
82
82
|
*
|
|
83
|
-
* @param
|
|
84
|
-
* @param content -
|
|
85
|
-
* @param
|
|
86
|
-
* @returns
|
|
83
|
+
* @param publicKeyBase64 - Base64-encoded public key (DER / PKCS#1 or SPKI)
|
|
84
|
+
* @param content - Original content that was signed
|
|
85
|
+
* @param signatureBase64 - Base64-encoded signature
|
|
86
|
+
* @returns Whether the signature is valid
|
|
87
87
|
*/
|
|
88
|
-
function verifyWithRSA(
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return
|
|
88
|
+
function verifyWithRSA(publicKeyBase64, content, signatureBase64) {
|
|
89
|
+
const pem = `-----BEGIN PUBLIC KEY-----\n${publicKeyBase64}\n-----END PUBLIC KEY-----`;
|
|
90
|
+
const verifier = (0, crypto_1.createVerify)('SHA1');
|
|
91
|
+
verifier.update(content);
|
|
92
|
+
return verifier.verify(pem, signatureBase64, 'base64');
|
|
93
93
|
}
|