tigeropen 0.3.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 (84) 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 +106 -7
  12. package/dist/cjs/model/order-helpers.js +149 -0
  13. package/dist/cjs/model/order-status.js +46 -0
  14. package/dist/cjs/model/quote-requests.js +11 -0
  15. package/dist/cjs/model/trade-requests.js +13 -0
  16. package/dist/cjs/push/index.js +1 -0
  17. package/dist/cjs/push/pb/OrderStatusData.js +24 -0
  18. package/dist/cjs/push/proto-message.js +6 -0
  19. package/dist/cjs/push/push-client.js +117 -19
  20. package/dist/cjs/push/push-message.js +4 -0
  21. package/dist/cjs/push/tick-util.js +172 -0
  22. package/dist/cjs/quote/quote-client.js +584 -42
  23. package/dist/cjs/trade/trade-client.js +334 -32
  24. package/dist/cjs/version.js +4 -0
  25. package/dist/esm/client/api-request.js +1 -1
  26. package/dist/esm/client/api-response.js +29 -8
  27. package/dist/esm/client/case-convert.js +4 -3
  28. package/dist/esm/client/http-client.js +128 -12
  29. package/dist/esm/client/index.js +6 -6
  30. package/dist/esm/client/token-methods.js +37 -0
  31. package/dist/esm/config/client-config.js +118 -20
  32. package/dist/esm/config/config-parser.js +19 -9
  33. package/dist/esm/config/index.js +4 -3
  34. package/dist/esm/config/token-manager.js +55 -5
  35. package/dist/esm/index.js +15 -1
  36. package/dist/esm/logger/index.js +1 -1
  37. package/dist/esm/model/contract-helpers.js +1 -1
  38. package/dist/esm/model/enums.js +104 -6
  39. package/dist/esm/model/order-helpers.js +142 -1
  40. package/dist/esm/model/order-status.js +43 -0
  41. package/dist/esm/model/quote-requests.js +10 -0
  42. package/dist/esm/model/trade-requests.js +12 -0
  43. package/dist/esm/push/index.js +6 -5
  44. package/dist/esm/push/pb/OrderStatusData.js +24 -0
  45. package/dist/esm/push/pb/PushData.js +11 -11
  46. package/dist/esm/push/pb/QuoteBasicData.js +1 -1
  47. package/dist/esm/push/pb/Response.js +1 -1
  48. package/dist/esm/push/pb/index.js +17 -17
  49. package/dist/esm/push/proto-message.js +9 -3
  50. package/dist/esm/push/push-client.js +124 -26
  51. package/dist/esm/push/push-message.js +4 -0
  52. package/dist/esm/push/tick-util.js +165 -0
  53. package/dist/esm/quote/index.js +1 -1
  54. package/dist/esm/quote/quote-client.js +553 -44
  55. package/dist/esm/signer/index.js +2 -2
  56. package/dist/esm/trade/index.js +1 -1
  57. package/dist/esm/trade/trade-client.js +303 -34
  58. package/dist/esm/version.js +1 -0
  59. package/dist/types/client/api-response.d.ts +6 -4
  60. package/dist/types/client/case-convert.d.ts +3 -1
  61. package/dist/types/client/http-client.d.ts +32 -1
  62. package/dist/types/client/token-methods.d.ts +34 -0
  63. package/dist/types/config/client-config.d.ts +22 -1
  64. package/dist/types/config/index.d.ts +3 -1
  65. package/dist/types/config/token-manager.d.ts +27 -3
  66. package/dist/types/index.d.ts +22 -1
  67. package/dist/types/model/enums.d.ts +77 -7
  68. package/dist/types/model/order-helpers.d.ts +52 -1
  69. package/dist/types/model/order-status.d.ts +14 -0
  70. package/dist/types/model/order.d.ts +127 -10
  71. package/dist/types/model/quote-requests.d.ts +356 -0
  72. package/dist/types/model/quote.d.ts +391 -4
  73. package/dist/types/model/trade-requests.d.ts +309 -0
  74. package/dist/types/model/trade.d.ts +231 -5
  75. package/dist/types/push/callbacks.d.ts +3 -7
  76. package/dist/types/push/index.d.ts +1 -0
  77. package/dist/types/push/pb/OrderStatusData.d.ts +4 -0
  78. package/dist/types/push/push-client.d.ts +36 -3
  79. package/dist/types/push/push-message.d.ts +4 -0
  80. package/dist/types/push/tick-util.d.ts +30 -0
  81. package/dist/types/quote/quote-client.d.ts +193 -15
  82. package/dist/types/trade/trade-client.d.ts +136 -18
  83. package/dist/types/version.d.ts +1 -0
  84. 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.3.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,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.PriceType = exports.OrderType = exports.Currency = exports.SecurityType = exports.Market = void 0;
