@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
@@ -7,7 +7,7 @@ const errors_1 = require("./errors");
7
7
  const retry_1 = require("./retry");
8
8
  const api_response_1 = require("./api-response");
9
9
  /** SDK 版本号 */
10
- const SDK_VERSION = '0.1.0';
10
+ const SDK_VERSION = '0.4.0';
11
11
  /** User-Agent 字符串 */
12
12
  const USER_AGENT = `openapi-typescript-sdk-${SDK_VERSION}`;
13
13
  /** 默认字符集 */
package/dist/cjs/index.js CHANGED
@@ -18,4 +18,4 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.VERSION = void 0;
20
20
  /** SDK 版本号 */
21
- exports.VERSION = '0.3.0';
21
+ exports.VERSION = '0.4.0';
@@ -4,7 +4,8 @@
4
4
  * 所有枚举值与 API JSON 保持一致
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.TimeInForce = exports.License = exports.QuoteRight = exports.Language = exports.BarPeriod = exports.OrderStatus = exports.OrderType = exports.Currency = exports.SecurityType = exports.Market = void 0;
7
+ exports.FinancialReportPeriod = exports.OptionAnalysisPeriod = exports.SortDirection = exports.IndustryLevel = exports.CorporateActionType = exports.SegmentType = exports.OrderSortBy = exports.TimeInForce = exports.License = exports.QuoteRight = exports.Language = exports.BarPeriod = exports.OrderStatus = exports.OrderType = exports.Currency = exports.SecurityType = exports.Market = void 0;
8
+ exports.orderStatusCode = orderStatusCode;
8
9
  /** 市场枚举 */
9
10
  var Market;
10
11
  (function (Market) {
@@ -51,19 +52,49 @@ var OrderType;
51
52
  OrderType["VWAP"] = "VWAP";
52
53
  OrderType["OCA"] = "OCA";
53
54
  })(OrderType || (exports.OrderType = OrderType = {}));
54
- /** 订单状态枚举 */
55
+ /**
56
+ * 订单状态枚举。对齐 Java SDK OrderStatus 定义。
57
+ *
58
+ * 服务端 wire 返回的值同时可能是:
59
+ * - 数字: -2 / -1 / 3 / 4 / 5 / 6 / 7 / 8
60
+ * - 字符串: "Invalid" / "Initial" / "PendingCancel" / "Cancelled" /
61
+ * "Submitted" / "Filled" / "Inactive" / "PendingSubmit"
62
+ *
63
+ * Client 层通过 normalizeOrderStatus() 做数字→字符串归一,不做跨别名合并。
64
+ */
55
65
  var OrderStatus;
56
66
  (function (OrderStatus) {
57
- OrderStatus["PendingNew"] = "PendingNew";
67
+ OrderStatus["Invalid"] = "Invalid";
58
68
  OrderStatus["Initial"] = "Initial";
69
+ OrderStatus["PendingCancel"] = "PendingCancel";
70
+ OrderStatus["Cancelled"] = "Cancelled";
59
71
  OrderStatus["Submitted"] = "Submitted";
60
- OrderStatus["PartiallyFilled"] = "PartiallyFilled";
61
72
  OrderStatus["Filled"] = "Filled";
62
- OrderStatus["Cancelled"] = "Cancelled";
63
- OrderStatus["PendingCancel"] = "PendingCancel";
64
73
  OrderStatus["Inactive"] = "Inactive";
65
- OrderStatus["Invalid"] = "Invalid";
74
+ OrderStatus["PendingSubmit"] = "PendingSubmit";
66
75
  })(OrderStatus || (exports.OrderStatus = OrderStatus = {}));
