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
@@ -70,34 +70,34 @@ function parsePropertiesString(content) {
70
70
  let continuation = false;
71
71
  for (const rawLine of lines) {
72
72
  if (continuation) {
73
- // 续行:去除前导空格后拼接
74
73
  const trimmedLeft = rawLine.replace(/^[ \t]+/, '');
75
- if (trimmedLeft.endsWith('\\')) {
74
+ if (trimmedLeft === '' || trimmedLeft.startsWith('#') || trimmedLeft.startsWith('!')) {
75
+ continuation = false;
76
+ }
77
+ else if (endsWithContinuation(trimmedLeft)) {
76
78
  currentLine += trimmedLeft.slice(0, -1);
77
79
  continue;
78
80
  }
79
- currentLine += trimmedLeft;
80
- continuation = false;
81
+ else {
82
+ currentLine += trimmedLeft;
83
+ continuation = false;
84
+ }
81
85
  }
82
86
  else {
83
87
  const trimmed = rawLine.trim();
84
- // 跳过空行
85
88
  if (trimmed === '') {
86
89
  continue;
87
90
  }
88
- // 跳过注释行
89
91
  if (trimmed.startsWith('#') || trimmed.startsWith('!')) {
90
92
  continue;
91
93
  }
92
- // 检查续行
93
- if (trimmed.endsWith('\\')) {
94
+ if (endsWithContinuation(trimmed)) {
94
95
  currentLine = trimmed.slice(0, -1);
95
96
  continuation = true;
96
97
  continue;
97
98
  }
98
99
  currentLine = trimmed;
99
100
  }
100
- // 解析键值对
101
101
  const result = parseKeyValue(currentLine);
102
102
  if (result) {
103
103
  props[result[0]] = result[1];
@@ -113,6 +113,16 @@ function parsePropertiesString(content) {
113
113
  }
114
114
  return props;
115
115
  }
116
+ /**
117
+ * 判断一行是否以续行标记结尾(奇数个末尾反斜杠)。
118
+ */
119
+ function endsWithContinuation(line) {
120
+ let count = 0;
121
+ for (let i = line.length - 1; i >= 0 && line[i] === '\\'; i--) {
122
+ count++;
123
+ }
124
+ return count % 2 === 1;
125
+ }
116
126
  /**
117
127
  * 解析单行键值对,支持 = 和 : 分隔符。
118
128
  * 值中可以包含 = 或 :,只按第一个分隔符拆分。
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveDynamicQuoteServerUrl = exports.resolveDynamicServerUrl = exports.queryDomains = exports.loadPropertiesFile = exports.createClientConfig = exports.parsePropertiesString = exports.parsePropertiesFile = void 0;
3
+ exports.resolveDynamicQuoteServerUrl = exports.resolveDynamicServerUrl = exports.queryDomains = exports.TokenManager = exports.SANDBOX_TIGER_PUBLIC_KEY = exports.loadPropertiesFile = exports.createClientConfig = exports.parsePropertiesString = exports.parsePropertiesFile = void 0;
4
4
  /**
5
5
  * 配置层导出
6
6
  */
@@ -10,6 +10,9 @@ Object.defineProperty(exports, "parsePropertiesString", { enumerable: true, get:
10
10
  var client_config_1 = require("./client-config");
11
11
  Object.defineProperty(exports, "createClientConfig", { enumerable: true, get: function () { return client_config_1.createClientConfig; } });
12
12
  Object.defineProperty(exports, "loadPropertiesFile", { enumerable: true, get: function () { return client_config_1.loadPropertiesFile; } });
13
+ Object.defineProperty(exports, "SANDBOX_TIGER_PUBLIC_KEY", { enumerable: true, get: function () { return client_config_1.SANDBOX_TIGER_PUBLIC_KEY; } });
14
+ var token_manager_1 = require("./token-manager");
15
+ Object.defineProperty(exports, "TokenManager", { enumerable: true, get: function () { return token_manager_1.TokenManager; } });
13
16
  var domain_1 = require("./domain");
14
17
  Object.defineProperty(exports, "queryDomains", { enumerable: true, get: function () { return domain_1.queryDomains; } });
15
18
  Object.defineProperty(exports, "resolveDynamicServerUrl", { enumerable: true, get: function () { return domain_1.resolveDynamicServerUrl; } });
@@ -21,6 +21,7 @@ class TokenManager {
21
21
  constructor(options) {
22
22
  this.token = '';
23
23
  this.timer = null;
24
+ this.fileEnabled = options?.filePath !== undefined;
24
25
  this.filePath = options?.filePath ?? DEFAULT_TOKEN_FILE;
25
26
  this.refreshInterval = options?.refreshInterval ?? DEFAULT_REFRESH_INTERVAL;
26
27
  let dur = options?.refreshDuration ?? 0;
@@ -28,9 +29,39 @@ class TokenManager {
28
29
  dur = 30;
29
30
  }
30
31
  this.refreshDuration = dur;
32
+ this.tokenLoader = options?.tokenLoader;
33
+ this.tokenWriter = options?.tokenWriter;
31
34
  }
32
- /** 从 properties 文件加载 Token */
33
- loadToken() {
35
+ /**
36
+ * 从 properties 文件(或自定义 tokenLoader)加载 Token。
37
+ * 若设置了 tokenLoader,优先调用;否则从 properties 文件读取。
38
+ */
39
+ async loadToken() {
40
+ if (this.tokenLoader) {
41
+ const token = await this.tokenLoader();
42
+ if (!token) {
43
+ throw new Error('自定义 tokenLoader 返回空值');
44
+ }
45
+ this.token = token;
46
+ return token;
47
+ }
48
+ const content = (0, fs_1.readFileSync)(this.filePath, 'utf-8');
49
+ const props = (0, config_parser_1.parsePropertiesString)(content);
50
+ const token = props['token'];
51
+ if (!token) {
52
+ throw new Error('Token 文件中未找到 token 字段');
53
+ }
54
+ this.token = token;
55
+ return token;
56
+ }
57
+ /**
58
+ * 同步版文件加载(仅用于无 tokenLoader 时的兼容入口)。
59
+ * 建议优先使用 loadToken()(异步)。
60
+ */
61
+ loadTokenSync() {
62
+ if (this.tokenLoader) {
63
+ throw new Error('tokenLoader 是异步函数,请使用 loadToken()');
64
+ }
34
65
  const content = (0, fs_1.readFileSync)(this.filePath, 'utf-8');
35
66
  const props = (0, config_parser_1.parsePropertiesString)(content);
36
67
  const token = props['token'];
@@ -44,10 +75,25 @@ class TokenManager {
44
75
  getToken() {
45
76
  return this.token;
46
77
  }
47
- /** 设置 Token 并更新文件 */
78
+ /**
79
+ * 设置 Token;若启用了文件持久化(显式传入 filePath),则同步写文件。
80
+ * 成功后触发 tokenWriter 回调(如有)。
81
+ */
48
82
  setToken(token) {
49
83
  this.token = token;
50
- this.saveTokenToFile(token);
84
+ if (this.fileEnabled) {
85
+ this.saveTokenToFile(token);
86
+ }
87
+ if (this.tokenWriter) {
88
+ this.tokenWriter(token);
89
+ }
90
+ }
91
+ /**
92
+ * 仅更新内存中的 token,不写文件,不触发 tokenWriter 回调。
93
+ * 用于多个组件共享 token 时的内部同步。
94
+ */
95
+ syncToken(token) {
96
+ this.token = token;
51
97
  }
52
98
  /** 将 Token 保存到 properties 文件 */
53
99
  saveTokenToFile(token) {
@@ -104,6 +150,10 @@ class TokenManager {
104
150
  // 刷新失败时静默跳过
105
151
  }
106
152
  }, this.refreshInterval);
153
+ // 防止 timer 阻止 Node.js 进程退出
154
+ if (this.timer.unref) {
155
+ this.timer.unref();
156
+ }
107
157
  }
108
158
  /** 停止后台刷新 */
109
159
  stopAutoRefresh() {
package/dist/cjs/index.js CHANGED
@@ -16,6 +16,57 @@
16
16
  * @packageDocumentation
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.VERSION = void 0;
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.SANDBOX_TIGER_PUBLIC_KEY = exports.loadPropertiesFile = exports.createClientConfig = exports.VERSION = void 0;
20
20
  /** SDK 版本号 */
21
- exports.VERSION = '0.4.0';
21
+ var version_1 = require("./version");
22
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.SDK_VERSION; } });
23
+ // Config
24
+ var config_1 = require("./config");
25
+ Object.defineProperty(exports, "createClientConfig", { enumerable: true, get: function () { return config_1.createClientConfig; } });
26
+ Object.defineProperty(exports, "loadPropertiesFile", { enumerable: true, get: function () { return config_1.loadPropertiesFile; } });
27
+ Object.defineProperty(exports, "SANDBOX_TIGER_PUBLIC_KEY", { enumerable: true, get: function () { return config_1.SANDBOX_TIGER_PUBLIC_KEY; } });
28
+ var config_2 = require("./config");
29
+ Object.defineProperty(exports, "TokenManager", { enumerable: true, get: function () { return config_2.TokenManager; } });
30
+ // Transport
31
+ var client_1 = require("./client");
32
+ Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return client_1.HttpClient; } });
33
+ var client_2 = require("./client");
34
+ Object.defineProperty(exports, "TigerError", { enumerable: true, get: function () { return client_2.TigerError; } });
35
+ Object.defineProperty(exports, "classifyErrorCode", { enumerable: true, get: function () { return client_2.classifyErrorCode; } });
36
+ // Clients
37
+ var quote_1 = require("./quote");
38
+ Object.defineProperty(exports, "QuoteClient", { enumerable: true, get: function () { return quote_1.QuoteClient; } });
39
+ Object.defineProperty(exports, "parseOptionIdentifier", { enumerable: true, get: function () { return quote_1.parseOptionIdentifier; } });
40
+ var trade_1 = require("./trade");
41
+ Object.defineProperty(exports, "TradeClient", { enumerable: true, get: function () { return trade_1.TradeClient; } });
42
+ var push_1 = require("./push");
43
+ Object.defineProperty(exports, "PushClient", { enumerable: true, get: function () { return push_1.PushClient; } });
44
+ Object.defineProperty(exports, "ConnectionState", { enumerable: true, get: function () { return push_1.ConnectionState; } });
45
+ Object.defineProperty(exports, "SubjectType", { enumerable: true, get: function () { return push_1.SubjectType; } });
46
+ var order_helpers_1 = require("./model/order-helpers");
47
+ Object.defineProperty(exports, "marketOrder", { enumerable: true, get: function () { return order_helpers_1.marketOrder; } });
48
+ Object.defineProperty(exports, "limitOrder", { enumerable: true, get: function () { return order_helpers_1.limitOrder; } });
49
+ Object.defineProperty(exports, "stopOrder", { enumerable: true, get: function () { return order_helpers_1.stopOrder; } });
50
+ Object.defineProperty(exports, "stopLimitOrder", { enumerable: true, get: function () { return order_helpers_1.stopLimitOrder; } });
51
+ var order_status_1 = require("./model/order-status");
52
+ Object.defineProperty(exports, "normalizeOrderStatus", { enumerable: true, get: function () { return order_status_1.normalizeOrderStatus; } });
53
+ // Enums
54
+ var enums_1 = require("./model/enums");
55
+ Object.defineProperty(exports, "OrderStatus", { enumerable: true, get: function () { return enums_1.OrderStatus; } });
56
+ Object.defineProperty(exports, "SecurityType", { enumerable: true, get: function () { return enums_1.SecurityType; } });
57
+ Object.defineProperty(exports, "OrderType", { enumerable: true, get: function () { return enums_1.OrderType; } });
58
+ Object.defineProperty(exports, "TimeInForce", { enumerable: true, get: function () { return enums_1.TimeInForce; } });
59
+ Object.defineProperty(exports, "Market", { enumerable: true, get: function () { return enums_1.Market; } });
60
+ Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return enums_1.Currency; } });
61
+ Object.defineProperty(exports, "QuoteRight", { enumerable: true, get: function () { return enums_1.QuoteRight; } });
62
+ Object.defineProperty(exports, "SegmentType", { enumerable: true, get: function () { return enums_1.SegmentType; } });
63
+ Object.defineProperty(exports, "OrderSortBy", { enumerable: true, get: function () { return enums_1.OrderSortBy; } });
64
+ Object.defineProperty(exports, "CorporateActionType", { enumerable: true, get: function () { return enums_1.CorporateActionType; } });
65
+ Object.defineProperty(exports, "IndustryLevel", { enumerable: true, get: function () { return enums_1.IndustryLevel; } });
66
+ Object.defineProperty(exports, "SortDirection", { enumerable: true, get: function () { return enums_1.SortDirection; } });
67
+ Object.defineProperty(exports, "OptionAnalysisPeriod", { enumerable: true, get: function () { return enums_1.OptionAnalysisPeriod; } });
68
+ Object.defineProperty(exports, "FinancialReportPeriod", { enumerable: true, get: function () { return enums_1.FinancialReportPeriod; } });
69
+ Object.defineProperty(exports, "Language", { enumerable: true, get: function () { return enums_1.Language; } });
70
+ Object.defineProperty(exports, "License", { enumerable: true, get: function () { return enums_1.License; } });
71
+ Object.defineProperty(exports, "BarPeriod", { enumerable: true, get: function () { return enums_1.BarPeriod; } });
72
+ Object.defineProperty(exports, "orderStatusCode", { enumerable: true, get: function () { return enums_1.orderStatusCode; } });
@@ -4,7 +4,7 @@
4
4
  * 所有枚举值与 API JSON 保持一致
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
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;
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.PriceType = exports.OrderType = exports.Currency = exports.SecurityType = exports.Market = void 0;
8
8
  exports.orderStatusCode = orderStatusCode;
