@tigeropenapi/tigeropen 0.3.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.
Files changed (37) hide show
  1. package/dist/cjs/client/http-client.js +1 -1
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/model/enums.js +89 -7
  4. package/dist/cjs/model/order-status.js +46 -0
  5. package/dist/cjs/model/quote-requests.js +11 -0
  6. package/dist/cjs/model/trade-requests.js +13 -0
  7. package/dist/cjs/push/pb/OrderStatusData.js +24 -0
  8. package/dist/cjs/push/proto-message.js +6 -0
  9. package/dist/cjs/push/push-client.js +71 -1
  10. package/dist/cjs/push/push-message.js +4 -0
  11. package/dist/cjs/quote/quote-client.js +321 -9
  12. package/dist/cjs/trade/trade-client.js +166 -25
  13. package/dist/esm/client/http-client.js +1 -1
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/model/enums.js +87 -6
  16. package/dist/esm/model/order-status.js +43 -0
  17. package/dist/esm/model/quote-requests.js +10 -0
  18. package/dist/esm/model/trade-requests.js +12 -0
  19. package/dist/esm/push/pb/OrderStatusData.js +24 -0
  20. package/dist/esm/push/proto-message.js +6 -0
  21. package/dist/esm/push/push-client.js +71 -1
  22. package/dist/esm/push/push-message.js +4 -0
  23. package/dist/esm/quote/quote-client.js +321 -9
  24. package/dist/esm/trade/trade-client.js +166 -25
  25. package/dist/types/index.d.ts +1 -1
  26. package/dist/types/model/enums.d.ts +60 -6
  27. package/dist/types/model/order-status.d.ts +14 -0
  28. package/dist/types/model/quote-requests.d.ts +344 -0
  29. package/dist/types/model/quote.d.ts +261 -0
  30. package/dist/types/model/trade-requests.d.ts +195 -0
  31. package/dist/types/model/trade.d.ts +122 -0
  32. package/dist/types/push/pb/OrderStatusData.d.ts +4 -0
  33. package/dist/types/push/push-client.d.ts +31 -0
  34. package/dist/types/push/push-message.d.ts +4 -0
  35. package/dist/types/quote/quote-client.d.ts +119 -6
  36. package/dist/types/trade/trade-client.d.ts +84 -12
  37. package/package.json +1 -1
@@ -41,12 +41,31 @@ export class QuoteClient {
41
41
  const response = await this.httpClient.executeRequest(request);
42
42
  return unmarshalData(response.data);
43
43
  }
44
+ /**
45
+ * Some endpoints return either a list or a single object depending on the
46
+ * server response shape (future_contract_by_contract_code /
47
+ * future_continuous_contracts). Unify into an array.
48
+ */
49
+ async callIntoListOrObject(method, bizParams, version) {
50
+ const raw = await this.callInto(method, bizParams, version);
51
+ if (raw == null)
52
+ return [];
53
+ if (Array.isArray(raw))
54
+ return raw;
55
+ return [raw];
56
+ }
57
+ /** Unwrap server {"items":[...]} envelope. */
58
+ async callIntoItems(method, bizParams, version) {
59
+ const wrap = await this.callInto(method, bizParams, version);
60
+ return wrap?.items ?? [];
61
+ }
44
62
  // === Basic market data ===
45
63
  async getMarketState(market) {
46
64
  return this.callInto('market_state', { market });
47
65
  }