76
+ /** 返回订单状态对应的服务端数字码,未知返回 0。 */
77
+ function orderStatusCode(status) {
78
+ switch (status) {
79
+ case OrderStatus.Invalid:
80
+ return -2;
81
+ case OrderStatus.Initial:
82
+ return -1;
83
+ case OrderStatus.PendingCancel:
84
+ return 3;
85
+ case OrderStatus.Cancelled:
86
+ return 4;
87
+ case OrderStatus.Submitted:
88
+ return 5;
89
+ case OrderStatus.Filled:
90
+ return 6;
91
+ case OrderStatus.Inactive:
92
+ return 7;
93
+ case OrderStatus.PendingSubmit:
94
+ return 8;
95
+ }
96
+ return 0;
97
+ }
67
98
  /** K 线周期枚举 */
68
99
  var BarPeriod;
69
100
  (function (BarPeriod) {
@@ -108,3 +139,54 @@ var TimeInForce;
108
139
  TimeInForce["GTC"] = "GTC";
109
140
  TimeInForce["OPG"] = "OPG";
110
141
  })(TimeInForce || (exports.TimeInForce = TimeInForce = {}));
142
+ /** 订单排序字段 */
143
+ var OrderSortBy;
144
+ (function (OrderSortBy) {
145
+ OrderSortBy["LatestCreated"] = "LATEST_CREATED";
146
+ OrderSortBy["LatestStatusUpdated"] = "LATEST_STATUS_UPDATED";
147
+ })(OrderSortBy || (exports.OrderSortBy = OrderSortBy = {}));
148
+ /** 账户分部类型 */
149
+ var SegmentType;
150
+ (function (SegmentType) {
151
+ SegmentType["All"] = "ALL";
152
+ SegmentType["Sec"] = "SEC";
153
+ SegmentType["Fut"] = "FUT";
154
+ SegmentType["Fund"] = "FUND";
155
+ })(SegmentType || (exports.SegmentType = SegmentType = {}));
156
+ /** 公司行动类型 */
157
+ var CorporateActionType;
158
+ (function (CorporateActionType) {
159
+ CorporateActionType["Split"] = "split";
160
+ CorporateActionType["Dividend"] = "dividend";
161
+ CorporateActionType["Earning"] = "earning";
162
+ })(CorporateActionType || (exports.CorporateActionType = CorporateActionType = {}));
163
+ /** 行业级别 (1~4 级) */
164
+ var IndustryLevel;
165
+ (function (IndustryLevel) {
166
+ IndustryLevel["GSector"] = "GSECTOR";
167
+ IndustryLevel["GGroup"] = "GGROUP";
168
+ IndustryLevel["GInd"] = "GIND";
169
+ IndustryLevel["GSubInd"] = "GSUBIND";
170
+ })(IndustryLevel || (exports.IndustryLevel = IndustryLevel = {}));
171
+ /** 排序方向 */
172
+ var SortDirection;
173
+ (function (SortDirection) {
174
+ SortDirection["No"] = "SortDir_No";
175
+ SortDirection["Ascend"] = "SortDir_Ascend";
176
+ SortDirection["Descend"] = "SortDir_Descend";
177
+ })(SortDirection || (exports.SortDirection = SortDirection = {}));
178
+ /** 期权分析周期 */
179
+ var OptionAnalysisPeriod;
180
+ (function (OptionAnalysisPeriod) {
181
+ OptionAnalysisPeriod["ThreeYear"] = "3year";
182
+ OptionAnalysisPeriod["FiftyTwoWeek"] = "52week";
183
+ OptionAnalysisPeriod["TwentySixWeek"] = "26week";
184
+ OptionAnalysisPeriod["ThirteenWeek"] = "13week";
185
+ })(OptionAnalysisPeriod || (exports.OptionAnalysisPeriod = OptionAnalysisPeriod = {}));
186
+ /** 财报类型 */
187
+ var FinancialReportPeriod;
188
+ (function (FinancialReportPeriod) {
189
+ FinancialReportPeriod["Annual"] = "Annual";
190
+ FinancialReportPeriod["Quarterly"] = "Quarterly";
191
+ FinancialReportPeriod["LTM"] = "LTM";
192
+ })(FinancialReportPeriod || (exports.FinancialReportPeriod = FinancialReportPeriod = {}));
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Order status normalization.
4
+ *
5
+ * 服务端返回的订单状态有时是整数(-2/-1/3/4/5/6/7/8),有时是字符串
6
+ * ("Invalid"/"Submitted"/...)。本模块把二者统一为 Java SDK OrderStatus 的
7
+ * 字符串值。不做跨别名合并。
8
+ *
9
+ * 对齐 Java SDK OrderStatus.java。
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.normalizeOrderStatus = normalizeOrderStatus;
13
+ const enums_1 = require("./enums");
14
+ /** 把数字状态码映射到字符串,未识别返回空串。 */
15
+ function statusIntToString(n) {
16
+ switch (n) {
17
+ case -2:
18
+ return enums_1.OrderStatus.Invalid;
19
+ case -1:
20
+ return enums_1.OrderStatus.Initial;
21
+ case 3:
22
+ return enums_1.OrderStatus.PendingCancel;
23
+ case 4:
24
+ return enums_1.OrderStatus.Cancelled;
25
+ case 5:
26
+ return enums_1.OrderStatus.Submitted;
27
+ case 6:
28
+ return enums_1.OrderStatus.Filled;
29
+ case 7:
30
+ return enums_1.OrderStatus.Inactive;
31
+ case 8:
32
+ return enums_1.OrderStatus.PendingSubmit;
33
+ }
34
+ return '';
35
+ }
36
+ /**
37
+ * 把服务端可能返回的 string/number 订单状态归一为字符串。
38
+ * 字符串原样透传;数字按映射表转换;其他输入返回空串。
39
+ */
40
+ function normalizeOrderStatus(raw) {
41
+ if (typeof raw === 'string')
42
+ return raw;
43
+ if (typeof raw === 'number')
44
+ return statusIntToString(raw);
45
+ return '';
46
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ /**
3
+ * Quote request interfaces (v0.4.0).
4
+ *
5
+ * 所有字段可选(用户调用时传一个空对象即可);字段名用 camelCase,
6
+ * client 层通过 keysToSnakeCase 转成服务端 wire 真名的 snake_case。
7
+ * **字段名设计规则:camelCase → snake_case 后必须等于服务端 wire 真名。**
8
+ *
9
+ * 参考 Go SDK model/quote_requests.go。
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Trade request interfaces (v0.4.0).
4
+ *
5
+ * 所有字段可选(用户调用时传一个空对象即可);字段名用 camelCase,
6
+ * client 层通过 keysToSnakeCase 转成服务端 wire 真名的 snake_case。
7
+ * **字段名设计规则:camelCase → snake_case 后必须等于服务端 wire 真名。**
8
+ * 比如 Trade 用 `startDate`/`endDate`(wire `start_date`/`end_date`),
9
+ * 不用 `startTime`/`endTime`(会被转成 `start_time`/`end_time`,与 wire 不符)。
10
+ *
11
+ * 参考 Go SDK model/trade_requests.go。
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -54,6 +54,8 @@ function createBaseOrderStatusData() {
54
54
  gst: 0,
55
55
  attrList: [],
56
56
  timeInForce: "",
57
+ updateTime: 0,
58
+ latestTime: 0,
57
59
  };
58
60
  }
59
61
  exports.OrderStatusData = {
@@ -187,6 +189,12 @@ exports.OrderStatusData = {
187
189
  if (message.timeInForce !== "") {
188
190
  writer.uint32(346).string(message.timeInForce);
189
191
  }
192
+ if (message.updateTime !== 0) {
193
+ writer.uint32(352).uint64(message.updateTime);
194
+ }
195
+ if (message.latestTime !== 0) {
196
+ writer.uint32(360).uint64(message.latestTime);
197
+ }
190
198
  return writer;
191
199
  },
192
200
  decode(input, length) {
@@ -497,6 +505,20 @@ exports.OrderStatusData = {
497
505
  message.timeInForce = reader.string();
498
506
  continue;
499
507
  }
508
+ case 44: {
509
+ if (tag !== 352) {
510
+ break;
511
+ }
512
+ message.updateTime = longToNumber(reader.uint64());
513
+ continue;
514
+ }
515
+ case 45: {
516
+ if (tag !== 360) {
517
+ break;
518
+ }
519
+ message.latestTime = longToNumber(reader.uint64());
520
+ continue;
521
+ }
500
522
  }
501
523
  if ((tag & 7) === 4 || tag === 0) {
502
524
  break;
@@ -553,6 +575,8 @@ exports.OrderStatusData = {
553
575
  message.gst = object.gst ?? 0;
554
576
  message.attrList = object.attrList?.map((e) => e) || [];
555
577
  message.timeInForce = object.timeInForce ?? "";
578
+ message.updateTime = object.updateTime ?? 0;
579
+ message.latestTime = object.latestTime ?? 0;
556
580
  return message;
557
581
  },
558
582
  };
@@ -123,6 +123,12 @@ function subjectToDataType(subject) {
123
123
  return SocketCommon_1.SocketCommon_DataType.TradeTick;
124
124
  case push_message_1.SubjectType.QuoteBBO:
125
125
  return SocketCommon_1.SocketCommon_DataType.Quote;
126
+ case push_message_1.SubjectType.Cc:
127
+ // 加密货币推送
128
+ return SocketCommon_1.SocketCommon_DataType.Cc;
129
+ case push_message_1.SubjectType.Market:
130
+ // 市场状态推送协议上 dataType=Quote,只设置 market 字段
131
+ return SocketCommon_1.SocketCommon_DataType.Quote;
126
132
  default:
127
133
  return SocketCommon_1.SocketCommon_DataType.Unknown;
128
134
  }
@@ -65,7 +65,7 @@ const MAX_RECONNECT_INTERVAL = 60000;
65
65
  /** Default connect timeout (ms) */
66
66
  const DEFAULT_CONNECT_TIMEOUT = 30000;
67
67
  /** SDK version identifier */
68
- const SDK_VERSION = 'typescript/0.1.0';
68
+ const SDK_VERSION = 'typescript/0.4.0';
69
69
  /** Protocol version */
70
70
  const ACCEPT_VERSION = '1.0';
71
71
  /** Default send heartbeat interval (ms) */
@@ -387,6 +387,11 @@ class PushClient {
387
387
  if (pushData.klineData)
388
388
  cb.onKline?.(pushData.klineData);
389
389
  break;
390
+ case SocketCommon_1.SocketCommon_DataType.Cc:
391
+ // 加密货币(Cc)推送复用 QuoteData body,路由到 onQuote 回调
392
+ if (pushData.quoteData)
393
+ cb.onQuote?.(pushData.quoteData);
394
+ break;
390
395
  default:
391
396
  // FullTick and QuoteBBO use TradeTick/Quote dataType
392
397
  // TickData (fullTick) via tickData field
@@ -493,6 +498,71 @@ class PushClient {
493
498
  this.doUnsubscribe(push_message_1.SubjectType.Kline, symbols);
494
499
  this.removeSubscription(push_message_1.SubjectType.Kline, symbols);
495
500
  }
501
+ // ===== v0.4.0: stock_top / option_top / cc / market =====
502
+ /**
503
+ * Subscribe to stock top rankings (v0.4.0).
504
+ * @param market US / HK / CN
505
+ * @param indicators LATEST_PRICE / HIGHER / LOWER / VOLUME / AMOUNT / AMPLITUDE / TURNOVER_RATE
506
+ */
507
+ subscribeStockTop(market, indicators) {
508
+ this.doSubscribe(push_message_1.SubjectType.StockTop, indicators, undefined, market);
509
+ this.addSubscription(push_message_1.SubjectType.StockTop, indicators);
510
+ }
511
+ /** Unsubscribe from stock top rankings (v0.4.0). */
512
+ unsubscribeStockTop(market, indicators) {
513
+ const dataType = (0, proto_message_1.subjectToDataType)(push_message_1.SubjectType.StockTop);
514
+ const symbolsStr = indicators.join(',');
515
+ const req = (0, proto_message_1.buildUnSubscribeMessage)(dataType, symbolsStr, undefined, market);
516
+ this.sendMessage(req);
517
+ this.removeSubscription(push_message_1.SubjectType.StockTop, indicators);
518
+ }
519
+ /**
520
+ * Subscribe to option top rankings (v0.4.0).
521
+ * @param market US / HK / CN
522
+ */
523
+ subscribeOptionTop(market, indicators) {
524
+ this.doSubscribe(push_message_1.SubjectType.OptionTop, indicators, undefined, market);
525
+ this.addSubscription(push_message_1.SubjectType.OptionTop, indicators);
526
+ }
527
+ /** Unsubscribe from option top rankings (v0.4.0). */
528
+ unsubscribeOptionTop(market, indicators) {
529
+ const dataType = (0, proto_message_1.subjectToDataType)(push_message_1.SubjectType.OptionTop);
530
+ const symbolsStr = indicators.join(',');
531
+ const req = (0, proto_message_1.buildUnSubscribeMessage)(dataType, symbolsStr, undefined, market);
532
+ this.sendMessage(req);
533
+ this.removeSubscription(push_message_1.SubjectType.OptionTop, indicators);
534
+ }
535
+ /**
536
+ * Subscribe to crypto realtime quotes (v0.4.0).
537
+ * Data is delivered via the `onQuote` callback (same QuoteData body).
538
+ * @param symbols e.g. ["BTCUSD", "ETHUSD"]
539
+ */
540
+ subscribeCc(symbols) {
541
+ this.doSubscribe(push_message_1.SubjectType.Cc, symbols);
542
+ this.addSubscription(push_message_1.SubjectType.Cc, symbols);
543
+ }
544
+ /** Unsubscribe from crypto realtime quotes (v0.4.0). */
545
+ unsubscribeCc(symbols) {
546
+ this.doUnsubscribe(push_message_1.SubjectType.Cc, symbols);
547
+ this.removeSubscription(push_message_1.SubjectType.Cc, symbols);
548
+ }
549
+ /**
550
+ * Subscribe to market status updates (v0.4.0).
551
+ * Protocol uses dataType=Quote with only the `market` field set.
552
+ * Data is delivered via the `onQuote` callback.
553
+ */
554
+ subscribeMarket(market) {
555
+ // symbols 为空,只带 market 字段
556
+ this.doSubscribe(push_message_1.SubjectType.Market, undefined, undefined, market);
557
+ this.addSubscription(push_message_1.SubjectType.Market, [market]);
558
+ }
559
+ /** Unsubscribe from market status (v0.4.0). */
560
+ unsubscribeMarket(market) {
561
+ const dataType = (0, proto_message_1.subjectToDataType)(push_message_1.SubjectType.Market);
562
+ const req = (0, proto_message_1.buildUnSubscribeMessage)(dataType, undefined, undefined, market);
563
+ this.sendMessage(req);
564
+ this.removeSubscription(push_message_1.SubjectType.Market, [market]);
565
+ }
496
566
  // ===== Account push subscribe/unsubscribe =====
497
567
  /** Subscribe to asset changes */
498
568
  subscribeAsset(account) {
@@ -20,6 +20,10 @@ var SubjectType;
20
20
  SubjectType["OptionTop"] = "option_top";
21
21
  SubjectType["FullTick"] = "full_tick";
22
22
  SubjectType["QuoteBBO"] = "quote_bbo";
23
+ /** 加密货币实时行情 (v0.4.0) */
24
+ SubjectType["Cc"] = "cc";
25
+ /** 市场状态 (v0.4.0) */
26
+ SubjectType["Market"] = "market";
23
27
  SubjectType["Asset"] = "asset";
24
28
  SubjectType["Position"] = "position";
25
29
  SubjectType["Order"] = "order";