9
9
  /** 市场枚举 */
10
10
  var Market;
@@ -51,7 +51,20 @@ var OrderType;
51
51
  OrderType["TWAP"] = "TWAP";
52
52
  OrderType["VWAP"] = "VWAP";
53
53
  OrderType["OCA"] = "OCA";
54
+ OrderType["ICEBERG"] = "ICEBERG";
54
55
  })(OrderType || (exports.OrderType = OrderType = {}));
56
+ /** 冰山单价格类型 */
57
+ var PriceType;
58
+ (function (PriceType) {
59
+ /** 限价 */
60
+ PriceType["LIMIT_PRICE"] = "LIMIT_PRICE";
61
+ /** 卖一价 */
62
+ PriceType["ASK_PRICE"] = "ASK_PRICE";
63
+ /** 买一价 */
64
+ PriceType["BID_PRICE"] = "BID_PRICE";
65
+ /** 最新价 */
66
+ PriceType["LATEST_PRICE"] = "LATEST_PRICE";
67
+ })(PriceType || (exports.PriceType = PriceType = {}));
55
68
  /**
56
69
  * 订单状态枚举。对齐 Java SDK OrderStatus 定义。
57
70
  *
@@ -137,6 +150,7 @@ var TimeInForce;
137
150
  (function (TimeInForce) {
138
151
  TimeInForce["DAY"] = "DAY";
139
152
  TimeInForce["GTC"] = "GTC";
153
+ TimeInForce["GTD"] = "GTD";
140
154
  TimeInForce["OPG"] = "OPG";
141
155
  })(TimeInForce || (exports.TimeInForce = TimeInForce = {}));
142
156
  /** 订单排序字段 */