48
- async getBrief(symbols) {
49
- return this.callInto('quote_real_time', { symbols });
66
+ /** Real-time stock briefs. wire: quote_real_time */
67
+ async getBrief(req) {
68
+ return this.callInto('quote_real_time', req);
50
69
  }
51
70
  async getKline(symbol, period) {
52
71
  return this.callInto('kline', { symbols: [symbol], period });
@@ -54,12 +73,13 @@ export class QuoteClient {
54
73
  async getTimeline(symbols) {
55
74
  return this.callInto('timeline', { symbols });
56
75
  }
57
- async getTradeTick(symbols) {
58
- return this.callInto('trade_tick', { symbols });
76
+ /** Tick-by-tick trades. wire: trade_tick */
77
+ async getTradeTick(req) {
78
+ return this.callInto('trade_tick', req);
59
79
  }
60
- /** Depth snapshot. market is required (US / HK supported). */
61
- async getQuoteDepth(symbol, market) {
62
- return this.callInto('quote_depth', { symbols: [symbol], market });
80
+ /** Depth snapshot. wire: quote_depth */
81
+ async getQuoteDepth(req) {
82
+ return this.callInto('quote_depth', req);
63
83
  }
64
84
  // === Options ===
65
85
  async getOptionExpiration(symbol) {
@@ -94,8 +114,9 @@ export class QuoteClient {
94
114
  async getFutureContracts(exchange) {
95
115
  return this.callInto('future_contract_by_exchange_code', { exchangeCode: exchange });
96
116
  }
97
- async getFutureRealTimeQuote(contractCodes) {
98
- return this.callInto('future_real_time_quote', { contractCodes });
117
+ /** Real-time futures quotes. wire: future_real_time_quote */
118
+ async getFutureRealTimeQuote(req) {
119
+ return this.callInto('future_real_time_quote', req);
99
120
  }
100
121
  /** Futures K-line; use -1 for unbounded beginTime / endTime. */
101
122
  async getFutureKline(req) {
@@ -136,4 +157,295 @@ export class QuoteClient {
136
157
  async grabQuotePermission() {
137
158
  return this.callInto('grab_quote_permission');
138
159
  }
160
+ // ==========================================================================
161
+ // Batch 3: stock basics + time series
162
+ // ==========================================================================
163
+ /** All symbol codes (string list). wire: all_symbols */
164
+ async getSymbols(req) {
165
+ return this.callInto('all_symbols', req);
166
+ }
167
+ /** All symbols with names. wire: all_symbol_names */
168
+ async getSymbolNames(req) {
169
+ return this.callInto('all_symbol_names', req);
170
+ }
171
+ /** Trade meta (lot size / tick size). wire: quote_stock_trade */
172
+ async getTradeMetas(req) {
173
+ return this.callInto('quote_stock_trade', req);
174
+ }
175
+ /** Stock details. wire: stock_detail. Server returns {items:[...]}. */
176
+ async getStockDetails(req) {
177
+ return this.callIntoItems('stock_detail', req);
178
+ }
179
+ /** Delayed stock briefs. wire: quote_delay */
180
+ async getStockDelayBriefs(req) {
181
+ return this.callInto('quote_delay', req);
182
+ }
183
+ /** K-line bars (full request). wire: kline */
184
+ async getBars(req) {
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) {
193
+ const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
194
+ const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
195
+ let beginTime = req.beginTime ?? -1;
196
+ let endTime = req.endTime ?? -1;
197
+ if (beginTime === 0)
198
+ beginTime = -1;
199
+ if (endTime === 0)
200
+ endTime = -1;
201
+ const acc = [];
202
+ while (acc.length < totalSize) {
203
+ const sub = {
204
+ symbols: req.symbol ? [req.symbol] : undefined,
205
+ period: req.period,
206
+ right: req.right,
207
+ beginTime,
208
+ endTime,
209
+ limit: pageSize,
210
+ tradeSession: req.tradeSession,
211
+ lang: req.lang,
212
+ };
213
+ const pageOut = await this.callInto('kline', sub);
214
+ if (!pageOut || pageOut.length === 0 || !pageOut[0].items || pageOut[0].items.length === 0) {
215
+ break;
216
+ }
217
+ const items = pageOut[0].items;
218
+ acc.push(...items);
219
+ if (items.length < pageSize)
220
+ break;
221
+ // next page endTime = oldest bar time - 1
222
+ let oldest = items[0].time;
223
+ for (const it of items) {
224
+ if (it.time < oldest)
225
+ oldest = it.time;
226
+ }
227
+ endTime = oldest - 1;
228
+ }
229
+ return acc;
230
+ }
231
+ /** Historical intraday timeline. wire: history_timeline */
232
+ async getTimelineHistory(req) {
233
+ return this.callInto('history_timeline', req);
234
+ }
235
+ /** Trade rank (top movers / volume). wire: trade_rank */
236
+ async getTradeRank(req) {
237
+ return this.callInto('trade_rank', req);
238
+ }
239
+ /** Short interest / shortable. wire: quote_shortable_stocks */
240
+ async getShortInterest(req) {
241
+ return this.callInto('quote_shortable_stocks', req);
242
+ }
243
+ /** Broker queue. wire: stock_broker */
244
+ async getStockBroker(req) {
245
+ return this.callInto('stock_broker', req);
246
+ }
247
+ /** Stock fundamentals (server returns grouped map). wire: stock_fundamental */
248
+ async getStockFundamental(req) {
249
+ const out = await this.callInto('stock_fundamental', req);
250
+ return out ?? {};
251
+ }
252
+ /** Stock industry classification (array). wire: stock_industry */
253
+ async getStockIndustry(req) {
254
+ return this.callInto('stock_industry', req);
255
+ }
256
+ /** Quote permission detail. wire: get_quote_permission */
257
+ async getQuotePermission(req) {
258
+ return this.callInto('get_quote_permission', req);
259
+ }
260
+ /** K-line quota usage. wire: kline_quota */
261
+ async getKlineQuota(req) {
262
+ return this.callInto('kline_quota', req);
263
+ }
264
+ // ==========================================================================
265
+ // Batch 4: option / future extensions
266
+ // ==========================================================================
267
+ /** Option K-line. wire: option_kline (v2.0) */
268
+ async getOptionBars(req) {
269
+ return this.callInto('option_kline', req, '2.0');
270
+ }
271
+ /** Option tick trades. wire: option_trade_tick */
272
+ async getOptionTradeTicks(req) {
273
+ return this.callInto('option_trade_tick', req);
274
+ }
275
+ /** Option intraday timeline. wire: option_timeline */
276
+ async getOptionTimeline(req) {
277
+ return this.callInto('option_timeline', req);
278
+ }
279
+ /** Option depth. wire: option_depth */
280
+ async getOptionDepth(req) {
281
+ return this.callInto('option_depth', req);
282
+ }
283
+ /** Available option symbols. wire: option_symbol */
284
+ async getOptionSymbols(req) {
285
+ return this.callInto('option_symbol', req);
286
+ }
287
+ /** Option analysis (volatility). wire: option_analysis */
288
+ async getOptionAnalysis(req) {
289
+ return this.callInto('option_analysis', req);
290
+ }
291
+ /** Single futures contract by code. wire: future_contract_by_contract_code */
292
+ async getFutureContract(req) {
293
+ return this.callIntoListOrObject('future_contract_by_contract_code', req);
294
+ }
295
+ /** All futures contracts. wire: future_contracts */
296
+ async getAllFutureContracts(req) {
297
+ return this.callInto('future_contracts', req);
298
+ }
299
+ /** Current main contract. wire: future_current_contract */
300
+ async getCurrentFutureContract(req) {
301
+ return this.callInto('future_current_contract', req);
302
+ }
303
+ /** Continuous main contracts. wire: future_continuous_contracts */
304
+ async getFutureContinuousContracts(req) {
305
+ return this.callIntoListOrObject('future_continuous_contracts', req);
306
+ }
307
+ /** Historical main contracts. wire: future_main_contract */
308
+ async getFutureHistoryMainContract(req) {
309
+ return this.callInto('future_main_contract', req);
310
+ }
311
+ /**
312
+ * Futures K-line (full request with index pagination). wire: future_kline
313
+ * begin_time / end_time default to -1 when unset (server requires them present).
314
+ */
315
+ async getFutureBars(req) {
316
+ const body = {
317
+ ...req,
318
+ beginTime: req.beginTime ?? -1,
319
+ endTime: req.endTime ?? -1,
320
+ };
321
+ return this.callInto('future_kline', body);
322
+ }
323
+ /** Client-side paginated futures K-line fetch. */
324
+ async getFutureBarsByPage(req) {
325
+ const pageSize = req.pageSize && req.pageSize > 0 ? req.pageSize : 200;
326
+ const totalSize = req.totalSize && req.totalSize > 0 ? req.totalSize : 1000;
327
+ let beginTime = req.beginTime ?? -1;
328
+ let endTime = req.endTime ?? -1;
329
+ if (beginTime === 0)
330
+ beginTime = -1;
331
+ if (endTime === 0)
332
+ endTime = -1;
333
+ const acc = [];
334
+ while (acc.length < totalSize) {
335
+ const sub = {
336
+ contractCode: req.contractCode,
337
+ period: req.period,
338
+ beginTime,
339
+ endTime,
340
+ limit: pageSize,
341
+ lang: req.lang,
342
+ };
343
+ const pageOut = await this.callInto('future_kline', sub);
344
+ if (!pageOut || pageOut.length === 0 || !pageOut[0].items || pageOut[0].items.length === 0) {
345
+ break;
346
+ }
347
+ const items = pageOut[0].items;
348
+ acc.push(...items);
349
+ if (items.length < pageSize)
350
+ break;
351
+ let oldest = items[0].time;
352
+ for (const it of items) {
353
+ if (it.time < oldest)
354
+ oldest = it.time;
355
+ }
356
+ endTime = oldest - 1;
357
+ }
358
+ return acc;
359
+ }
360
+ /** Futures tick trades. wire: future_tick (API v3.0) */
361
+ async getFutureTradeTicks(req) {
362
+ return this.callInto('future_tick', req, '3.0');
363
+ }
364
+ /** Futures depth. wire: future_depth */
365
+ async getFutureDepth(req) {
366
+ return this.callInto('future_depth', req);
367
+ }
368
+ /** Futures trading times (single-object response). wire: future_trading_date */
369
+ async getFutureTradingTimes(req) {
370
+ return this.callInto('future_trading_date', req);
371
+ }
372
+ // ==========================================================================
373
+ // Batch 5: fund / warrant / industry / corporate / financial / calendar
374
+ // ==========================================================================
375
+ /** Fund symbols. wire: fund_all_symbols */
376
+ async getFundSymbols(req) {
377
+ return this.callInto('fund_all_symbols', req);
378
+ }
379
+ /** Fund contracts. wire: fund_contracts */
380
+ async getFundContracts(req) {
381
+ return this.callInto('fund_contracts', req);
382
+ }
383
+ /** Fund real-time NAV. wire: fund_quote */
384
+ async getFundQuote(req) {
385
+ return this.callInto('fund_quote', req);
386
+ }
387
+ /** Fund historical NAV. wire: fund_history_quote */
388
+ async getFundHistoryQuote(req) {
389
+ return this.callInto('fund_history_quote', req);
390
+ }
391
+ /** Warrant briefs. wire: warrant_briefs */
392
+ async getWarrantBriefs(req) {
393
+ return this.callInto('warrant_briefs', req);
394
+ }
395
+ /** Warrant filter (paged). wire: warrant_filter */
396
+ async getWarrantFilter(req) {
397
+ return this.callInto('warrant_filter', req);
398
+ }
399
+ /** Industry list. wire: industry_list */
400
+ async getIndustryList(req) {
401
+ return this.callInto('industry_list', req);
402
+ }
403
+ /** Stocks inside an industry. wire: industry_stock_list */
404
+ async getIndustryStocks(req) {
405
+ return this.callInto('industry_stock_list', req);
406
+ }
407
+ /** Corporate split (flattened). wire: corporate_action (action_type=split) */
408
+ async getCorporateSplit(req) {
409
+ const body = { ...req, actionType: 'split' };
410
+ const grouped = await this.callInto('corporate_action', body);
411
+ if (!grouped || typeof grouped !== 'object')
412
+ return [];
413
+ return Object.values(grouped).flat();
414
+ }
415
+ /** Corporate dividend (flattened). wire: corporate_action (action_type=dividend) */
416
+ async getCorporateDividend(req) {
417
+ const body = { ...req, actionType: 'dividend' };
418
+ const grouped = await this.callInto('corporate_action', body);
419
+ if (!grouped || typeof grouped !== 'object')
420
+ return [];
421
+ return Object.values(grouped).flat();
422
+ }
423
+ /** Corporate earnings calendar (flattened). wire: corporate_action (action_type=earning) */
424
+ async getCorporateEarningsCalendar(req) {
425
+ const body = { ...req, actionType: 'earning' };
426
+ const grouped = await this.callInto('corporate_action', body);
427
+ if (!grouped || typeof grouped !== 'object')
428
+ return [];
429
+ return Object.values(grouped).flat();
430
+ }
431
+ /** Financial currency per symbol. wire: financial_currency */
432
+ async getFinancialCurrency(req) {
433
+ return this.callInto('financial_currency', req);
434
+ }
435
+ /** FX rates. wire: financial_exchange_rate */
436
+ async getFinancialExchangeRate(req) {
437
+ return this.callInto('financial_exchange_rate', req);
438
+ }
439
+ /** Trading calendar. wire: trading_calendar */
440
+ async getTradingCalendar(req) {
441
+ return this.callInto('trading_calendar', req);
442
+ }
443
+ /** Available market-scanner tags. wire: market_scanner_tags */
444
+ async getMarketScannerTags(req) {
445
+ return this.callInto('market_scanner_tags', req);
446
+ }
447
+ /** Overnight quote. wire: quote_overnight */
448
+ async getQuoteOvernight(req) {
449
+ return this.callInto('quote_overnight', req);
450
+ }
139
451
  }
@@ -1,5 +1,25 @@
1
1
  import { createApiRequest } from '../client/api-request';
2
2
  import { unmarshalData } from '../client/api-response';
3
+ import { normalizeOrderStatus } from '../model/order-status';
4
+ /** Normalize `Order.status` field in-place (handles int → string). */
5
+ function normalizeOrderInPlace(o) {
6
+ if (o && o.status !== undefined && o.status !== null) {
7
+ o.status = normalizeOrderStatus(o.status);
8
+ }
9
+ }
10
+ /** Normalize every Order in a list in-place. */
11
+ function normalizeOrders(orders) {
12
+ for (const o of orders)
13
+ normalizeOrderInPlace(o);
14
+ return orders;
15
+ }
16
+ /** Shallow-copy a request object and fill account if empty. */
17
+ function withAccount(req, account) {
18
+ const r = { ...(req ?? {}) };
19
+ if (!r.account)
20
+ r.account = account;
21
+ return r;
22
+ }
3
23
  /** Trading client wrapping all trade-related APIs. */
4
24
  export class TradeClient {
5
25
  constructor(httpClient, account) {
@@ -51,39 +71,160 @@ export class TradeClient {
51
71
  async cancelOrder(id) {
52
72
  return this.callInto('cancel_order', { account: this.account, id });
53
73
  }
54
- // === Order queries ===
55
- async getOrders() {
56
- return this.callIntoItems('orders', { account: this.account });
74
+ // === Order queries (BREAKING v0.4.0) ===
75
+ /**
76
+ * Query all historical orders. v0.4.0: optional OrdersRequest for filtering.
77
+ *
78
+ * @example
79
+ * // Default (unfiltered)
80
+ * await tc.getOrders();
81
+ * // Filter by status
82
+ * await tc.getOrders({ states: ['Filled'], limit: 100 });
83
+ */
84
+ async getOrders(req) {
85
+ return normalizeOrders(await this.callIntoItems('orders', withAccount(req, this.account)));
57
86
  }
58
- async getActiveOrders() {
59
- return this.callIntoItems('active_orders', { account: this.account });
87
+ /** Query active (open) orders. v0.4.0: supports ParentId to filter attached legs. */
88
+ async getActiveOrders(req) {
89
+ return normalizeOrders(await this.callIntoItems('active_orders', withAccount(req, this.account)));
60
90
  }
61
- async getInactiveOrders() {
62
- return this.callIntoItems('inactive_orders', { account: this.account });
91
+ /** Query inactive/cancelled orders. */
92
+ async getInactiveOrders(req) {
93
+ return normalizeOrders(await this.callIntoItems('inactive_orders', withAccount(req, this.account)));
63
94
  }
64
95
  /**
65
- * Filled orders in a time range (ms timestamps required by the server).
66
- * Use `Date.now() - 30*24*3600*1000` for "last 30 days".
96
+ * Query filled orders. v0.4.0 BREAKING: signature changed from positional
97
+ * (startDateMs, endDateMs) to OrdersRequest object.
98
+ *
99
+ * @example
100
+ * // Last 30 days
101
+ * const now = Date.now();
102
+ * await tc.getFilledOrders({ startDate: now - 30*24*3600*1000, endDate: now });
67
103
  */
68
- async getFilledOrders(startDateMs, endDateMs) {
69
- return this.callIntoItems('filled_orders', {
70
- account: this.account, startDate: startDateMs, endDate: endDateMs,
71
- });
104
+ async getFilledOrders(req) {
105
+ return normalizeOrders(await this.callIntoItems('filled_orders', withAccount(req, this.account)));
72
106
  }
73
- /** Transactions for a specific order; `symbol` and `secType` are required. */
74
- async getOrderTransactions(id, symbol, secType) {
75
- return this.callIntoItems('order_transactions', {
76
- account: this.account, orderId: id, symbol, secType,
77
- });
107
+ /**
108
+ * Get a single order by ID (v0.4.0 new).
109
+ * Wire method: `orders` with id/order_id param; server returns a single Order object
110
+ * (not `{items:[]}` envelope).
111
+ *
112
+ * Returns `undefined` if no match.
113
+ */
114
+ async getOrder(req) {
115
+ const merged = withAccount(req, this.account);
116
+ const out = await this.callInto('orders', merged);
117
+ if (!out || (!out.id && !out.orderId))
118
+ return undefined;
119
+ normalizeOrderInPlace(out);
120
+ return out;
78
121
  }
79
- // === Positions & assets ===
80
- async getPositions() {
81
- return this.callIntoItems('positions', { account: this.account });
122
+ /**
123
+ * Query order transaction details. v0.4.0 BREAKING: all fields now optional
124
+ * (previously symbol/secType required).
125
+ */
126
+ async getOrderTransactions(req) {
127
+ return this.callIntoItems('order_transactions', withAccount(req, this.account));
128
+ }
129
+ // === Positions & assets (BREAKING v0.4.0) ===
130
+ /** Query positions. v0.4.0: supports Symbol / SecType / Currency / Market filters. */
131
+ async getPositions(req) {
132
+ return this.callIntoItems('positions', withAccount(req, this.account));
133
+ }
134
+ /** Query assets. v0.4.0: supports sub-account list and aggregation options. */
135
+ async getAssets(req) {
136
+ return this.callIntoItems('assets', withAccount(req, this.account));
137
+ }
138
+ /** Query prime assets. v0.4.0: takes AssetsRequest for filters. */
139
+ async getPrimeAssets(req) {
140
+ return this.callInto('prime_assets', withAccount(req, this.account));
82
141
  }
83
- async getAssets() {
84
- return this.callIntoItems('assets', { account: this.account });
142
+ // ===== v0.4.0 NEW: Account management =====
143
+ /** Query managed sub-accounts (institutional). */
144
+ async getManagedAccounts(req) {
145
+ return this.callIntoItems('accounts', withAccount(req, this.account));
85
146
  }
86
- async getPrimeAssets() {
87
- return this.callInto('prime_assets', { account: this.account });
147
+ /**
148
+ * Query derivative contracts list. Same wire as getQuoteContract but accepts
149
+ * full request struct. Python: `get_derivative_contracts`.
150
+ */
151
+ async getDerivativeContracts(req) {
152
+ return this.callIntoItems('quote_contract', withAccount(req, this.account));
153
+ }
154
+ // ===== v0.4.0 NEW: Asset analytics =====
155
+ /** Daily P&L / net-value / holding-value analytics. */
156
+ async getAnalyticsAsset(req) {
157
+ return this.callIntoItems('analytics_asset', withAccount(req, this.account));
158
+ }
159
+ /** Aggregate assets (prime) by base currency. */
160
+ async getAggregateAssets(req) {
161
+ return this.callInto('aggregate_assets', withAccount(req, this.account));
162
+ }
163
+ /** Estimate tradable quantity given order parameters. */
164
+ async getEstimateTradableQuantity(req) {
165
+ return this.callInto('estimate_tradable_quantity', withAccount(req, this.account));
166
+ }
167
+ // ===== v0.4.0 NEW: Forex =====
168
+ /** Place forex order (sub-account base-currency swap). */
169
+ async placeForexOrder(req) {
170
+ return this.callInto('place_forex_order', withAccount(req, this.account));
171
+ }
172
+ // ===== v0.4.0 NEW: Segment fund transfer =====
173
+ /** Query amount available for inter-segment transfer. Returns array. */
174
+ async getSegmentFundAvailable(req) {
175
+ return this.callInto('segment_fund_available', withAccount(req, this.account));
176
+ }
177
+ /** Query segment fund transfer history. Server returns plain array (no items wrapper). */
178
+ async getSegmentFundHistory(req) {
179
+ return this.callInto('segment_fund_history', withAccount(req, this.account));
180
+ }
181
+ /** Execute an inter-segment fund transfer. */
182
+ async transferSegmentFund(req) {
183
+ return this.callInto('transfer_segment_fund', withAccount(req, this.account));
184
+ }
185
+ /** Cancel a pending inter-segment transfer. */
186
+ async cancelSegmentFund(req) {
187
+ return this.callInto('cancel_segment_fund', withAccount(req, this.account));
188
+ }
189
+ // ===== v0.4.0 NEW: Fund details / history =====
190
+ /** Fund-movement details (by segment / currency / fund-type). */
191
+ async getFundDetails(req) {
192
+ return this.callIntoItems('fund_details', withAccount(req, this.account));
193
+ }
194
+ /** Funding history (wire method: `transfer_fund`). */
195
+ async getFundingHistory(req) {
196
+ return this.callIntoItems('transfer_fund', withAccount(req, this.account));
197
+ }
198
+ // ===== v0.4.0 NEW: Internal / external position transfer =====
199
+ /**
200
+ * Internal position transfer (cross sub-account).
201
+ * @note Uses `fromAccount` / `toAccount` (not `account`).
202
+ */
203
+ async transferPosition(req) {
204
+ const merged = { ...req };
205
+ if (!merged.fromAccount)
206
+ merged.fromAccount = this.account;
207
+ return this.callInto('position_transfer', merged);
208
+ }
209
+ /** Query internal position transfer records. Uses `accountId` (wire: `account_id`). */
210
+ async getPositionTransferRecords(req) {
211
+ const merged = { ...req };
212
+ if (!merged.accountId)
213
+ merged.accountId = this.account;
214
+ return this.callIntoItems('position_transfer_records', merged);
215
+ }
216
+ /** Query single internal position transfer detail by ID. */
217
+ async getPositionTransferDetail(req) {
218
+ const merged = { ...req };
219
+ if (!merged.accountId)
220
+ merged.accountId = this.account;
221
+ return this.callInto('position_transfer_detail', merged);
222
+ }
223
+ /** Query external position transfer records (DWAC / FOP / etc.). */
224
+ async getPositionTransferExternalRecords(req) {
225
+ const merged = { ...req };
226
+ if (!merged.accountId)
227
+ merged.accountId = this.account;
228
+ return this.callIntoItems('position_transfer_external_records', merged);
88
229
  }
89
230
  }
@@ -15,4 +15,4 @@
15
15
  * @packageDocumentation
16
16
  */
17
17
  /** SDK 版本号 */
18
- export declare const VERSION = "0.3.0";
18
+ export declare const VERSION = "0.4.0";
@@ -44,18 +44,28 @@ export declare enum OrderType {
44
44
  VWAP = "VWAP",
45
45
  OCA = "OCA"
46
46
  }
47
- /** 订单状态枚举 */
47
+ /**
48
+ * 订单状态枚举。对齐 Java SDK OrderStatus 定义。
49
+ *
50
+ * 服务端 wire 返回的值同时可能是:
51
+ * - 数字: -2 / -1 / 3 / 4 / 5 / 6 / 7 / 8
52
+ * - 字符串: "Invalid" / "Initial" / "PendingCancel" / "Cancelled" /
53
+ * "Submitted" / "Filled" / "Inactive" / "PendingSubmit"
54
+ *
55
+ * Client 层通过 normalizeOrderStatus() 做数字→字符串归一,不做跨别名合并。
56
+ */
48
57
  export declare enum OrderStatus {
49
- PendingNew = "PendingNew",
58
+ Invalid = "Invalid",
50
59
  Initial = "Initial",
60
+ PendingCancel = "PendingCancel",
61
+ Cancelled = "Cancelled",
51
62
  Submitted = "Submitted",
52
- PartiallyFilled = "PartiallyFilled",
53
63
  Filled = "Filled",
54
- Cancelled = "Cancelled",
55
- PendingCancel = "PendingCancel",
56
64
  Inactive = "Inactive",
57
- Invalid = "Invalid"
65
+ PendingSubmit = "PendingSubmit"
58
66
  }
67
+ /** 返回订单状态对应的服务端数字码,未知返回 0。 */
68
+ export declare function orderStatusCode(status: OrderStatus | string): number;
59
69
  /** K 线周期枚举 */
60
70
  export declare enum BarPeriod {
61
71
  Day = "day",
@@ -95,3 +105,47 @@ export declare enum TimeInForce {
95
105
  GTC = "GTC",
96
106
  OPG = "OPG"
97
107
  }
108
+ /** 订单排序字段 */
109
+ export declare enum OrderSortBy {
110
+ LatestCreated = "LATEST_CREATED",
111
+ LatestStatusUpdated = "LATEST_STATUS_UPDATED"
112
+ }
113
+ /** 账户分部类型 */
114
+ export declare enum SegmentType {
115
+ All = "ALL",
116
+ Sec = "SEC",
117
+ Fut = "FUT",
118
+ Fund = "FUND"
119
+ }
120
+ /** 公司行动类型 */
121
+ export declare enum CorporateActionType {
122
+ Split = "split",
123
+ Dividend = "dividend",
124
+ Earning = "earning"
125
+ }
126
+ /** 行业级别 (1~4 级) */
127
+ export declare enum IndustryLevel {
128
+ GSector = "GSECTOR",
129
+ GGroup = "GGROUP",
130
+ GInd = "GIND",
131
+ GSubInd = "GSUBIND"
132
+ }
133
+ /** 排序方向 */
134
+ export declare enum SortDirection {
135
+ No = "SortDir_No",
136
+ Ascend = "SortDir_Ascend",
137
+ Descend = "SortDir_Descend"
138
+ }
139
+ /** 期权分析周期 */
140
+ export declare enum OptionAnalysisPeriod {
141
+ ThreeYear = "3year",
142
+ FiftyTwoWeek = "52week",
143
+ TwentySixWeek = "26week",
144
+ ThirteenWeek = "13week"
145
+ }
146
+ /** 财报类型 */
147
+ export declare enum FinancialReportPeriod {
148
+ Annual = "Annual",
149
+ Quarterly = "Quarterly",
150
+ LTM = "LTM"
151
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Order status normalization.
3
+ *
4
+ * 服务端返回的订单状态有时是整数(-2/-1/3/4/5/6/7/8),有时是字符串
5
+ * ("Invalid"/"Submitted"/...)。本模块把二者统一为 Java SDK OrderStatus 的
6
+ * 字符串值。不做跨别名合并。
7
+ *
8
+ * 对齐 Java SDK OrderStatus.java。
9
+ */
10
+ /**
11
+ * 把服务端可能返回的 string/number 订单状态归一为字符串。
12
+ * 字符串原样透传;数字按映射表转换;其他输入返回空串。
13
+ */
14
+ export declare function normalizeOrderStatus(raw: unknown): string;