tigeropen 0.4.0 → 0.5.5

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 (71) hide show
  1. package/README.md +55 -2
  2. package/dist/cjs/client/api-response.js +28 -7
  3. package/dist/cjs/client/case-convert.js +4 -3
  4. package/dist/cjs/client/http-client.js +124 -8
  5. package/dist/cjs/client/token-methods.js +42 -0
  6. package/dist/cjs/config/client-config.js +115 -16
  7. package/dist/cjs/config/config-parser.js +19 -9
  8. package/dist/cjs/config/index.js +4 -1
  9. package/dist/cjs/config/token-manager.js +54 -4
  10. package/dist/cjs/index.js +53 -2
  11. package/dist/cjs/model/enums.js +18 -1
  12. package/dist/cjs/model/order-helpers.js +149 -0
  13. package/dist/cjs/push/index.js +1 -0
  14. package/dist/cjs/push/push-client.js +47 -19
  15. package/dist/cjs/push/tick-util.js +172 -0
  16. package/dist/cjs/quote/quote-client.js +300 -70
  17. package/dist/cjs/trade/trade-client.js +174 -13
  18. package/dist/cjs/version.js +4 -0
  19. package/dist/esm/client/api-request.js +1 -1
  20. package/dist/esm/client/api-response.js +29 -8
  21. package/dist/esm/client/case-convert.js +4 -3
  22. package/dist/esm/client/http-client.js +128 -12
  23. package/dist/esm/client/index.js +6 -6
  24. package/dist/esm/client/token-methods.js +37 -0
  25. package/dist/esm/config/client-config.js +118 -20
  26. package/dist/esm/config/config-parser.js +19 -9
  27. package/dist/esm/config/index.js +4 -3
  28. package/dist/esm/config/token-manager.js +55 -5
  29. package/dist/esm/index.js +15 -1
  30. package/dist/esm/logger/index.js +1 -1
  31. package/dist/esm/model/contract-helpers.js +1 -1
  32. package/dist/esm/model/enums.js +17 -0
  33. package/dist/esm/model/order-helpers.js +142 -1
  34. package/dist/esm/model/order-status.js +1 -1
  35. package/dist/esm/push/index.js +6 -5
  36. package/dist/esm/push/pb/PushData.js +11 -11
  37. package/dist/esm/push/pb/QuoteBasicData.js +1 -1
  38. package/dist/esm/push/pb/Response.js +1 -1
  39. package/dist/esm/push/pb/index.js +17 -17
  40. package/dist/esm/push/proto-message.js +3 -3
  41. package/dist/esm/push/push-client.js +54 -26
  42. package/dist/esm/push/tick-util.js +165 -0
  43. package/dist/esm/quote/index.js +1 -1
  44. package/dist/esm/quote/quote-client.js +269 -72
  45. package/dist/esm/signer/index.js +2 -2
  46. package/dist/esm/trade/index.js +1 -1
  47. package/dist/esm/trade/trade-client.js +144 -16
  48. package/dist/esm/version.js +1 -0
  49. package/dist/types/client/api-response.d.ts +6 -4
  50. package/dist/types/client/case-convert.d.ts +3 -1
  51. package/dist/types/client/http-client.d.ts +32 -1
  52. package/dist/types/client/token-methods.d.ts +34 -0
  53. package/dist/types/config/client-config.d.ts +22 -1
  54. package/dist/types/config/index.d.ts +3 -1
  55. package/dist/types/config/token-manager.d.ts +27 -3
  56. package/dist/types/index.d.ts +22 -1
  57. package/dist/types/model/enums.d.ts +18 -2
  58. package/dist/types/model/order-helpers.d.ts +52 -1
  59. package/dist/types/model/order.d.ts +127 -10
  60. package/dist/types/model/quote-requests.d.ts +27 -15
  61. package/dist/types/model/quote.d.ts +150 -24
  62. package/dist/types/model/trade-requests.d.ts +118 -4
  63. package/dist/types/model/trade.d.ts +121 -17
  64. package/dist/types/push/callbacks.d.ts +3 -7
  65. package/dist/types/push/index.d.ts +1 -0
  66. package/dist/types/push/push-client.d.ts +5 -3
  67. package/dist/types/push/tick-util.d.ts +30 -0
  68. package/dist/types/quote/quote-client.d.ts +101 -36
  69. package/dist/types/trade/trade-client.d.ts +57 -11
  70. package/dist/types/version.d.ts +1 -0
  71. package/package.json +5 -2