@@ -159,6 +173,9 @@ var CorporateActionType;
159
173
  CorporateActionType["Split"] = "split";
160
174
  CorporateActionType["Dividend"] = "dividend";
161
175
  CorporateActionType["Earning"] = "earning";
176
+ CorporateActionType["SymbolChange"] = "symbol_change";
177
+ CorporateActionType["Delisting"] = "delisting";
178
+ CorporateActionType["IPO"] = "ipo";
162
179
  })(CorporateActionType || (exports.CorporateActionType = CorporateActionType = {}));
163
180
  /** 行业级别 (1~4 级) */
164
181
  var IndustryLevel;
@@ -8,7 +8,15 @@ exports.trailOrder = trailOrder;
8
8
  exports.auctionLimitOrder = auctionLimitOrder;
9
9
  exports.auctionMarketOrder = auctionMarketOrder;
10
10
  exports.algoOrder = algoOrder;
11
+ exports.icebergOrder = icebergOrder;
11
12
  exports.orderLeg = orderLeg;
13
+ exports.marketOrderByAmount = marketOrderByAmount;
14
+ exports.limitOrderByAmount = limitOrderByAmount;
15
+ exports.trailOrderByPrice = trailOrderByPrice;
16
+ exports.limitOrderWithLegs = limitOrderWithLegs;
17
+ exports.comboOrder = comboOrder;
18
+ exports.ocaOrder = ocaOrder;
19
+ exports.contractLeg = contractLeg;
12
20
  const enums_1 = require("./enums");
