@tigeropenapi/tigeropen 0.4.7 → 0.4.8
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/dist/cjs/client/http-client.js +2 -3
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/push/push-client.js +2 -1
- package/dist/cjs/quote/quote-client.js +40 -48
- package/dist/cjs/trade/trade-client.js +14 -0
- package/dist/cjs/version.js +4 -0
- package/dist/esm/client/http-client.js +1 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/push/push-client.js +2 -1
- package/dist/esm/quote/quote-client.js +40 -48
- package/dist/esm/trade/trade-client.js +14 -0
- package/dist/esm/version.js +1 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/model/quote-requests.d.ts +6 -13
- package/dist/types/quote/quote-client.d.ts +17 -26
- package/dist/types/trade/trade-client.d.ts +4 -1
- package/dist/types/version.d.ts +1 -0
- package/package.json +1 -1
|
@@ -7,10 +7,9 @@ const signer_1 = require("../signer/signer");
|
|
|
7
7
|
const errors_1 = require("./errors");
|
|
8
8
|
const retry_1 = require("./retry");
|
|
9
9
|
const api_response_1 = require("./api-response");
|
|
10
|
-
|
|
11
|
-
const SDK_VERSION = '0.4.0';
|
|
10
|
+
const version_1 = require("../version");
|
|
12
11
|
/** User-Agent 字符串 */
|
|
13
|
-
const USER_AGENT = `openapi-typescript-sdk-${SDK_VERSION}`;
|
|
12
|
+
const USER_AGENT = `openapi-typescript-sdk-${version_1.SDK_VERSION}`;
|
|
14
13
|
/** 默认字符集 */
|
|
15
14
|
const DEFAULT_CHARSET = 'UTF-8';
|
|
16
15
|
/** 默认签名类型 */
|
package/dist/cjs/index.js
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.orderStatusCode = exports.BarPeriod = exports.License = exports.Language = exports.FinancialReportPeriod = exports.OptionAnalysisPeriod = exports.SortDirection = exports.IndustryLevel = exports.CorporateActionType = exports.OrderSortBy = exports.SegmentType = exports.QuoteRight = exports.Currency = exports.Market = exports.TimeInForce = exports.OrderType = exports.SecurityType = exports.OrderStatus = exports.normalizeOrderStatus = exports.stopLimitOrder = exports.stopOrder = exports.limitOrder = exports.marketOrder = exports.SubjectType = exports.ConnectionState = exports.PushClient = exports.TradeClient = exports.parseOptionIdentifier = exports.QuoteClient = exports.classifyErrorCode = exports.TigerError = exports.HttpClient = exports.TokenManager = exports.loadPropertiesFile = exports.createClientConfig = exports.VERSION = void 0;
|
|
20
20
|
/** SDK 版本号 */
|
|
21
|
-
|
|
21
|
+
var version_1 = require("./version");
|
|
22
|
+
Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.SDK_VERSION; } });
|
|
22
23
|
// Config
|
|
23
24
|
var config_1 = require("./config");
|
|
24
25
|
Object.defineProperty(exports, "createClientConfig", { enumerable: true, get: function () { return config_1.createClientConfig; } });
|
|
@@ -64,8 +64,9 @@ const DEFAULT_RECONNECT_INTERVAL = 5000;
|
|
|
64
64
|
const MAX_RECONNECT_INTERVAL = 60000;
|
|
65
65
|
/** Default connect timeout (ms) */
|
|
66
66
|
const DEFAULT_CONNECT_TIMEOUT = 30000;
|
|
67
|
+
const version_1 = require("../version");
|
|
67
68
|
/** SDK version identifier */
|
|
68
|
-
const SDK_VERSION =
|
|
69
|
+
const SDK_VERSION = `typescript/${version_1.SDK_VERSION}`;
|
|
69
70
|
/** Protocol version */
|
|
70
71
|
const ACCEPT_VERSION = '1.0';
|
|
71
72
|
/** Default send heartbeat interval (ms) */
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.QuoteClient = void 0;
|
|
4
4
|
exports.parseOptionIdentifier = parseOptionIdentifier;
|
|
5
|
+
/**
|
|
6
|
+
* QuoteClient — market-data client.
|
|
7
|
+
*
|
|
8
|
+
* All methods return strongly-typed responses from the `model` package.
|
|
9
|
+
* Request parameters are written in camelCase in TypeScript and are
|
|
10
|
+
* converted to snake_case on the wire automatically.
|
|
11
|
+
*/
|
|
12
|
+
const http_client_1 = require("../client/http-client");
|
|
5
13
|
const api_request_1 = require("../client/api-request");
|
|
6
14
|
const api_response_1 = require("../client/api-response");
|
|
7
15
|
/**
|
|
@@ -40,6 +48,10 @@ class QuoteClient {
|
|
|
40
48
|
constructor(httpClient) {
|
|
41
49
|
this.httpClient = httpClient;
|
|
42
50
|
}
|
|
51
|
+
/** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
52
|
+
static fromConfig(config) {
|
|
53
|
+
return new QuoteClient(new http_client_1.HttpClient(config, undefined, { useQuoteServerUrl: true }));
|
|
54
|
+
}
|
|
43
55
|
async callInto(method, bizParams, version) {
|
|
44
56
|
const request = (0, api_request_1.createApiRequest)(method, bizParams, version);
|
|
45
57
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -71,8 +83,8 @@ class QuoteClient {
|
|
|
71
83
|
async getBrief(req) {
|
|
72
84
|
return this.callInto('quote_real_time', req);
|
|
73
85
|
}
|
|
74
|
-
async getKline(
|
|
75
|
-
return this.callInto('kline',
|
|
86
|
+
async getKline(req) {
|
|
87
|
+
return this.callInto('kline', req);
|
|
76
88
|
}
|
|
77
89
|
async getTimeline(symbols) {
|
|
78
90
|
return this.callInto('timeline', { symbols });
|
|
@@ -86,17 +98,20 @@ class QuoteClient {
|
|
|
86
98
|
return this.callInto('quote_depth', req);
|
|
87
99
|
}
|
|
88
100
|
// === Options ===
|
|
89
|
-
async getOptionExpiration(
|
|
90
|
-
return this.callInto('option_expiration', { symbols
|
|
91
|
-
}
|
|
92
|
-
/** Option chain;
|
|
93
|
-
async getOptionChain(
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
async getOptionExpiration(symbols) {
|
|
102
|
+
return this.callInto('option_expiration', { symbols });
|
|
103
|
+
}
|
|
104
|
+
/** Option chain; each item is [symbol, "YYYY-MM-DD"]. */
|
|
105
|
+
async getOptionChain(items) {
|
|
106
|
+
const optionBasic = items.map(([symbol, expiry]) => {
|
|
107
|
+
const d = new Date(expiry + 'T00:00:00Z');
|
|
108
|
+
const expiryMs = d.getTime();
|
|
109
|
+
if (Number.isNaN(expiryMs)) {
|
|
110
|
+
throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
|
|
111
|
+
}
|
|
112
|
+
return { symbol, expiry: expiryMs };
|
|
113
|
+
});
|
|
114
|
+
return this.callInto('option_chain', { option_basic: optionBasic }, '3.0');
|
|
100
115
|
}
|
|
101
116
|
async getOptionBrief(identifiers) {
|
|
102
117
|
const optionBasic = identifiers.map((id) => {
|
|
@@ -105,11 +120,12 @@ class QuoteClient {
|
|
|
105
120
|
});
|
|
106
121
|
return this.callInto('option_brief', { option_basic: optionBasic }, '2.0');
|
|
107
122
|
}
|
|
108
|
-
async getOptionKline(
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
123
|
+
async getOptionKline(identifiers, period) {
|
|
124
|
+
const optionQuery = identifiers.map((id) => {
|
|
125
|
+
const p = parseOptionIdentifier(id);
|
|
126
|
+
return { symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike, period };
|
|
127
|
+
});
|
|
128
|
+
return this.callInto('option_kline', { option_query: optionQuery }, '2.0');
|
|
113
129
|
}
|
|
114
130
|
// === Futures ===
|
|
115
131
|
async getFutureExchange() {
|
|
@@ -122,15 +138,6 @@ class QuoteClient {
|
|
|
122
138
|
async getFutureRealTimeQuote(req) {
|
|
123
139
|
return this.callInto('future_real_time_quote', req);
|
|
124
140
|
}
|
|
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
141
|
// === Fundamentals ===
|
|
135
142
|
async getFinancialDaily(req) {
|
|
136
143
|
return this.callInto('financial_daily', req);
|
|
@@ -184,16 +191,8 @@ class QuoteClient {
|
|
|
184
191
|
async getStockDelayBriefs(req) {
|
|
185
192
|
return this.callInto('quote_delay', req);
|
|
186
193
|
}
|
|
187
|
-
/** K-line bars
|
|
188
|
-
async
|
|
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) {
|
|
194
|
+
/** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
|
|
195
|
+
async getKlineByPage(req) {
|
|
197
196
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
198
197
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
199
198
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -222,7 +221,6 @@ class QuoteClient {
|
|
|
222
221
|
acc.push(...items);
|
|
223
222
|
if (items.length < pageSize)
|
|
224
223
|
break;
|
|
225
|
-
// next page endTime = oldest bar time - 1
|
|
226
224
|
let oldest = items[0].time;
|
|
227
225
|
for (const it of items) {
|
|
228
226
|
if (it.time < oldest)
|
|
@@ -268,10 +266,6 @@ class QuoteClient {
|
|
|
268
266
|
// ==========================================================================
|
|
269
267
|
// Batch 4: option / future extensions
|
|
270
268
|
// ==========================================================================
|
|
271
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
272
|
-
async getOptionBars(req) {
|
|
273
|
-
return this.callInto('option_kline', req, '2.0');
|
|
274
|
-
}
|
|
275
269
|
/** Option tick trades. wire: option_trade_tick */
|
|
276
270
|
async getOptionTradeTicks(req) {
|
|
277
271
|
return this.callInto('option_trade_tick', req);
|
|
@@ -312,11 +306,9 @@ class QuoteClient {
|
|
|
312
306
|
async getFutureHistoryMainContract(req) {
|
|
313
307
|
return this.callInto('future_main_contract', req);
|
|
314
308
|
}
|
|
315
|
-
/**
|
|
316
|
-
*
|
|
317
|
-
|
|
318
|
-
*/
|
|
319
|
-
async getFutureBars(req) {
|
|
309
|
+
/** Futures K-line. wire: future_kline
|
|
310
|
+
* beginTime / endTime default to -1 when unset (server requires them present). */
|
|
311
|
+
async getFutureKline(req) {
|
|
320
312
|
const body = {
|
|
321
313
|
...req,
|
|
322
314
|
beginTime: req.beginTime ?? -1,
|
|
@@ -325,7 +317,7 @@ class QuoteClient {
|
|
|
325
317
|
return this.callInto('future_kline', body);
|
|
326
318
|
}
|
|
327
319
|
/** Client-side paginated futures K-line fetch. */
|
|
328
|
-
async
|
|
320
|
+
async getFutureKlineByPage(req) {
|
|
329
321
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
330
322
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
331
323
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TradeClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* TradeClient — trading client.
|
|
6
|
+
*
|
|
7
|
+
* All methods return strongly-typed responses; request parameters are
|
|
8
|
+
* written in camelCase in TypeScript and converted to snake_case on the wire.
|
|
9
|
+
*
|
|
10
|
+
* v0.4.0: 所有查询类方法改为 Request 对象签名(OrdersRequest 等),补齐 17
|
|
11
|
+
* 个新方法(账户管理 / 资产分析 / 资金调拨 / 持仓划转等)。
|
|
12
|
+
*/
|
|
13
|
+
const http_client_1 = require("../client/http-client");
|
|
4
14
|
const api_request_1 = require("../client/api-request");
|
|
5
15
|
const api_response_1 = require("../client/api-response");
|
|
6
16
|
const order_status_1 = require("../model/order-status");
|
|
@@ -30,6 +40,10 @@ class TradeClient {
|
|
|
30
40
|
this.account = account;
|
|
31
41
|
this.secretKey = secretKey;
|
|
32
42
|
}
|
|
43
|
+
/** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
44
|
+
static fromConfig(config, account, secretKey) {
|
|
45
|
+
return new TradeClient(new http_client_1.HttpClient(config), account, secretKey);
|
|
46
|
+
}
|
|
33
47
|
async callInto(method, bizParams) {
|
|
34
48
|
const request = (0, api_request_1.createApiRequest)(method, bizParams);
|
|
35
49
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -4,8 +4,7 @@ import { signWithRSA, verifyWithRSA } from '../signer/signer.js';
|
|
|
4
4
|
import { TigerError } from './errors.js';
|
|
5
5
|
import { defaultRetryPolicy } from './retry.js';
|
|
6
6
|
import { parseApiResponse, unmarshalData } from './api-response.js';
|
|
7
|
-
|
|
8
|
-
const SDK_VERSION = '0.4.0';
|
|
7
|
+
import { SDK_VERSION } from '../version.js';
|
|
9
8
|
/** User-Agent 字符串 */
|
|
10
9
|
const USER_AGENT = `openapi-typescript-sdk-${SDK_VERSION}`;
|
|
11
10
|
/** 默认字符集 */
|
package/dist/esm/index.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @packageDocumentation
|
|
16
16
|
*/
|
|
17
17
|
/** SDK 版本号 */
|
|
18
|
-
export
|
|
18
|
+
export { SDK_VERSION as VERSION } from './version.js';
|
|
19
19
|
// Config
|
|
20
20
|
export { createClientConfig, loadPropertiesFile } from './config/index.js';
|
|
21
21
|
export { TokenManager } from './config/index.js';
|
|
@@ -28,8 +28,9 @@ const DEFAULT_RECONNECT_INTERVAL = 5000;
|
|
|
28
28
|
const MAX_RECONNECT_INTERVAL = 60000;
|
|
29
29
|
/** Default connect timeout (ms) */
|
|
30
30
|
const DEFAULT_CONNECT_TIMEOUT = 30000;
|
|
31
|
+
import { SDK_VERSION as _SDK_VERSION } from '../version.js';
|
|
31
32
|
/** SDK version identifier */
|
|
32
|
-
const SDK_VERSION =
|
|
33
|
+
const SDK_VERSION = `typescript/${_SDK_VERSION}`;
|
|
33
34
|
/** Protocol version */
|
|
34
35
|
const ACCEPT_VERSION = '1.0';
|
|
35
36
|
/** Default send heartbeat interval (ms) */
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QuoteClient — market-data client.
|
|
3
|
+
*
|
|
4
|
+
* All methods return strongly-typed responses from the `model` package.
|
|
5
|
+
* Request parameters are written in camelCase in TypeScript and are
|
|
6
|
+
* converted to snake_case on the wire automatically.
|
|
7
|
+
*/
|
|
8
|
+
import { HttpClient } from '../client/http-client.js';
|
|
1
9
|
import { createApiRequest } from '../client/api-request.js';
|
|
2
10
|
import { unmarshalData } from '../client/api-response.js';
|
|
3
11
|
/**
|
|
@@ -36,6 +44,10 @@ export class QuoteClient {
|
|
|
36
44
|
constructor(httpClient) {
|
|
37
45
|
this.httpClient = httpClient;
|
|
38
46
|
}
|
|
47
|
+
/** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
48
|
+
static fromConfig(config) {
|
|
49
|
+
return new QuoteClient(new HttpClient(config, undefined, { useQuoteServerUrl: true }));
|
|
50
|
+
}
|
|
39
51
|
async callInto(method, bizParams, version) {
|
|
40
52
|
const request = createApiRequest(method, bizParams, version);
|
|
41
53
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -67,8 +79,8 @@ export class QuoteClient {
|
|
|
67
79
|
async getBrief(req) {
|
|
68
80
|
return this.callInto('quote_real_time', req);
|
|
69
81
|
}
|
|
70
|
-
async getKline(
|
|
71
|
-
return this.callInto('kline',
|
|
82
|
+
async getKline(req) {
|
|
83
|
+
return this.callInto('kline', req);
|
|
72
84
|
}
|
|
73
85
|
async getTimeline(symbols) {
|
|
74
86
|
return this.callInto('timeline', { symbols });
|
|
@@ -82,17 +94,20 @@ export class QuoteClient {
|
|
|
82
94
|
return this.callInto('quote_depth', req);
|
|
83
95
|
}
|
|
84
96
|
// === Options ===
|
|
85
|
-
async getOptionExpiration(
|
|
86
|
-
return this.callInto('option_expiration', { symbols
|
|
87
|
-
}
|
|
88
|
-
/** Option chain;
|
|
89
|
-
async getOptionChain(
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
async getOptionExpiration(symbols) {
|
|
98
|
+
return this.callInto('option_expiration', { symbols });
|
|
99
|
+
}
|
|
100
|
+
/** Option chain; each item is [symbol, "YYYY-MM-DD"]. */
|
|
101
|
+
async getOptionChain(items) {
|
|
102
|
+
const optionBasic = items.map(([symbol, expiry]) => {
|
|
103
|
+
const d = new Date(expiry + 'T00:00:00Z');
|
|
104
|
+
const expiryMs = d.getTime();
|
|
105
|
+
if (Number.isNaN(expiryMs)) {
|
|
106
|
+
throw new Error(`invalid expiry date, expected YYYY-MM-DD: ${expiry}`);
|
|
107
|
+
}
|
|
108
|
+
return { symbol, expiry: expiryMs };
|
|
109
|
+
});
|
|
110
|
+
return this.callInto('option_chain', { option_basic: optionBasic }, '3.0');
|
|
96
111
|
}
|
|
97
112
|
async getOptionBrief(identifiers) {
|
|
98
113
|
const optionBasic = identifiers.map((id) => {
|
|
@@ -101,11 +116,12 @@ export class QuoteClient {
|
|
|
101
116
|
});
|
|
102
117
|
return this.callInto('option_brief', { option_basic: optionBasic }, '2.0');
|
|
103
118
|
}
|
|
104
|
-
async getOptionKline(
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
119
|
+
async getOptionKline(identifiers, period) {
|
|
120
|
+
const optionQuery = identifiers.map((id) => {
|
|
121
|
+
const p = parseOptionIdentifier(id);
|
|
122
|
+
return { symbol: p.symbol, expiry: p.expiryMs, right: p.right, strike: p.strike, period };
|
|
123
|
+
});
|
|
124
|
+
return this.callInto('option_kline', { option_query: optionQuery }, '2.0');
|
|
109
125
|
}
|
|
110
126
|
// === Futures ===
|
|
111
127
|
async getFutureExchange() {
|
|
@@ -118,15 +134,6 @@ export class QuoteClient {
|
|
|
118
134
|
async getFutureRealTimeQuote(req) {
|
|
119
135
|
return this.callInto('future_real_time_quote', req);
|
|
120
136
|
}
|
|
121
|
-
/** Futures K-line; use -1 for unbounded beginTime / endTime. */
|
|
122
|
-
async getFutureKline(req) {
|
|
123
|
-
const body = {
|
|
124
|
-
...req,
|
|
125
|
-
beginTime: req.beginTime ?? -1,
|
|
126
|
-
endTime: req.endTime ?? -1,
|
|
127
|
-
};
|
|
128
|
-
return this.callInto('future_kline', body);
|
|
129
|
-
}
|
|
130
137
|
// === Fundamentals ===
|
|
131
138
|
async getFinancialDaily(req) {
|
|
132
139
|
return this.callInto('financial_daily', req);
|
|
@@ -180,16 +187,8 @@ export class QuoteClient {
|
|
|
180
187
|
async getStockDelayBriefs(req) {
|
|
181
188
|
return this.callInto('quote_delay', req);
|
|
182
189
|
}
|
|
183
|
-
/** K-line bars
|
|
184
|
-
async
|
|
185
|
-
return this.callInto('kline', req);
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Client-side paginated K-line fetch — loops over getBars until TotalSize
|
|
189
|
-
* bars are collected. Items are returned oldest-first, matching
|
|
190
|
-
* Python/Go get_bars_by_page behaviour.
|
|
191
|
-
*/
|
|
192
|
-
async getBarsByPage(req) {
|
|
190
|
+
/** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
|
|
191
|
+
async getKlineByPage(req) {
|
|
193
192
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
194
193
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
195
194
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -218,7 +217,6 @@ export class QuoteClient {
|
|
|
218
217
|
acc.push(...items);
|
|
219
218
|
if (items.length < pageSize)
|
|
220
219
|
break;
|
|
221
|
-
// next page endTime = oldest bar time - 1
|
|
222
220
|
let oldest = items[0].time;
|
|
223
221
|
for (const it of items) {
|
|
224
222
|
if (it.time < oldest)
|
|
@@ -264,10 +262,6 @@ export class QuoteClient {
|
|
|
264
262
|
// ==========================================================================
|
|
265
263
|
// Batch 4: option / future extensions
|
|
266
264
|
// ==========================================================================
|
|
267
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
268
|
-
async getOptionBars(req) {
|
|
269
|
-
return this.callInto('option_kline', req, '2.0');
|
|
270
|
-
}
|
|
271
265
|
/** Option tick trades. wire: option_trade_tick */
|
|
272
266
|
async getOptionTradeTicks(req) {
|
|
273
267
|
return this.callInto('option_trade_tick', req);
|
|
@@ -308,11 +302,9 @@ export class QuoteClient {
|
|
|
308
302
|
async getFutureHistoryMainContract(req) {
|
|
309
303
|
return this.callInto('future_main_contract', req);
|
|
310
304
|
}
|
|
311
|
-
/**
|
|
312
|
-
*
|
|
313
|
-
|
|
314
|
-
*/
|
|
315
|
-
async getFutureBars(req) {
|
|
305
|
+
/** Futures K-line. wire: future_kline
|
|
306
|
+
* beginTime / endTime default to -1 when unset (server requires them present). */
|
|
307
|
+
async getFutureKline(req) {
|
|
316
308
|
const body = {
|
|
317
309
|
...req,
|
|
318
310
|
beginTime: req.beginTime ?? -1,
|
|
@@ -321,7 +313,7 @@ export class QuoteClient {
|
|
|
321
313
|
return this.callInto('future_kline', body);
|
|
322
314
|
}
|
|
323
315
|
/** Client-side paginated futures K-line fetch. */
|
|
324
|
-
async
|
|
316
|
+
async getFutureKlineByPage(req) {
|
|
325
317
|
const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
|
|
326
318
|
const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
|
|
327
319
|
let beginTime = req.beginTime ?? -1;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TradeClient — trading client.
|
|
3
|
+
*
|
|
4
|
+
* All methods return strongly-typed responses; request parameters are
|
|
5
|
+
* written in camelCase in TypeScript and converted to snake_case on the wire.
|
|
6
|
+
*
|
|
7
|
+
* v0.4.0: 所有查询类方法改为 Request 对象签名(OrdersRequest 等),补齐 17
|
|
8
|
+
* 个新方法(账户管理 / 资产分析 / 资金调拨 / 持仓划转等)。
|
|
9
|
+
*/
|
|
10
|
+
import { HttpClient } from '../client/http-client.js';
|
|
1
11
|
import { createApiRequest } from '../client/api-request.js';
|
|
2
12
|
import { unmarshalData } from '../client/api-response.js';
|
|
3
13
|
import { normalizeOrderStatus } from '../model/order-status.js';
|
|
@@ -27,6 +37,10 @@ export class TradeClient {
|
|
|
27
37
|
this.account = account;
|
|
28
38
|
this.secretKey = secretKey;
|
|
29
39
|
}
|
|
40
|
+
/** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
41
|
+
static fromConfig(config, account, secretKey) {
|
|
42
|
+
return new TradeClient(new HttpClient(config), account, secretKey);
|
|
43
|
+
}
|
|
30
44
|
async callInto(method, bizParams) {
|
|
31
45
|
const request = createApiRequest(method, bizParams);
|
|
32
46
|
const response = await this.httpClient.executeRequest(request);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SDK_VERSION = '0.4.8';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @packageDocumentation
|
|
16
16
|
*/
|
|
17
17
|
/** SDK 版本号 */
|
|
18
|
-
export
|
|
18
|
+
export { SDK_VERSION as VERSION } from './version';
|
|
19
19
|
export { createClientConfig, loadPropertiesFile } from './config';
|
|
20
20
|
export type { ClientConfig, ClientConfigOptions } from './config';
|
|
21
21
|
export { TokenManager } from './config';
|
|
@@ -35,5 +35,5 @@ export type { Position } from './model/position';
|
|
|
35
35
|
export type { Asset, AssetSegment, PrimeAsset, PreviewResult, PlaceOrderResult, OrderIdResult, Transaction, ManagedAccount, AnalyticsAsset, AggregateAssets, EstimateTradableQuantity, ForexOrderResult, SegmentFund, SegmentFundAvailableItem, SegmentFundHistoryItem, FundDetails, FundingHistoryItem, PositionTransferRecord, PositionTransferDetail, PositionTransferExternalRecord, OptionExerciseCheckResult, OptionExercisePositionPageResult, OptionExerciseRecordPageResult, } from './model/trade';
|
|
36
36
|
export type { OrdersRequest, GetOrderRequest, OrderTransactionsRequest, PositionsRequest, AssetsRequest, ManagedAccountsRequest, DerivativeContractsRequest, AnalyticsAssetRequest, AggregateAssetsRequest, EstimateTradableQuantityRequest, ForexOrderRequest, SegmentFundRequest, FundDetailsRequest, FundingHistoryRequest, PositionTransferRequest, PositionTransferRecordsRequest, PositionTransferDetailRequest, PositionTransferExternalRecordsRequest, OptionExerciseCheckRequest, OptionExercisePositionRequest, OptionExerciseSubmitRequest, OptionExerciseRecordsRequest, OptionExerciseCancelRequest, } from './model/trade-requests';
|
|
37
37
|
export type { MarketState, Brief, Kline, KlineItem, Timeline, TimelineItem, TradeTick, TradeTickItem, Depth, DepthLevel, OptionExpiration, OptionChain, OptionChainRow, OptionSymbol, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FutureDepth, FutureTradeTickItem, FutureTradingTime, FinancialDailyItem, FinancialReportItem, CorporateAction, CapitalFlow, CapitalFlowItem, CapitalDistribution, ScannerResult, ScannerResultItem, QuotePermission, SymbolName, TradeMeta, StockDetail, StockBroker, StockBrokerItem, ShortInterest, StockIndustry, IndustryItem, IndustryStock, WarrantBrief, WarrantFilterResult, FundContractInfo, FundQuote, FundHistoryQuote, QuoteOvernight, KlineQuota, MarketScannerTag, MarketScannerTags, OptionAnalysis, OptionLeg, OptionVolatilityPoint, ExchangeRate, FinancialCurrency, BrokerDetail, TradingCalendarItem, FutureMainContractHistory, } from './model/quote';
|
|
38
|
-
export type { BriefRequest, DepthQuoteRequest, TradeTickRequest,
|
|
38
|
+
export type { BriefRequest, DepthQuoteRequest, TradeTickRequest, KlineRequest, KlineByPageRequest, FutureBriefRequest, FutureKlineRequest, FutureKlineByPageRequest, FutureTradeTicksRequest, FutureDepthRequest, FutureContractSingleRequest, FutureContinuousContractsRequest, FutureHistoryMainContractRequest, FutureTradingTimesRequest, AllFutureContractsRequest, OptionTradeTicksRequest, OptionTimelineRequest, OptionDepthRequest, OptionSymbolsRequest, OptionAnalysisRequest, OptionQueryItem, ShortInterestRequest, StockBrokerRequest, StockDetailsRequest, StockFundamentalRequest, StockIndustryRequest, StockDelayBriefsRequest, SymbolsRequest, TradeMetasRequest, TradeRankRequest, TimelineHistoryRequest, TradingCalendarRequest, KlineQuotaRequest, QuotePermissionRequest, QuoteOvernightRequest, IndustryListRequest, IndustryStocksRequest, FundSymbolsRequest, FundContractsRequest, FundQuoteRequest, FundHistoryQuoteRequest, WarrantBriefsRequest, WarrantFilterRequest, MarketScannerTagsRequest, FinancialCurrencyRequest, FinancialExchangeRateRequest, } from './model/quote-requests';
|
|
39
39
|
export { OrderStatus, SecurityType, OrderType, TimeInForce, Market, Currency, QuoteRight, SegmentType, OrderSortBy, CorporateActionType, IndustryLevel, SortDirection, OptionAnalysisPeriod, FinancialReportPeriod, Language, License, BarPeriod, orderStatusCode, } from './model/enums';
|
|
@@ -58,11 +58,10 @@ export interface StockDelayBriefsRequest {
|
|
|
58
58
|
secType?: string;
|
|
59
59
|
lang?: string;
|
|
60
60
|
}
|
|
61
|
-
/**
|
|
62
|
-
* K-line bars (full options). wire: kline
|
|
61
|
+
/** K-line request. wire: kline
|
|
63
62
|
* BeginTime/EndTime (ms) and BeginIndex/EndIndex are mutually exclusive.
|
|
64
63
|
*/
|
|
65
|
-
export interface
|
|
64
|
+
export interface KlineRequest {
|
|
66
65
|
symbols?: string[];
|
|
67
66
|
period?: string;
|
|
68
67
|
right?: string;
|
|
@@ -79,7 +78,7 @@ export interface BarsRequest {
|
|
|
79
78
|
lang?: string;
|
|
80
79
|
}
|
|
81
80
|
/** K-line client-side pagination wrapper. */
|
|
82
|
-
export interface
|
|
81
|
+
export interface KlineByPageRequest {
|
|
83
82
|
symbol?: string;
|
|
84
83
|
period?: string;
|
|
85
84
|
beginTime?: number;
|
|
@@ -155,12 +154,6 @@ export interface OptionQueryItem {
|
|
|
155
154
|
endIndex?: number;
|
|
156
155
|
pageToken?: string;
|
|
157
156
|
}
|
|
158
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
159
|
-
export interface OptionBarsRequest {
|
|
160
|
-
optionQuery?: OptionQueryItem[];
|
|
161
|
-
market?: string;
|
|
162
|
-
lang?: string;
|
|
163
|
-
}
|
|
164
157
|
/** Option tick trades. wire: option_trade_tick */
|
|
165
158
|
export interface OptionTradeTicksRequest {
|
|
166
159
|
contracts?: OptionQueryItem[];
|
|
@@ -215,8 +208,8 @@ export interface FutureHistoryMainContractRequest {
|
|
|
215
208
|
endTime?: number;
|
|
216
209
|
lang?: string;
|
|
217
210
|
}
|
|
218
|
-
/** Futures K-line
|
|
219
|
-
export interface
|
|
211
|
+
/** Futures K-line request. wire: future_kline */
|
|
212
|
+
export interface FutureKlineRequest {
|
|
220
213
|
contractCodes?: string[];
|
|
221
214
|
contractCode?: string;
|
|
222
215
|
period?: string;
|
|
@@ -229,7 +222,7 @@ export interface FutureBarsRequest {
|
|
|
229
222
|
lang?: string;
|
|
230
223
|
}
|
|
231
224
|
/** Futures K-line client-side pagination wrapper. */
|
|
232
|
-
export interface
|
|
225
|
+
export interface FutureKlineByPageRequest {
|
|
233
226
|
contractCode?: string;
|
|
234
227
|
period?: string;
|
|
235
228
|
beginTime?: number;
|
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* Request parameters are written in camelCase in TypeScript and are
|
|
6
6
|
* converted to snake_case on the wire automatically.
|
|
7
7
|
*/
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
10
|
-
import type {
|
|
8
|
+
import { HttpClient } from '../client/http-client';
|
|
9
|
+
import type { ClientConfig } from '../config/client-config';
|
|
10
|
+
import type { MarketState, Brief, Kline, KlineItem, Timeline, TradeTick, Depth, OptionExpiration, OptionChain, FutureExchange, FutureContractInfo, FutureQuote, FutureKline, FutureKlineItem, FinancialDailyItem, FinancialReportItem, CorporateAction, CapitalFlow, CapitalDistribution, ScannerResult, QuotePermission, MarketScannerRequest, SymbolName, TradeMeta, StockDetail, StockBroker, StockIndustry, TradeRankItem, ShortInterest, KlineQuota, OptionAnalysis, OptionSymbol, FutureMainContractHistory, FutureTradingTime, FutureTradeTickItem, FutureDepth, WarrantBrief, WarrantFilterResult, IndustryItem, IndustryStock, TradingCalendarItem, ExchangeRate, FinancialCurrency, QuoteOvernight, MarketScannerTags, FundContractInfo, FundQuote, FundHistoryQuote, FinancialDailyRequest, FinancialReportRequest, CorporateActionRequest } from '../model/quote';
|
|
11
|
+
import type { BriefRequest, DepthQuoteRequest, TradeTickRequest, FutureBriefRequest, SymbolsRequest, TradeMetasRequest, StockDetailsRequest, StockDelayBriefsRequest, KlineRequest, KlineByPageRequest, TimelineHistoryRequest, TradeRankRequest, ShortInterestRequest, StockBrokerRequest, StockFundamentalRequest, StockIndustryRequest, KlineQuotaRequest, QuotePermissionRequest, OptionTradeTicksRequest, OptionTimelineRequest, OptionDepthRequest, OptionSymbolsRequest, OptionAnalysisRequest, FutureContractSingleRequest, AllFutureContractsRequest, FutureContinuousContractsRequest, FutureHistoryMainContractRequest, FutureKlineRequest, FutureKlineByPageRequest, FutureTradeTicksRequest, FutureDepthRequest, FutureTradingTimesRequest, FundSymbolsRequest, FundContractsRequest, FundQuoteRequest, FundHistoryQuoteRequest, WarrantBriefsRequest, WarrantFilterRequest, IndustryListRequest, IndustryStocksRequest, TradingCalendarRequest, FinancialExchangeRateRequest, FinancialCurrencyRequest, MarketScannerTagsRequest, QuoteOvernightRequest } from '../model/quote-requests';
|
|
11
12
|
/**
|
|
12
13
|
* Parse an OCC-style option identifier like "AAPL 260619C00150000"
|
|
13
14
|
* into its component parts.
|
|
@@ -22,6 +23,8 @@ export declare function parseOptionIdentifier(identifier: string): {
|
|
|
22
23
|
export declare class QuoteClient {
|
|
23
24
|
private httpClient;
|
|
24
25
|
constructor(httpClient: HttpClient);
|
|
26
|
+
/** Create a QuoteClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
27
|
+
static fromConfig(config: ClientConfig): QuoteClient;
|
|
25
28
|
private callInto;
|
|
26
29
|
/**
|
|
27
30
|
* Some endpoints return either a list or a single object depending on the
|
|
@@ -34,23 +37,21 @@ export declare class QuoteClient {
|
|
|
34
37
|
getMarketState(market: string): Promise<MarketState[]>;
|
|
35
38
|
/** Real-time stock briefs. wire: quote_real_time */
|
|
36
39
|
getBrief(req: BriefRequest): Promise<Brief[]>;
|
|
37
|
-
getKline(
|
|
40
|
+
getKline(req: KlineRequest): Promise<Kline[]>;
|
|
38
41
|
getTimeline(symbols: string[]): Promise<Timeline[]>;
|
|
39
42
|
/** Tick-by-tick trades. wire: trade_tick */
|
|
40
43
|
getTradeTick(req: TradeTickRequest): Promise<TradeTick[]>;
|
|
41
44
|
/** Depth snapshot. wire: quote_depth */
|
|
42
45
|
getQuoteDepth(req: DepthQuoteRequest): Promise<Depth[]>;
|
|
43
|
-
getOptionExpiration(
|
|
44
|
-
/** Option chain;
|
|
45
|
-
getOptionChain(
|
|
46
|
+
getOptionExpiration(symbols: string[]): Promise<OptionExpiration[]>;
|
|
47
|
+
/** Option chain; each item is [symbol, "YYYY-MM-DD"]. */
|
|
48
|
+
getOptionChain(items: Array<[string, string]>): Promise<OptionChain[]>;
|
|
46
49
|
getOptionBrief(identifiers: string[]): Promise<Brief[]>;
|
|
47
|
-
getOptionKline(
|
|
50
|
+
getOptionKline(identifiers: string[], period: string): Promise<Kline[]>;
|
|
48
51
|
getFutureExchange(): Promise<FutureExchange[]>;
|
|
49
52
|
getFutureContracts(exchange: string): Promise<FutureContractInfo[]>;
|
|
50
53
|
/** Real-time futures quotes. wire: future_real_time_quote */
|
|
51
54
|
getFutureRealTimeQuote(req: FutureBriefRequest): Promise<FutureQuote[]>;
|
|
52
|
-
/** Futures K-line; use -1 for unbounded beginTime / endTime. */
|
|
53
|
-
getFutureKline(req: FutureKlineRequest): Promise<FutureKline[]>;
|
|
54
55
|
getFinancialDaily(req: FinancialDailyRequest): Promise<FinancialDailyItem[]>;
|
|
55
56
|
getFinancialReport(req: FinancialReportRequest): Promise<FinancialReportItem[]>;
|
|
56
57
|
/**
|
|
@@ -71,14 +72,8 @@ export declare class QuoteClient {
|
|
|
71
72
|
getStockDetails(req: StockDetailsRequest): Promise<StockDetail[]>;
|
|
72
73
|
/** Delayed stock briefs. wire: quote_delay */
|
|
73
74
|
getStockDelayBriefs(req: StockDelayBriefsRequest): Promise<Brief[]>;
|
|
74
|
-
/** K-line bars
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Client-side paginated K-line fetch — loops over getBars until TotalSize
|
|
78
|
-
* bars are collected. Items are returned oldest-first, matching
|
|
79
|
-
* Python/Go get_bars_by_page behaviour.
|
|
80
|
-
*/
|
|
81
|
-
getBarsByPage(req: BarsByPageRequest): Promise<KlineItem[]>;
|
|
75
|
+
/** Client-side paginated K-line fetch. Loops until totalSize bars are collected, oldest-first. */
|
|
76
|
+
getKlineByPage(req: KlineByPageRequest): Promise<KlineItem[]>;
|
|
82
77
|
/** Historical intraday timeline. wire: history_timeline */
|
|
83
78
|
getTimelineHistory(req: TimelineHistoryRequest): Promise<Timeline[]>;
|
|
84
79
|
/** Trade rank (top movers / volume). wire: trade_rank */
|
|
@@ -95,8 +90,6 @@ export declare class QuoteClient {
|
|
|
95
90
|
getQuotePermission(req: QuotePermissionRequest): Promise<QuotePermission[]>;
|
|
96
91
|
/** K-line quota usage. wire: kline_quota */
|
|
97
92
|
getKlineQuota(req: KlineQuotaRequest): Promise<KlineQuota[]>;
|
|
98
|
-
/** Option K-line. wire: option_kline (v2.0) */
|
|
99
|
-
getOptionBars(req: OptionBarsRequest): Promise<Kline[]>;
|
|
100
93
|
/** Option tick trades. wire: option_trade_tick */
|
|
101
94
|
getOptionTradeTicks(req: OptionTradeTicksRequest): Promise<TradeTick[]>;
|
|
102
95
|
/** Option intraday timeline. wire: option_timeline */
|
|
@@ -117,13 +110,11 @@ export declare class QuoteClient {
|
|
|
117
110
|
getFutureContinuousContracts(req: FutureContinuousContractsRequest): Promise<FutureContractInfo[]>;
|
|
118
111
|
/** Historical main contracts. wire: future_main_contract */
|
|
119
112
|
getFutureHistoryMainContract(req: FutureHistoryMainContractRequest): Promise<FutureMainContractHistory[]>;
|
|
120
|
-
/**
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
getFutureBars(req: FutureBarsRequest): Promise<FutureKline[]>;
|
|
113
|
+
/** Futures K-line. wire: future_kline
|
|
114
|
+
* beginTime / endTime default to -1 when unset (server requires them present). */
|
|
115
|
+
getFutureKline(req: FutureKlineRequest): Promise<FutureKline[]>;
|
|
125
116
|
/** Client-side paginated futures K-line fetch. */
|
|
126
|
-
|
|
117
|
+
getFutureKlineByPage(req: FutureKlineByPageRequest): Promise<FutureKlineItem[]>;
|
|
127
118
|
/** Futures tick trades. wire: future_tick (API v3.0)
|
|
128
119
|
* Server returns {contractCode, items:[...]}; unwrap items and backfill contractCode.
|
|
129
120
|
* endIndex defaults to 30 when not set (consistent with Python/Go SDK). */
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* v0.4.0: 所有查询类方法改为 Request 对象签名(OrdersRequest 等),补齐 17
|
|
8
8
|
* 个新方法(账户管理 / 资产分析 / 资金调拨 / 持仓划转等)。
|
|
9
9
|
*/
|
|
10
|
-
import
|
|
10
|
+
import { HttpClient } from '../client/http-client';
|
|
11
|
+
import type { ClientConfig } from '../config/client-config';
|
|
11
12
|
import type { OrderRequest, Order } from '../model/order';
|
|
12
13
|
import type { Contract } from '../model/contract';
|
|
13
14
|
import type { Position } from '../model/position';
|
|
@@ -19,6 +20,8 @@ export declare class TradeClient {
|
|
|
19
20
|
private account;
|
|
20
21
|
private secretKey?;
|
|
21
22
|
constructor(httpClient: HttpClient, account: string, secretKey?: string);
|
|
23
|
+
/** Create a TradeClient directly from a ClientConfig — no need to construct HttpClient manually. */
|
|
24
|
+
static fromConfig(config: ClientConfig, account: string, secretKey?: string): TradeClient;
|
|
22
25
|
private callInto;
|
|
23
26
|
/** Strip `{items: [...]}` envelope used by most trade read endpoints. */
|
|
24
27
|
private callIntoItems;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SDK_VERSION = "0.4.8";
|
package/package.json
CHANGED