@@ -5,17 +5,17 @@
5
5
  // source: PushData.proto
6
6
  /* eslint-disable */
7
7
  import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
8
- import { AssetData } from "./AssetData";
9
- import { KlineData } from "./KlineData";
10
- import { OptionTopData } from "./OptionTopData";
11
- import { OrderStatusData } from "./OrderStatusData";
12
- import { OrderTransactionData } from "./OrderTransactionData";
13
- import { PositionData } from "./PositionData";
14
- import { QuoteData } from "./QuoteData";
15
- import { QuoteDepthData } from "./QuoteDepthData";
16
- import { StockTopData } from "./StockTopData";
17
- import { TickData } from "./TickData";
18
- import { TradeTickData } from "./TradeTickData";
8
+ import { AssetData } from "./AssetData.js";
9
+ import { KlineData } from "./KlineData.js";
10
+ import { OptionTopData } from "./OptionTopData.js";
11
+ import { OrderStatusData } from "./OrderStatusData.js";
12
+ import { OrderTransactionData } from "./OrderTransactionData.js";
13
+ import { PositionData } from "./PositionData.js";
14
+ import { QuoteData } from "./QuoteData.js";
15
+ import { QuoteDepthData } from "./QuoteDepthData.js";
16
+ import { StockTopData } from "./StockTopData.js";
17
+ import { TickData } from "./TickData.js";
18
+ import { TradeTickData } from "./TradeTickData.js";
19
19
  export const protobufPackage = "com.tigerbrokers.stock.openapi.client.socket.data.pb";