13
21
  /** Market order */
14
22
  function marketOrder(account, symbol, secType, action, quantity) {
@@ -98,7 +106,148 @@ function algoOrder(account, symbol, secType, action, quantity, limitPrice, algoT
98
106
  outsideRth: false,
99
107
  };
100
108
  }
109
+ /**
110
+ * Iceberg order. `displaySize` is required; all other parameters are optional.
111
+ * Pass `priceType` as empty string to use the server default (LIMIT_PRICE).
112
+ * Pass `startTime` / `endTime` as 0 to omit the time window.
113
+ */
114
+ function icebergOrder(account, symbol, secType, action, quantity, limitPrice, displaySize, minDisplaySize, checkIntervals, priceType, startTime, endTime) {
115
+ const req = {
116
+ account, symbol, secType, action,
117
+ orderType: enums_1.OrderType.ICEBERG,
118
+ totalQuantity: quantity,
119
+ limitPrice,
120
+ timeInForce: enums_1.TimeInForce.DAY,
121
+ outsideRth: false,
122
+ displaySize,
123
+ priceType: priceType || enums_1.PriceType.LIMIT_PRICE,
124
+ };
125
+ if (minDisplaySize !== undefined && minDisplaySize > 0)
126
+ req.minDisplaySize = minDisplaySize;
127
+ if (checkIntervals !== undefined && checkIntervals > 0)
128
+ req.checkIntervals = checkIntervals;
129
+ if (startTime && startTime > 0)
130
+ req.startTime = startTime;
131
+ if (endTime && endTime > 0)
132
+ req.endTime = endTime;
133
+ return req;
134
+ }
101
135
  /** Attached profit / loss leg */