8
+ exports.orderStatusCode = orderStatusCode;
8
9
  /** 市场枚举 */
9
10
  var Market;
10
11
  (function (Market) {
@@ -50,20 +51,63 @@ var OrderType;
50
51
  OrderType["TWAP"] = "TWAP";
51
52
  OrderType["VWAP"] = "VWAP";
52
53
  OrderType["OCA"] = "OCA";
54
+ OrderType["ICEBERG"] = "ICEBERG";
53
55
  })(OrderType || (exports.OrderType = OrderType = {}));
54
- /** 订单状态枚举 */
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 = {}));
68
+ /**
69
+ * 订单状态枚举。对齐 Java SDK OrderStatus 定义。
70
+ *
71
+ * 服务端 wire 返回的值同时可能是:
72
+ * - 数字: -2 / -1 / 3 / 4 / 5 / 6 / 7 / 8
73
+ * - 字符串: "Invalid" / "Initial" / "PendingCancel" / "Cancelled" /
74
+ * "Submitted" / "Filled" / "Inactive" / "PendingSubmit"
75
+ *
76
+ * Client 层通过 normalizeOrderStatus() 做数字→字符串归一,不做跨别名合并。
77
+ */
55
78
  var OrderStatus;
56
79
  (function (OrderStatus) {
57
- OrderStatus["PendingNew"] = "PendingNew";
80
+ OrderStatus["Invalid"] = "Invalid";
58
81
  OrderStatus["Initial"] = "Initial";
82
+ OrderStatus["PendingCancel"] = "PendingCancel";
83
+ OrderStatus["Cancelled"] = "Cancelled";
59
84
  OrderStatus["Submitted"] = "Submitted";
60
- OrderStatus["PartiallyFilled"] = "PartiallyFilled";
61
85
  OrderStatus["Filled"] = "Filled";
62
- OrderStatus["Cancelled"] = "Cancelled";
63
- OrderStatus["PendingCancel"] = "PendingCancel";
64
86
  OrderStatus["Inactive"] = "Inactive";
65
- OrderStatus["Invalid"] = "Invalid";
87
+ OrderStatus["PendingSubmit"] = "PendingSubmit";
66
88
  })(OrderStatus || (exports.OrderStatus = OrderStatus = {}));
89
+ /** 返回订单状态对应的服务端数字码,未知返回 0。 */
90
+ function orderStatusCode(status) {
91
+ switch (status) {
92
+ case OrderStatus.Invalid:
93
+ return -2;
94
+ case OrderStatus.Initial:
95
+ return -1;
96
+ case OrderStatus.PendingCancel:
97
+ return 3;
98
+ case OrderStatus.Cancelled:
99
+ return 4;
100
+ case OrderStatus.Submitted:
101
+ return 5;
102
+ case OrderStatus.Filled:
103
+ return 6;
104
+ case OrderStatus.Inactive:
105
+ return 7;
106
+ case OrderStatus.PendingSubmit:
107
+ return 8;
108
+ }
109
+ return 0;
110
+ }
67
111
  /** K 线周期枚举 */