20
20
  function createBasePushData() {
21
21
  return {
@@ -5,7 +5,7 @@
5
5
  // source: QuoteBasicData.proto
6
6
  /* eslint-disable */
7
7
  import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
8
- import { QuoteData_Minute } from "./QuoteData";
8
+ import { QuoteData_Minute } from "./QuoteData.js";
9
9
  export const protobufPackage = "com.tigerbrokers.stock.openapi.client.socket.data.pb";
10
10
  function createBaseQuoteBasicData() {
11
11
  return {
@@ -5,7 +5,7 @@
5
5
  // source: Response.proto
6
6
  /* eslint-disable */
7
7
  import { BinaryReader, BinaryWriter } from "@bufbuild/protobuf/wire";
8
- import { PushData } from "./PushData";
8
+ import { PushData } from "./PushData.js";
9
9
  export const protobufPackage = "com.tigerbrokers.stock.openapi.client.socket.data.pb";
10
10
  function createBaseResponse() {
11
11
  return { command: 0, id: undefined, code: undefined, msg: undefined, body: undefined };
@@ -4,22 +4,22 @@
4
4
  * 由 ts-proto 从 proto 文件生成的所有类型、枚举和编解码函数
5
5
  */
6
6
  // 基础层:命令和数据类型枚举
7
- export { SocketCommon_Command, SocketCommon_DataType, SocketCommon_QuoteType, } from './SocketCommon';
7
+ export { SocketCommon_Command, SocketCommon_DataType, SocketCommon_QuoteType, } from './SocketCommon.js';
8
8
  // 协议层:请求和响应消息
9
- export { Request, Request_Connect, Request_Subscribe } from './Request';
10
- export { Response } from './Response';
11
- export { PushData } from './PushData';
9
+ export { Request, Request_Connect, Request_Subscribe } from './Request.js';
10
+ export { Response } from './Response.js';
11
+ export { PushData } from './PushData.js';
12
12
  // 数据层:业务数据消息
13
- export { QuoteData } from './QuoteData';
14
- export { QuoteBasicData } from './QuoteBasicData';
15
- export { QuoteBBOData } from './QuoteBBOData';
16
- export { QuoteDepthData } from './QuoteDepthData';
17
- export { TradeTickData } from './TradeTickData';
18
- export { TickData } from './TickData';
19
- export { AssetData } from './AssetData';
20
- export { PositionData } from './PositionData';
21
- export { OrderStatusData } from './OrderStatusData';
22
- export { OrderTransactionData } from './OrderTransactionData';
23
- export { StockTopData } from './StockTopData';
24
- export { OptionTopData } from './OptionTopData';
25
- export { KlineData } from './KlineData';
13
+ export { QuoteData } from './QuoteData.js';
14
+ export { QuoteBasicData } from './QuoteBasicData.js';
15
+ export { QuoteBBOData } from './QuoteBBOData.js';
16
+ export { QuoteDepthData } from './QuoteDepthData.js';
17
+ export { TradeTickData } from './TradeTickData.js';
18
+ export { TickData } from './TickData.js';
19
+ export { AssetData } from './AssetData.js';
20
+ export { PositionData } from './PositionData.js';
21
+ export { OrderStatusData } from './OrderStatusData.js';
22
+ export { OrderTransactionData } from './OrderTransactionData.js';
23
+ export { StockTopData } from './StockTopData.js';
24
+ export { OptionTopData } from './OptionTopData.js';
25
+ export { KlineData } from './KlineData.js';
@@ -4,9 +4,9 @@
4
4
  * 对齐 Java SDK 的 ProtoMessageUtil,提供构建各种 Request 消息的工具函数。
5
5
  * 所有构建函数共享一个递增的 requestId 计数器。
6
6
  */
7
- import { Request, Request_Connect, Request_Subscribe, } from './pb/Request';
8
- import { SocketCommon_Command, SocketCommon_DataType, } from './pb/SocketCommon';
9
- import { SubjectType } from './push-message';
7
+ import { Request, Request_Connect, Request_Subscribe, } from './pb/Request.js';
8
+ import { SocketCommon_Command, SocketCommon_DataType, } from './pb/SocketCommon.js';
9
+ import { SubjectType } from './push-message.js';
10
10
  /** 递增请求 ID 计数器(单线程环境,简单递增变量) */
11
11
  let requestId = 0;
12
12
  /**
@@ -9,13 +9,14 @@
9
9
  * heartbeat keep-alive, and automatic reconnection.
10
10
  */
11
11
  import * as tls from 'tls';
12
- import { signWithRSA } from '../signer/signer';
13
- import { SubjectType } from './push-message';
14
- import { Request } from './pb/Request';
15
- import { Response } from './pb/Response';
16
- import { SocketCommon_Command, SocketCommon_DataType } from './pb/SocketCommon';
17
- import { encodeVarint32, decodeVarint32 } from './varint';
18
- import { buildConnectMessage, buildHeartBeatMessage, buildSubscribeMessage, buildUnSubscribeMessage, buildDisconnectMessage, subjectToDataType, } from './proto-message';
12
+ import { signWithRSA } from '../signer/signer.js';
13
+ import { SubjectType } from './push-message.js';
14
+ import { convertTradeTick } from './tick-util.js';
15
+ import { Request } from './pb/Request.js';
16
+ import { Response } from './pb/Response.js';
17
+ import { SocketCommon_Command, SocketCommon_DataType } from './pb/SocketCommon.js';
18
+ import { encodeVarint32, decodeVarint32 } from './varint.js';
19
+ import { buildConnectMessage, buildHeartBeatMessage, buildSubscribeMessage, buildUnSubscribeMessage, buildDisconnectMessage, subjectToDataType, } from './proto-message.js';
19
20
  /** Default push server host */
20
21
  const DEFAULT_PUSH_HOST = 'openapi.tigerfintech.com';
21
22
  /** Default push server port */
@@ -28,8 +29,9 @@ const DEFAULT_RECONNECT_INTERVAL = 5000;
28
29
  const MAX_RECONNECT_INTERVAL = 60000;
29
30
  /** Default connect timeout (ms) */
30
31
  const DEFAULT_CONNECT_TIMEOUT = 30000;
32
+ import { SDK_VERSION as _SDK_VERSION } from '../version.js';
31
33
  /** SDK version identifier */
32
- const SDK_VERSION = 'typescript/0.4.0';
34
+ const SDK_VERSION = `typescript/${_SDK_VERSION}`;
33
35
  /** Protocol version */
34
36
  const ACCEPT_VERSION = '1.0';
35
37
  /** Default send heartbeat interval (ms) */
@@ -50,11 +52,13 @@ export class PushClient {
50
52
  constructor(config, options) {
51
53
  this.socket = null;
52
54
  this._state = ConnectionState.Disconnected;
55
+ /** Whether this connect attempt already fell back to unverified TLS */
56
+ this.tlsFallback = false;
53
57
  this.callbacks = {};
54
58
  /** Subscription state: subject -> Set<symbol> */
55
59
  this.subscriptions = new Map();
56
- /** Account-level subscriptions */
57
- this.accountSubs = new Set();
60
+ /** Account-level subscriptions: subject -> account string used at subscribe time */
61
+ this.accountSubs = new Map();
58
62
  this.heartbeatTimer = null;
59
63
  this.reconnectTimer = null;
60
64
  this.stopped = false;
@@ -88,6 +92,7 @@ export class PushClient {
88
92
  }
89
93
  this._state = ConnectionState.Connecting;
90
94
  this.stopped = false;
95
+ this.tlsFallback = false;
91
96
  this.recvBuffer = Buffer.alloc(0);
92
97
  const socket = this.createSocket(this.pushHost, this.pushPort);
93
98
  this.socket = socket;
@@ -144,6 +149,24 @@ export class PushClient {
144
149
  });
145
150
  socket.on('error', (err) => {
146
151
  if (!settled) {
152
+ // If this is a TLS certificate error, warn and retry without verification.
153
+ const isTlsCertError = err.message.includes('certificate') ||
154
+ err.message.includes('CERT') ||
155
+ err.code === 'DEPTH_ZERO_SELF_SIGNED_CERT' ||
156
+ err.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' ||
157
+ err.code === 'CERT_HAS_EXPIRED';
158
+ if (isTlsCertError && !this.tlsFallback) {
159
+ this.tlsFallback = true;
160
+ settled = true;
161
+ clearTimeout(timeout);
162
+ socket.destroy();
163
+ this.socket = null;
164
+ this._state = ConnectionState.Disconnected;
165
+ console.warn(`[TigerOpen] TLS certificate verification failed: ${err.message}. Retrying without verification.`);
166
+ // Retry immediately using unverified TLS
167
+ this.connect().then(resolve).catch(reject);
168
+ return;
169
+ }
147
170
  settled = true;
148
171
  clearTimeout(timeout);
149
172
  this._state = ConnectionState.Disconnected;
@@ -196,7 +219,7 @@ export class PushClient {
196
219
  createSocket(host, port) {
197
220
  if (this.socketFactory)
198
221
  return this.socketFactory(host, port);
199
- return tls.connect({ host, port, rejectUnauthorized: false });
222
+ return tls.connect({ host, port, rejectUnauthorized: !this.tlsFallback });
200
223
  }
201
224
  /** Handle incoming TCP data: buffer + decode varint32 frames */
202
225
  handleData(chunk, onConnected) {
@@ -295,8 +318,8 @@ export class PushClient {
295
318
  for (const [subject, symbols] of this.subscriptions) {
296
319
  this.doSubscribe(subject, Array.from(symbols));
297
320
  }
298
- for (const subject of this.accountSubs) {
299
- this.doSubscribe(subject, undefined, this.config.account);
321
+ for (const [subject, account] of this.accountSubs) {
322
+ this.doSubscribe(subject, undefined, account);
300
323
  }
301
324
  }
302
325
  /** Dispatch push data to the appropriate callback based on dataType */
@@ -320,8 +343,10 @@ export class PushClient {
320
343
  cb.onDepth?.(pushData.quoteDepthData);
321
344
  break;
322
345
  case SocketCommon_DataType.TradeTick:
346
+ if (pushData.tickData)
347
+ cb.onFullTick?.(pushData.tickData);
323
348
  if (pushData.tradeTickData)
324
- cb.onTick?.(pushData.tradeTickData);
349
+ cb.onTick?.(convertTradeTick(pushData.tradeTickData));
325
350
  break;
326
351
  case SocketCommon_DataType.Asset:
327
352
  if (pushData.assetData)
@@ -357,8 +382,7 @@ export class PushClient {
357
382
  cb.onQuote?.(pushData.quoteData);
358
383
  break;
359
384
  default:
360
- // FullTick and QuoteBBO use TradeTick/Quote dataType
361
- // TickData (fullTick) via tickData field
385
+ // QuoteBBO and some full-tick payloads reuse an existing dataType.
362
386
  if (pushData.tickData)
363
387
  cb.onFullTick?.(pushData.tickData);
364
388
  break;
@@ -530,8 +554,9 @@ export class PushClient {
530
554
  // ===== Account push subscribe/unsubscribe =====
531
555
  /** Subscribe to asset changes */
532
556
  subscribeAsset(account) {
533
- this.doSubscribe(SubjectType.Asset, undefined, account || this.config.account);
534
- this.accountSubs.add(SubjectType.Asset);
557
+ const acct = account || this.config.account;
558
+ this.doSubscribe(SubjectType.Asset, undefined, acct);
559
+ this.accountSubs.set(SubjectType.Asset, acct);
535
560
  }
536
561
  /** Unsubscribe from asset changes */
537
562
  unsubscribeAsset() {
@@ -540,8 +565,9 @@ export class PushClient {
540
565
  }
541
566
  /** Subscribe to position changes */
542
567
  subscribePosition(account) {
543
- this.doSubscribe(SubjectType.Position, undefined, account || this.config.account);
544
- this.accountSubs.add(SubjectType.Position);
568
+ const acct = account || this.config.account;
569
+ this.doSubscribe(SubjectType.Position, undefined, acct);
570
+ this.accountSubs.set(SubjectType.Position, acct);
545
571
  }
546
572
  /** Unsubscribe from position changes */
547
573
  unsubscribePosition() {
@@ -550,8 +576,9 @@ export class PushClient {
550
576
  }
551
577
  /** Subscribe to order status */
552
578
  subscribeOrder(account) {
553
- this.doSubscribe(SubjectType.Order, undefined, account || this.config.account);
554
- this.accountSubs.add(SubjectType.Order);
579
+ const acct = account || this.config.account;
580
+ this.doSubscribe(SubjectType.Order, undefined, acct);
581
+ this.accountSubs.set(SubjectType.Order, acct);
555
582
  }
556
583
  /** Unsubscribe from order status */
557
584
  unsubscribeOrder() {
@@ -560,8 +587,9 @@ export class PushClient {
560
587
  }
561
588
  /** Subscribe to transaction details */
562
589
  subscribeTransaction(account) {
563
- this.doSubscribe(SubjectType.Transaction, undefined, account || this.config.account);
564
- this.accountSubs.add(SubjectType.Transaction);
590
+ const acct = account || this.config.account;
591
+ this.doSubscribe(SubjectType.Transaction, undefined, acct);
592
+ this.accountSubs.set(SubjectType.Transaction, acct);
565
593
  }
566
594
  /** Unsubscribe from transaction details */
567
595
  unsubscribeTransaction() {
@@ -577,8 +605,8 @@ export class PushClient {
577
605
  }
578
606
  return result;
579
607
  }
580
- /** Get account-level subscriptions */
608
+ /** Get account-level subscriptions: subject -> account */
581
609
  getAccountSubscriptions() {
582
- return Array.from(this.accountSubs);
610
+ return new Map(this.accountSubs);
583
611
  }
584
612
  }
@@ -0,0 +1,165 @@
1
+ const PART_CODE_NAME_MAP = {
2
+ a: 'NYSE American, LLC (NYSE American)',
3
+ b: 'NASDAQ OMX BX, Inc. (NASDAQ OMX BX)',
4
+ c: 'NYSE National, Inc. (NYSE National)',
5
+ d: 'FINRA Alternative Display Facility (ADF)',
6
+ h: 'MIAX Pearl Exchange, LLC (MIAX)',
7
+ i: 'International Securities Exchange, LLC (ISE)',
8
+ j: 'Cboe EDGA Exchange, Inc. (Cboe EDGA)',
9
+ k: 'Cboe EDGX Exchange, Inc. (Cboe EDGX)',
10
+ l: 'Long-Term Stock Exchange, Inc. (LTSE)',
11
+ m: 'NYSE Chicago, Inc. (NYSE Chicago)',
12
+ n: 'New York Stock Exchange, LLC (NYSE)',
13
+ p: 'NYSE Arca, Inc. (NYSE Arca)',
14
+ s: 'Consolidated Tape System (CTS)',
15
+ t: 'NASDAQ Stock Market, LLC (NASDAQ)',
16
+ u: 'Members Exchange, LLC (MEMX)',
17
+ v: "Investors' Exchange, LLC. (IEX)",
18
+ w: 'CBOE Stock Exchange, Inc. (CBSX)',
19
+ x: 'NASDAQ OMX PSX, Inc. (NASDAQ OMX PSX)',
20
+ y: 'Cboe BYX Exchange, Inc. (Cboe BYX)',
21
+ z: 'Cboe BZX Exchange, Inc. (Cboe BZX)',
22
+ };
23
+ const PART_CODE_SHORT_NAME_MAP = {
24
+ a: 'AMEX',
25
+ b: 'BX',
26
+ c: 'NSX',
27
+ d: 'ADF',
28
+ h: 'MIAX',
29
+ i: 'ISE',
30
+ j: 'EDGA',
31
+ k: 'EDGX',
32
+ l: 'LTSE',
33
+ m: 'CHO',
34
+ n: 'NYSE',
35
+ p: 'ARCA',
36
+ s: 'CTS',
37
+ t: 'NSDQ',
38
+ u: 'MEMX',
39
+ v: 'IEX',
40
+ w: 'CBSX',
41
+ x: 'PSX',
42
+ y: 'BYX',
43
+ z: 'BZX',
44
+ };
45
+ const US_TRADE_COND = {
46
+ ' ': 'US_REGULAR_SALE',
47
+ B: 'US_BUNCHED_TRADE',
48
+ C: 'US_CASH_TRADE',
49
+ F: 'US_INTERMARKET_SWEEP',
50
+ G: 'US_BUNCHED_SOLD_TRADE',
51
+ H: 'US_PRICE_VARIATION_TRADE',
52
+ I: 'US_ODD_LOT_TRADE',
53
+ K: 'US_RULE_127_OR_155_TRADE',
54
+ L: 'US_SOLD_LAST',
55
+ M: 'US_MARKET_CENTER_CLOSE_PRICE',
56
+ N: 'US_NEXT_DAY_TRADE',
57
+ O: 'US_MARKET_CENTER_OPENING_TRADE',
58
+ P: 'US_PRIOR_REFERENCE_PRICE',
59
+ Q: 'US_MARKET_CENTER_OPEN_PRICE',
60
+ R: 'US_SELLER',
61
+ T: 'US_FORM_T',
62
+ U: 'US_EXTENDED_TRADING_HOURS',
63
+ V: 'US_CONTINGENT_TRADE',
64
+ W: 'US_AVERAGE_PRICE_TRADE',
65
+ X: 'US_CROSS_TRADE',
66
+ Z: 'US_SOLD_OUT_OF_SEQUENCE',
67
+ '0': 'US_ODD_LOST_CROSS_TRADE',
68
+ '4': 'US_DERIVATIVELY_PRICED',
69
+ '5': 'US_MARKET_CENTER_RE_OPENING_TRADE',
70
+ '6': 'US_MARKET_CENTER_CLOSING_TRADE',
71
+ '7': 'US_QUALIFIED_CONTINGENT_TRADE',
72
+ '9': 'US_CONSOLIDATED_LAST_PRICE_PER_LISTING_PACKET',
73
+ };
74
+ const HK_TRADE_COND = {
75
+ ' ': 'HK_AUTOMATCH_NORMAL',
76
+ D: 'HK_ODD_LOT_TRADE',
77
+ U: 'HK_AUCTION_TRADE',
78
+ '*': 'HK_OVERSEAS_TRADE',
79
+ P: 'HK_LATE_TRADE_OFF_EXCHG',
80
+ M: 'HK_NON_DIRECT_OFF_EXCHG_TRADE',
81
+ X: 'HK_DIRECT_OFF_EXCHG_TRADE',
82
+ Y: 'HK_AUTOMATIC_INTERNALIZED',
83
+ };
84
+ /** Returns the full exchange name for a partCode letter, or the raw code if unknown. */
85
+ export function getPartNameByCode(code) {
86
+ if (!code)
87
+ return code;
88
+ return PART_CODE_NAME_MAP[code] ?? code;
89
+ }
90
+ /** Returns the short exchange name for a partCode letter, or the raw code if unknown. */
91
+ export function getPartShortNameByCode(code) {
92
+ if (!code)
93
+ return code;
94
+ return PART_CODE_SHORT_NAME_MAP[code] ?? code;
95
+ }
96
+ /** Resolves a raw cond character to a readable string. */
97
+ export function getTradeCondByCode(isUs, ch) {
98
+ const map = isUs ? US_TRADE_COND : HK_TRADE_COND;
99
+ return map[ch] ?? ch;
100
+ }
101
+ const US_SYMBOL_RE = /^[A-Z]+(\.[A-Z0-9]+)?$/;
102
+ /** Reports whether symbol is a US stock (uppercase letters, optional dot suffix). */
103
+ export function isUsStockSymbol(symbol) {
104
+ return US_SYMBOL_RE.test(symbol);
105
+ }
106
+ function isUsSymbol(symbol) {
107
+ return US_SYMBOL_RE.test(symbol);
108
+ }
109
+ function getTradeCond(isUs, ch) {
110
+ const map = isUs ? US_TRADE_COND : HK_TRADE_COND;
111
+ return map[ch] ?? ch;
112
+ }
113
+ /** Decodes a TradeTickData pb message into a PushTradeTick with resolved partCode/partName. */
114
+ export function convertTradeTick(src) {
115
+ if (src.secType === 'FUT')
116
+ return convertFutureTick(src);
117
+ return convertStockTick(src);
118
+ }
119
+ function convertStockTick(src) {
120
+ const isUs = isUsSymbol(src.symbol);
121
+ const denominator = Math.pow(10, src.priceOffset);
122
+ const ticks = [];
123
+ let currentTime = 0;
124
+ for (let i = 0; i < src.time.length; i++) {
125
+ currentTime += src.time[i];
126
+ const condCh = src.cond.length > i ? src.cond[i] : ' ';
127
+ const rawCode = i < src.partCode.length ? src.partCode[i] : '';
128
+ ticks.push({
129
+ sn: src.sn + i,
130
+ time: currentTime,
131
+ price: (src.priceBase + src.price[i]) / denominator,
132
+ volume: src.volume[i],
133
+ tickType: src.type.length > i ? src.type[i] : '',
134
+ cond: getTradeCond(isUs, condCh),
135
+ partCode: getPartShortNameByCode(rawCode),
136
+ partName: getPartNameByCode(rawCode),
137
+ });
138
+ }
139
+ return { symbol: src.symbol, secType: src.secType, quoteLevel: src.quoteLevel, timestamp: src.timestamp, ticks };
140
+ }
141
+ function convertFutureTick(src) {
142
+ const denominator = Math.pow(10, src.priceOffset);
143
+ const ticks = [];
144
+ let currentTime = 0;
145
+ let startSn = src.sn;
146
+ for (let i = 0; i < src.time.length; i++) {
147
+ currentTime += src.time[i];
148
+ const curPrice = (src.priceBase + src.price[i]) / denominator;
149
+ const mv = src.mergedVols[i];
150
+ for (let j = 0; j < mv.vol.length; j++) {
151
+ ticks.push({
152
+ sn: startSn * 10 + j,
153
+ time: currentTime,
154
+ price: curPrice,
155
+ volume: mv.vol[j],
156
+ tickType: '',
157
+ cond: '',
158
+ partCode: '',
159
+ partName: '',
160
+ });
161
+ }
162
+ startSn++;
163
+ }
164
+ return { symbol: src.symbol, secType: src.secType, quoteLevel: '', timestamp: src.timestamp, ticks };
165
+ }
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Quote module exports
3
3
  */
4
- export { QuoteClient, parseOptionIdentifier } from './quote-client';
4
+ export { QuoteClient, parseOptionIdentifier } from './quote-client.js';