102
136
  function orderLeg(legType, price, timeInForce) {
103
137
  return { legType, price, timeInForce };
104
138
  }
139
+ /**
140
+ * Market order by cash amount (instead of quantity).
141
+ * Server uses `isQuantityByAmount=true` + `amount` field.
142
+ */
143
+ function marketOrderByAmount(account, symbol, secType, action, amount) {
144
+ return {
145
+ account, symbol, secType, action,
146
+ orderType: enums_1.OrderType.MKT,
147
+ totalQuantity: 0,
148
+ cashAmount: amount,
149
+ timeInForce: enums_1.TimeInForce.DAY,
150
+ outsideRth: false,
151
+ };
152
+ }
153
+ /**
154
+ * Limit order by cash amount (instead of quantity).
155
+ */
156
+ function limitOrderByAmount(account, symbol, secType, action, amount, limitPrice) {
157
+ return {
158
+ account, symbol, secType, action,
159
+ orderType: enums_1.OrderType.LMT,
160
+ totalQuantity: 0,
161
+ cashAmount: amount,
162
+ limitPrice,
163
+ timeInForce: enums_1.TimeInForce.DAY,
164
+ outsideRth: false,
165
+ };
166
+ }
167
+ /**
168
+ * Trailing stop order using a fixed price offset (auxPrice) instead of a percentage.
169
+ * Use `trailOrder()` for percentage-based trailing stops.
170
+ */
171
+ function trailOrderByPrice(account, symbol, secType, action, quantity, auxPrice) {
172
+ return {
173
+ account, symbol, secType, action,
174
+ orderType: enums_1.OrderType.TRAIL,
175
+ totalQuantity: quantity,
176
+ auxPrice,
177
+ timeInForce: enums_1.TimeInForce.DAY,
178
+ outsideRth: false,
179
+ };
180
+ }
181
+ /**
182
+ * Limit order with attached profit/loss legs (bracket order).
183
+ * At most 2 legs are supported.
184
+ *
185
+ * @param orderLegs - Array of `OrderLegRequest` (use `orderLeg()` helper)
186
+ */
187
+ function limitOrderWithLegs(account, symbol, secType, action, quantity, limitPrice, orderLegs) {
188
+ if (orderLegs.length === 0) {
189
+ throw new Error('At least 1 order leg is required for a bracket order');
190
+ }
191
+ if (orderLegs.length > 2) {
192
+ throw new Error('At most 2 order legs are supported');
193
+ }
194
+ return {
195
+ account, symbol, secType, action,
196
+ orderType: enums_1.OrderType.LMT,
197
+ totalQuantity: quantity,
198
+ limitPrice,
199
+ orderLegs,
200
+ timeInForce: enums_1.TimeInForce.DAY,
201
+ outsideRth: false,
202
+ };
203
+ }
204
+ /**
205
+ * Multi-leg (combo/MLEG) order for options combos.
206
+ *
207
+ * @param contractLegs - Array of `ContractLegRequest` (use `contractLeg()` helper)
208
+ * @param comboType - e.g. `'MLEG'`
209
+ */
210
+ function comboOrder(account, action, quantity, orderType, contractLegs, comboType = 'MLEG', limitPrice, auxPrice, trailingPercent) {
211
+ return {
212
+ account,
213
+ symbol: '', // not used for combo orders
214
+ secType: 'MLEG',
215
+ action,
216
+ orderType,
217
+ totalQuantity: quantity,
218
+ limitPrice,
219
+ auxPrice,
220
+ trailingPercent,
221
+ contractLegs,
222
+ comboType,
223
+ timeInForce: enums_1.TimeInForce.DAY,
224
+ outsideRth: false,
225
+ };
226
+ }
227
+ /**
228
+ * OCA (One-Cancels-All) order.
229
+ * Server expects `orderType: 'OCA'` and an `ocaOrders` list.
230
+ *
231
+ * @param ocaOrders - The contained orders (use any order helper to build each)
232
+ */
233
+ function ocaOrder(account, symbol, secType, action, quantity, ocaOrders) {
234
+ return {
235
+ account, symbol, secType, action,
236
+ orderType: enums_1.OrderType.OCA,
237
+ totalQuantity: quantity,
238
+ ocaOrders,
239
+ timeInForce: enums_1.TimeInForce.DAY,
240
+ outsideRth: false,
241
+ };
242
+ }
243
+ /**
244
+ * Build a single leg for a multi-leg (MLEG / combo) order.
245
+ *
246
+ * @param symbol - Underlying symbol
247
+ * @param secType - Security type (e.g. `'OPT'`)
248
+ * @param action - `'BUY'` or `'SELL'`
249
+ * @param ratio - Number of contracts for this leg
250
+ */
251
+ function contractLeg(symbol, secType, action, ratio, expiry, strike, right) {
252
+ return { symbol, secType, action, ratio, expiry, strike, right };
253
+ }
@@ -22,6 +22,7 @@ var push_message_1 = require("./push-message");
22
22
  Object.defineProperty(exports, "SubjectType", { enumerable: true, get: function () { return push_message_1.SubjectType; } });