68
112
  var BarPeriod;
69
113
  (function (BarPeriod) {
@@ -106,5 +150,60 @@ var TimeInForce;
106
150
  (function (TimeInForce) {
107
151
  TimeInForce["DAY"] = "DAY";
108
152
  TimeInForce["GTC"] = "GTC";
153
+ TimeInForce["GTD"] = "GTD";
109
154
  TimeInForce["OPG"] = "OPG";
110
155
  })(TimeInForce || (exports.TimeInForce = TimeInForce = {}));
156
+ /** 订单排序字段 */
157
+ var OrderSortBy;
158
+ (function (OrderSortBy) {
159
+ OrderSortBy["LatestCreated"] = "LATEST_CREATED";
160
+ OrderSortBy["LatestStatusUpdated"] = "LATEST_STATUS_UPDATED";
161
+ })(OrderSortBy || (exports.OrderSortBy = OrderSortBy = {}));
162
+ /** 账户分部类型 */
163
+ var SegmentType;
164
+ (function (SegmentType) {
165
+ SegmentType["All"] = "ALL";
166
+ SegmentType["Sec"] = "SEC";
167
+ SegmentType["Fut"] = "FUT";
168
+ SegmentType["Fund"] = "FUND";
169
+ })(SegmentType || (exports.SegmentType = SegmentType = {}));
170
+ /** 公司行动类型 */
171
+ var CorporateActionType;
172
+ (function (CorporateActionType) {
173
+ CorporateActionType["Split"] = "split";
174
+ CorporateActionType["Dividend"] = "dividend";
175
+ CorporateActionType["Earning"] = "earning";
176
+ CorporateActionType["SymbolChange"] = "symbol_change";
177
+ CorporateActionType["Delisting"] = "delisting";
178
+ CorporateActionType["IPO"] = "ipo";
179
+ })(CorporateActionType || (exports.CorporateActionType = CorporateActionType = {}));
180
+ /** 行业级别 (1~4 级) */
181
+ var IndustryLevel;
182
+ (function (IndustryLevel) {
183
+ IndustryLevel["GSector"] = "GSECTOR";
184
+ IndustryLevel["GGroup"] = "GGROUP";
185
+ IndustryLevel["GInd"] = "GIND";
186
+ IndustryLevel["GSubInd"] = "GSUBIND";
187
+ })(IndustryLevel || (exports.IndustryLevel = IndustryLevel = {}));
188
+ /** 排序方向 */
189
+ var SortDirection;
190
+ (function (SortDirection) {
191
+ SortDirection["No"] = "SortDir_No";
192
+ SortDirection["Ascend"] = "SortDir_Ascend";
193
+ SortDirection["Descend"] = "SortDir_Descend";
194
+ })(SortDirection || (exports.SortDirection = SortDirection = {}));
195
+ /** 期权分析周期 */
196
+ var OptionAnalysisPeriod;
197
+ (function (OptionAnalysisPeriod) {
198
+ OptionAnalysisPeriod["ThreeYear"] = "3year";
199
+ OptionAnalysisPeriod["FiftyTwoWeek"] = "52week";
200
+ OptionAnalysisPeriod["TwentySixWeek"] = "26week";
201
+ OptionAnalysisPeriod["ThirteenWeek"] = "13week";
202
+ })(OptionAnalysisPeriod || (exports.OptionAnalysisPeriod = OptionAnalysisPeriod = {}));
203
+ /** 财报类型 */
204
+ var FinancialReportPeriod;
205
+ (function (FinancialReportPeriod) {
206
+ FinancialReportPeriod["Annual"] = "Annual";
207
+ FinancialReportPeriod["Quarterly"] = "Quarterly";
208
+ FinancialReportPeriod["LTM"] = "LTM";
209
+ })(FinancialReportPeriod || (exports.FinancialReportPeriod = FinancialReportPeriod = {}));
@@ -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
+ }
@@ -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 });
@@ -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; } });
@@ -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
  };