23
23
  __exportStar(require("./callbacks"), exports);
24
24
  __exportStar(require("./varint"), exports);
25
+ __exportStar(require("./tick-util"), exports);
25
26
  __exportStar(require("./proto-message"), exports);
26
27
  var push_client_1 = require("./push-client");
27
28
  Object.defineProperty(exports, "PushClient", { enumerable: true, get: function () { return push_client_1.PushClient; } });
@@ -47,6 +47,7 @@ exports.PushClient = exports.ConnectionState = void 0;
47
47
  const tls = __importStar(require("tls"));
48
48
  const signer_1 = require("../signer/signer");
49
49
  const push_message_1 = require("./push-message");
50
+ const tick_util_1 = require("./tick-util");
50
51
  const Request_1 = require("./pb/Request");
51
52
  const Response_1 = require("./pb/Response");
52
53
  const SocketCommon_1 = require("./pb/SocketCommon");
@@ -64,8 +65,9 @@ const DEFAULT_RECONNECT_INTERVAL = 5000;
64
65
  const MAX_RECONNECT_INTERVAL = 60000;
65
66
  /** Default connect timeout (ms) */
66
67
  const DEFAULT_CONNECT_TIMEOUT = 30000;
68
+ const version_1 = require("../version");
67
69
  /** SDK version identifier */
68
- const SDK_VERSION = 'typescript/0.4.0';
70
+ const SDK_VERSION = `typescript/${version_1.SDK_VERSION}`;
69
71
  /** Protocol version */
70
72
  const ACCEPT_VERSION = '1.0';
71
73
  /** Default send heartbeat interval (ms) */
@@ -86,11 +88,13 @@ class PushClient {
86
88
  constructor(config, options) {
87
89
  this.socket = null;
88
90
  this._state = ConnectionState.Disconnected;
91
+ /** Whether this connect attempt already fell back to unverified TLS */
92
+ this.tlsFallback = false;
89
93
  this.callbacks = {};
90
94
  /** Subscription state: subject -> Set<symbol> */
91
95
  this.subscriptions = new Map();
92
- /** Account-level subscriptions */
93
- this.accountSubs = new Set();
96
+ /** Account-level subscriptions: subject -> account string used at subscribe time */
97
+ this.accountSubs = new Map();
94
98
  this.heartbeatTimer = null;
95
99
  this.reconnectTimer = null;
96
100
  this.stopped = false;
@@ -124,6 +128,7 @@ class PushClient {
124
128
  }
125
129
  this._state = ConnectionState.Connecting;
126
130
  this.stopped = false;
131
+ this.tlsFallback = false;
127
132
  this.recvBuffer = Buffer.alloc(0);
128
133
  const socket = this.createSocket(this.pushHost, this.pushPort);
129
134
  this.socket = socket;
@@ -180,6 +185,24 @@ class PushClient {
180
185
  });
181
186
  socket.on('error', (err) => {
182
187
  if (!settled) {
188
+ // If this is a TLS certificate error, warn and retry without verification.
189
+ const isTlsCertError = err.message.includes('certificate') ||
190
+ err.message.includes('CERT') ||
191
+ err.code === 'DEPTH_ZERO_SELF_SIGNED_CERT' ||
192
+ err.code === 'UNABLE_TO_VERIFY_LEAF_SIGNATURE' ||
193
+ err.code === 'CERT_HAS_EXPIRED';
194
+ if (isTlsCertError && !this.tlsFallback) {
195
+ this.tlsFallback = true;
196
+ settled = true;
197
+ clearTimeout(timeout);
198
+ socket.destroy();
199
+ this.socket = null;
200
+ this._state = ConnectionState.Disconnected;
201
+ console.warn(`[TigerOpen] TLS certificate verification failed: ${err.message}. Retrying without verification.`);
202
+ // Retry immediately using unverified TLS
203
+ this.connect().then(resolve).catch(reject);
204
+ return;
205
+ }
183
206
  settled = true;
184
207
  clearTimeout(timeout);
185
208
  this._state = ConnectionState.Disconnected;
@@ -232,7 +255,7 @@ class PushClient {
232
255
  createSocket(host, port) {
233
256
  if (this.socketFactory)
234
257
  return this.socketFactory(host, port);
235
- return tls.connect({ host, port, rejectUnauthorized: false });
258
+ return tls.connect({ host, port, rejectUnauthorized: !this.tlsFallback });
236
259
  }
237
260
  /** Handle incoming TCP data: buffer + decode varint32 frames */
238
261
  handleData(chunk, onConnected) {
@@ -331,8 +354,8 @@ class PushClient {
331
354
  for (const [subject, symbols] of this.subscriptions) {
332
355
  this.doSubscribe(subject, Array.from(symbols));
333
356
  }
334
- for (const subject of this.accountSubs) {
335
- this.doSubscribe(subject, undefined, this.config.account);
357
+ for (const [subject, account] of this.accountSubs) {
358
+ this.doSubscribe(subject, undefined, account);
336
359
  }
337
360
  }
338
361
  /** Dispatch push data to the appropriate callback based on dataType */
@@ -356,8 +379,10 @@ class PushClient {
356
379
  cb.onDepth?.(pushData.quoteDepthData);
357
380
  break;
358
381
  case SocketCommon_1.SocketCommon_DataType.TradeTick:
382
+ if (pushData.tickData)
383
+ cb.onFullTick?.(pushData.tickData);
359
384
  if (pushData.tradeTickData)
360
- cb.onTick?.(pushData.tradeTickData);
385
+ cb.onTick?.((0, tick_util_1.convertTradeTick)(pushData.tradeTickData));
361
386
  break;
362
387
  case SocketCommon_1.SocketCommon_DataType.Asset:
363
388
  if (pushData.assetData)
@@ -393,8 +418,7 @@ class PushClient {
393
418
  cb.onQuote?.(pushData.quoteData);
394
419
  break;
395
420
  default:
396
- // FullTick and QuoteBBO use TradeTick/Quote dataType
397
- // TickData (fullTick) via tickData field
421
+ // QuoteBBO and some full-tick payloads reuse an existing dataType.
398
422
  if (pushData.tickData)
399
423
  cb.onFullTick?.(pushData.tickData);
400
424
  break;
@@ -566,8 +590,9 @@ class PushClient {
566
590
  // ===== Account push subscribe/unsubscribe =====
567
591
  /** Subscribe to asset changes */
568
592
  subscribeAsset(account) {
569
- this.doSubscribe(push_message_1.SubjectType.Asset, undefined, account || this.config.account);
570
- this.accountSubs.add(push_message_1.SubjectType.Asset);
593
+ const acct = account || this.config.account;
594
+ this.doSubscribe(push_message_1.SubjectType.Asset, undefined, acct);
595
+ this.accountSubs.set(push_message_1.SubjectType.Asset, acct);
571
596
  }
572
597
  /** Unsubscribe from asset changes */
573
598
  unsubscribeAsset() {
@@ -576,8 +601,9 @@ class PushClient {
576
601
  }
577
602
  /** Subscribe to position changes */
578
603
  subscribePosition(account) {
579
- this.doSubscribe(push_message_1.SubjectType.Position, undefined, account || this.config.account);
580
- this.accountSubs.add(push_message_1.SubjectType.Position);
604
+ const acct = account || this.config.account;
605
+ this.doSubscribe(push_message_1.SubjectType.Position, undefined, acct);
606
+ this.accountSubs.set(push_message_1.SubjectType.Position, acct);
581
607
  }
582
608
  /** Unsubscribe from position changes */
583
609
  unsubscribePosition() {
@@ -586,8 +612,9 @@ class PushClient {
586
612
  }
587
613
  /** Subscribe to order status */
588
614
  subscribeOrder(account) {
589
- this.doSubscribe(push_message_1.SubjectType.Order, undefined, account || this.config.account);
590
- this.accountSubs.add(push_message_1.SubjectType.Order);
615
+ const acct = account || this.config.account;
616
+ this.doSubscribe(push_message_1.SubjectType.Order, undefined, acct);
617
+ this.accountSubs.set(push_message_1.SubjectType.Order, acct);
591
618
  }
592
619
  /** Unsubscribe from order status */
593
620
  unsubscribeOrder() {
@@ -596,8 +623,9 @@ class PushClient {
596
623
  }
597
624
  /** Subscribe to transaction details */
598
625
  subscribeTransaction(account) {
599
- this.doSubscribe(push_message_1.SubjectType.Transaction, undefined, account || this.config.account);
600
- this.accountSubs.add(push_message_1.SubjectType.Transaction);
626
+ const acct = account || this.config.account;
627
+ this.doSubscribe(push_message_1.SubjectType.Transaction, undefined, acct);
628
+ this.accountSubs.set(push_message_1.SubjectType.Transaction, acct);
601
629
  }
602
630
  /** Unsubscribe from transaction details */
603
631
  unsubscribeTransaction() {
@@ -613,9 +641,9 @@ class PushClient {
613
641
  }
614
642
  return result;
615
643
  }
616
- /** Get account-level subscriptions */
644
+ /** Get account-level subscriptions: subject -> account */
617
645
  getAccountSubscriptions() {
618
- return Array.from(this.accountSubs);
646
+ return new Map(this.accountSubs);
619
647
  }
620
648
  }
621
649
  exports.PushClient = PushClient;