@woodger/t-invest-node-sdk 0.5.2 → 0.5.4

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 (229) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/{THIRD_PARTY_NOTICES.md → LICENSE-APACHE-2.0} +1 -106
  3. package/NOTICE +98 -0
  4. package/dist/application/services/unary-limiter.d.ts +10 -1
  5. package/dist/application/services/unary-limiter.js +35 -11
  6. package/dist/bootstrap/args/sdk-options.d.ts +1 -2
  7. package/dist/bootstrap/cli/help-catalog.d.ts +733 -0
  8. package/dist/bootstrap/cli/help-catalog.js +1649 -0
  9. package/dist/bootstrap/cli/help.d.ts +2 -730
  10. package/dist/bootstrap/cli/help.js +5 -1647
  11. package/dist/bootstrap/cli/registry.d.ts +6 -6
  12. package/dist/bootstrap/commands/accounts/cli.d.ts +2 -3
  13. package/dist/bootstrap/commands/accounts/cli.js +5 -10
  14. package/dist/bootstrap/commands/accrued-interests/cli.d.ts +2 -3
  15. package/dist/bootstrap/commands/accrued-interests/cli.js +5 -10
  16. package/dist/bootstrap/commands/asset/cli.d.ts +2 -3
  17. package/dist/bootstrap/commands/asset/cli.js +5 -10
  18. package/dist/bootstrap/commands/assets/cli.d.ts +2 -3
  19. package/dist/bootstrap/commands/assets/cli.js +5 -10
  20. package/dist/bootstrap/commands/bond/cli.d.ts +2 -3
  21. package/dist/bootstrap/commands/bond/cli.js +5 -10
  22. package/dist/bootstrap/commands/bond-coupons/cli.d.ts +2 -3
  23. package/dist/bootstrap/commands/bond-coupons/cli.js +5 -10
  24. package/dist/bootstrap/commands/bonds/cli.d.ts +2 -3
  25. package/dist/bootstrap/commands/bonds/cli.js +5 -10
  26. package/dist/bootstrap/commands/brand/cli.d.ts +2 -3
  27. package/dist/bootstrap/commands/brand/cli.js +5 -10
  28. package/dist/bootstrap/commands/brands/cli.d.ts +2 -3
  29. package/dist/bootstrap/commands/brands/cli.js +5 -10
  30. package/dist/bootstrap/commands/broker-report/cli.d.ts +2 -3
  31. package/dist/bootstrap/commands/broker-report/cli.js +5 -10
  32. package/dist/bootstrap/commands/cancel-order/cli.d.ts +3 -39
  33. package/dist/bootstrap/commands/cancel-order/cli.js +8 -19
  34. package/dist/bootstrap/commands/cancel-order/request.mapper.d.ts +7 -0
  35. package/dist/bootstrap/commands/cancel-order/request.mapper.js +9 -0
  36. package/dist/bootstrap/commands/cancel-stop-order/cli.d.ts +3 -4
  37. package/dist/bootstrap/commands/cancel-stop-order/cli.js +6 -11
  38. package/dist/bootstrap/commands/candles/cli.d.ts +3 -4
  39. package/dist/bootstrap/commands/candles/cli.js +6 -11
  40. package/dist/bootstrap/commands/close-prices/cli.d.ts +3 -4
  41. package/dist/bootstrap/commands/close-prices/cli.js +6 -11
  42. package/dist/bootstrap/commands/countries/cli.d.ts +2 -3
  43. package/dist/bootstrap/commands/countries/cli.js +5 -10
  44. package/dist/bootstrap/commands/currencies/cli.d.ts +2 -3
  45. package/dist/bootstrap/commands/currencies/cli.js +5 -10
  46. package/dist/bootstrap/commands/currency/cli.d.ts +2 -3
  47. package/dist/bootstrap/commands/currency/cli.js +5 -10
  48. package/dist/bootstrap/commands/dividends/cli.d.ts +2 -3
  49. package/dist/bootstrap/commands/dividends/cli.js +5 -10
  50. package/dist/bootstrap/commands/dividends-foreign-issuer/cli.d.ts +2 -3
  51. package/dist/bootstrap/commands/dividends-foreign-issuer/cli.js +5 -10
  52. package/dist/bootstrap/commands/edit-favorites/cli.d.ts +2 -3
  53. package/dist/bootstrap/commands/edit-favorites/cli.js +5 -10
  54. package/dist/bootstrap/commands/etf/cli.d.ts +2 -3
  55. package/dist/bootstrap/commands/etf/cli.js +5 -10
  56. package/dist/bootstrap/commands/etfs/cli.d.ts +2 -3
  57. package/dist/bootstrap/commands/etfs/cli.js +5 -10
  58. package/dist/bootstrap/commands/favorites/cli.d.ts +2 -3
  59. package/dist/bootstrap/commands/favorites/cli.js +5 -10
  60. package/dist/bootstrap/commands/find-instrument/cli.d.ts +2 -3
  61. package/dist/bootstrap/commands/find-instrument/cli.js +5 -10
  62. package/dist/bootstrap/commands/future/cli.d.ts +2 -3
  63. package/dist/bootstrap/commands/future/cli.js +5 -10
  64. package/dist/bootstrap/commands/futures/cli.d.ts +2 -3
  65. package/dist/bootstrap/commands/futures/cli.js +5 -10
  66. package/dist/bootstrap/commands/futures-margin/cli.d.ts +2 -3
  67. package/dist/bootstrap/commands/futures-margin/cli.js +5 -10
  68. package/dist/bootstrap/commands/instrument/cli.d.ts +2 -3
  69. package/dist/bootstrap/commands/instrument/cli.js +5 -10
  70. package/dist/bootstrap/commands/last-prices/cli.d.ts +3 -4
  71. package/dist/bootstrap/commands/last-prices/cli.js +6 -11
  72. package/dist/bootstrap/commands/last-trades/cli.d.ts +3 -4
  73. package/dist/bootstrap/commands/last-trades/cli.js +6 -11
  74. package/dist/bootstrap/commands/margin-attributes/cli.d.ts +2 -3
  75. package/dist/bootstrap/commands/margin-attributes/cli.js +5 -10
  76. package/dist/bootstrap/commands/operations/cli.d.ts +5 -53
  77. package/dist/bootstrap/commands/operations/cli.js +9 -36
  78. package/dist/bootstrap/commands/operations/request.mapper.d.ts +23 -0
  79. package/dist/bootstrap/commands/operations/request.mapper.js +33 -0
  80. package/dist/bootstrap/commands/operations-by-cursor/cli.d.ts +5 -69
  81. package/dist/bootstrap/commands/operations-by-cursor/cli.js +9 -74
  82. package/dist/bootstrap/commands/operations-by-cursor/request.mapper.d.ts +28 -0
  83. package/dist/bootstrap/commands/operations-by-cursor/request.mapper.js +70 -0
  84. package/dist/bootstrap/commands/option/cli.d.ts +2 -3
  85. package/dist/bootstrap/commands/option/cli.js +5 -10
  86. package/dist/bootstrap/commands/options-by/cli.d.ts +2 -3
  87. package/dist/bootstrap/commands/options-by/cli.js +5 -10
  88. package/dist/bootstrap/commands/order-book/cli.d.ts +3 -4
  89. package/dist/bootstrap/commands/order-book/cli.js +6 -11
  90. package/dist/bootstrap/commands/order-state/cli.d.ts +3 -36
  91. package/dist/bootstrap/commands/order-state/cli.js +8 -21
  92. package/dist/bootstrap/commands/order-state/request.mapper.d.ts +13 -0
  93. package/dist/bootstrap/commands/order-state/request.mapper.js +17 -0
  94. package/dist/bootstrap/commands/orders/cli.d.ts +3 -32
  95. package/dist/bootstrap/commands/orders/cli.js +8 -18
  96. package/dist/bootstrap/commands/orders/request.mapper.d.ts +6 -0
  97. package/dist/bootstrap/commands/orders/request.mapper.js +8 -0
  98. package/dist/bootstrap/commands/portfolio/cli.d.ts +6 -40
  99. package/dist/bootstrap/commands/portfolio/cli.js +9 -26
  100. package/dist/bootstrap/commands/portfolio/request.mapper.d.ts +18 -0
  101. package/dist/bootstrap/commands/portfolio/request.mapper.js +21 -0
  102. package/dist/bootstrap/commands/positions/cli.d.ts +3 -32
  103. package/dist/bootstrap/commands/positions/cli.js +8 -18
  104. package/dist/bootstrap/commands/positions/request.mapper.d.ts +6 -0
  105. package/dist/bootstrap/commands/positions/request.mapper.js +8 -0
  106. package/dist/bootstrap/commands/post-order/cli.d.ts +8 -68
  107. package/dist/bootstrap/commands/post-order/cli.js +9 -39
  108. package/dist/bootstrap/commands/post-order/request.mapper.d.ts +27 -0
  109. package/dist/bootstrap/commands/post-order/request.mapper.js +35 -0
  110. package/dist/bootstrap/commands/post-stop-order/cli.d.ts +3 -4
  111. package/dist/bootstrap/commands/post-stop-order/cli.js +6 -11
  112. package/dist/bootstrap/commands/replace-order/cli.d.ts +5 -61
  113. package/dist/bootstrap/commands/replace-order/cli.js +9 -30
  114. package/dist/bootstrap/commands/replace-order/request.mapper.d.ts +22 -0
  115. package/dist/bootstrap/commands/replace-order/request.mapper.js +26 -0
  116. package/dist/bootstrap/commands/sandbox-accounts/cli.d.ts +2 -3
  117. package/dist/bootstrap/commands/sandbox-accounts/cli.js +5 -10
  118. package/dist/bootstrap/commands/sandbox-cancel-order/cli.d.ts +3 -4
  119. package/dist/bootstrap/commands/sandbox-cancel-order/cli.js +8 -13
  120. package/dist/bootstrap/commands/sandbox-close-account/cli.d.ts +2 -3
  121. package/dist/bootstrap/commands/sandbox-close-account/cli.js +5 -10
  122. package/dist/bootstrap/commands/sandbox-open-account/cli.d.ts +2 -3
  123. package/dist/bootstrap/commands/sandbox-open-account/cli.js +5 -10
  124. package/dist/bootstrap/commands/sandbox-operations/cli.d.ts +3 -4
  125. package/dist/bootstrap/commands/sandbox-operations/cli.js +8 -13
  126. package/dist/bootstrap/commands/sandbox-operations-by-cursor/cli.d.ts +3 -4
  127. package/dist/bootstrap/commands/sandbox-operations-by-cursor/cli.js +8 -13
  128. package/dist/bootstrap/commands/sandbox-order-state/cli.d.ts +3 -4
  129. package/dist/bootstrap/commands/sandbox-order-state/cli.js +8 -13
  130. package/dist/bootstrap/commands/sandbox-orders/cli.d.ts +3 -4
  131. package/dist/bootstrap/commands/sandbox-orders/cli.js +8 -13
  132. package/dist/bootstrap/commands/sandbox-pay-in/cli.d.ts +2 -3
  133. package/dist/bootstrap/commands/sandbox-pay-in/cli.js +5 -10
  134. package/dist/bootstrap/commands/sandbox-portfolio/cli.d.ts +3 -4
  135. package/dist/bootstrap/commands/sandbox-portfolio/cli.js +8 -13
  136. package/dist/bootstrap/commands/sandbox-positions/cli.d.ts +3 -4
  137. package/dist/bootstrap/commands/sandbox-positions/cli.js +8 -13
  138. package/dist/bootstrap/commands/sandbox-post-order/cli.d.ts +3 -4
  139. package/dist/bootstrap/commands/sandbox-post-order/cli.js +8 -13
  140. package/dist/bootstrap/commands/sandbox-replace-order/cli.d.ts +3 -4
  141. package/dist/bootstrap/commands/sandbox-replace-order/cli.js +8 -13
  142. package/dist/bootstrap/commands/sandbox-withdraw-limits/cli.d.ts +3 -4
  143. package/dist/bootstrap/commands/sandbox-withdraw-limits/cli.js +8 -13
  144. package/dist/bootstrap/commands/sdk-command-lifecycle.d.ts +15 -0
  145. package/dist/bootstrap/commands/sdk-command-lifecycle.js +21 -0
  146. package/dist/bootstrap/commands/share/cli.d.ts +2 -3
  147. package/dist/bootstrap/commands/share/cli.js +5 -10
  148. package/dist/bootstrap/commands/shares/cli.d.ts +2 -3
  149. package/dist/bootstrap/commands/shares/cli.js +5 -10
  150. package/dist/bootstrap/commands/stop-orders/cli.d.ts +3 -4
  151. package/dist/bootstrap/commands/stop-orders/cli.js +6 -11
  152. package/dist/bootstrap/commands/stream-run/cli.d.ts +2 -24
  153. package/dist/bootstrap/commands/stream-run/cli.js +7 -142
  154. package/dist/bootstrap/commands/stream-run/config.d.ts +7 -15
  155. package/dist/bootstrap/commands/stream-run/config.js +1 -101
  156. package/dist/bootstrap/commands/stream-run/request.mapper.d.ts +14 -0
  157. package/dist/bootstrap/commands/stream-run/request.mapper.js +111 -0
  158. package/dist/bootstrap/commands/stream-run/stream-session.d.ts +37 -0
  159. package/dist/bootstrap/commands/stream-run/stream-session.js +152 -0
  160. package/dist/bootstrap/commands/trading-schedules/cli.d.ts +2 -3
  161. package/dist/bootstrap/commands/trading-schedules/cli.js +5 -10
  162. package/dist/bootstrap/commands/trading-status/cli.d.ts +3 -4
  163. package/dist/bootstrap/commands/trading-status/cli.js +6 -11
  164. package/dist/bootstrap/commands/trading-statuses/cli.d.ts +3 -4
  165. package/dist/bootstrap/commands/trading-statuses/cli.js +6 -11
  166. package/dist/bootstrap/commands/user-info/cli.d.ts +2 -3
  167. package/dist/bootstrap/commands/user-info/cli.js +5 -10
  168. package/dist/bootstrap/commands/user-tariff/cli.d.ts +2 -3
  169. package/dist/bootstrap/commands/user-tariff/cli.js +5 -10
  170. package/dist/bootstrap/commands/withdraw-limits/cli.d.ts +3 -32
  171. package/dist/bootstrap/commands/withdraw-limits/cli.js +8 -18
  172. package/dist/bootstrap/commands/withdraw-limits/request.mapper.d.ts +6 -0
  173. package/dist/bootstrap/commands/withdraw-limits/request.mapper.js +8 -0
  174. package/dist/bootstrap/index.js +2 -2
  175. package/dist/bootstrap/proto/compile-proto.d.ts +1 -1
  176. package/dist/bootstrap/proto/compile-proto.js +28 -35
  177. package/dist/bootstrap/t-invest-node-sdk.d.ts +9 -9
  178. package/dist/bootstrap/t-invest-node-sdk.js +33 -18
  179. package/dist/bootstrap/unary-limit-config.js +4 -4
  180. package/dist/generated/common.js +2 -2
  181. package/dist/generated/google/api/field_behavior.js +2 -2
  182. package/dist/generated/google/protobuf/descriptor.js +2 -2
  183. package/dist/generated/google/protobuf/timestamp.js +2 -2
  184. package/dist/generated/instruments.js +2 -2
  185. package/dist/generated/marketdata.js +2 -2
  186. package/dist/generated/operations.js +2 -2
  187. package/dist/generated/orders.js +2 -2
  188. package/dist/generated/sandbox.js +2 -2
  189. package/dist/generated/signals.js +2 -2
  190. package/dist/generated/stoporders.js +2 -2
  191. package/dist/generated/users.js +2 -2
  192. package/dist/index.d.ts +1 -1
  193. package/dist/infrastructure/interceptor/warning-interceptor.d.ts +1 -1
  194. package/dist/infrastructure/interceptor/warning-interceptor.js +2 -2
  195. package/dist/infrastructure/transport/grpc/sdk-call-error.d.ts +12 -0
  196. package/dist/infrastructure/transport/grpc/sdk-call-error.js +180 -0
  197. package/dist/infrastructure/transport/grpc/sdk-client.d.ts +1 -1
  198. package/dist/infrastructure/transport/grpc/sdk-client.js +2 -2
  199. package/dist/infrastructure/transport/grpc/sdk-middleware.d.ts +1 -1
  200. package/dist/infrastructure/transport/grpc/sdk-middleware.js +8 -174
  201. package/dist/infrastructure/transport/grpc/unary-limit-resolver.d.ts +3 -1
  202. package/dist/infrastructure/transport/grpc/unary-limit-resolver.js +19 -18
  203. package/docs/architecture.md +45 -42
  204. package/docs/bundled-ca.md +12 -12
  205. package/docs/clean-architecture/adapters.md +15 -15
  206. package/docs/clean-architecture/api-commands.md +63 -52
  207. package/docs/clean-architecture/application.md +13 -13
  208. package/docs/clean-architecture/cli-output-boundaries.md +23 -23
  209. package/docs/clean-architecture/dto.md +9 -9
  210. package/docs/clean-architecture/index.md +13 -12
  211. package/docs/cli-stream-configuration.md +9 -9
  212. package/docs/cli-stream-reference.md +11 -11
  213. package/docs/guides/custom-unary-limiter.md +44 -30
  214. package/docs/guides/errors-and-lifecycle.md +10 -10
  215. package/docs/guides/getting-started.md +9 -9
  216. package/docs/guides/index.md +3 -3
  217. package/docs/guides/streams-and-cancellation.md +6 -6
  218. package/docs/guides/testing-with-service-definitions.md +4 -4
  219. package/docs/guides/unary-calls.md +8 -8
  220. package/docs/index.md +14 -10
  221. package/docs/limits-policy.md +10 -10
  222. package/docs/roadmap.md +14 -14
  223. package/docs/tls-policy.md +7 -7
  224. package/package.json +6 -5
  225. package/readme.md +37 -85
  226. package/dist/infrastructure/interceptor/index.d.ts +0 -1
  227. package/dist/infrastructure/interceptor/index.js +0 -17
  228. /package/dist/infrastructure/transport/grpc/{unary-limits.d.ts → unary-method-path.d.ts} +0 -0
  229. /package/dist/infrastructure/transport/grpc/{unary-limits.js → unary-method-path.js} +0 -0
@@ -4,22 +4,21 @@
4
4
  *
5
5
  * Здесь допустимы:
6
6
  * - объявление command path и option schema;
7
- * - преобразование CLI options в generated request;
8
- * - создание SDK через bootstrap factory и закрытие SDK resource;
7
+ * - переиспользование общего production/Sandbox request mapper-а;
8
+ * - выполнение короткого SDK lifecycle через общий bootstrap helper;
9
9
  *
10
10
  * Здесь не должно быть ручного table/json rendering или application report contracts.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.formatWithdrawLimits = exports.sandboxWithdrawLimitsCommand = void 0;
13
+ exports.sandboxWithdrawLimitsCommand = void 0;
14
14
  exports.createSandboxWithdrawLimitsCommand = createSandboxWithdrawLimitsCommand;
15
15
  exports.createSandboxWithdrawLimitsRequest = createSandboxWithdrawLimitsRequest;
16
16
  const contract_1 = require("../../cli/contract");
17
- const args_1 = require("../../args");
17
+ const sdk_command_lifecycle_1 = require("../sdk-command-lifecycle");
18
18
  const command_options_1 = require("../../args/command-options");
19
19
  const t_invest_node_sdk_1 = require("../../t-invest-node-sdk");
20
- const cli_1 = require("../withdraw-limits/cli");
20
+ const request_mapper_1 = require("../withdraw-limits/request.mapper");
21
21
  const reporter_1 = require("../withdraw-limits/reporter");
22
- Object.defineProperty(exports, "formatWithdrawLimits", { enumerable: true, get: function () { return reporter_1.formatWithdrawLimits; } });
23
22
  const sandboxWithdrawLimitsCommandPath = ['sandbox', 'withdraw-limits'];
24
23
  const defaultSandboxWithdrawLimitsSdkFactory = (options) => new t_invest_node_sdk_1.TInvestNodeSDK(options);
25
24
  const sandboxWithdrawLimitsRequestOptionsSchema = {
@@ -49,15 +48,11 @@ exports.sandboxWithdrawLimitsCommand = createSandboxWithdrawLimitsCommand();
49
48
  async function runSandboxWithdrawLimitsCommand(options, createSdk) {
50
49
  const request = createSandboxWithdrawLimitsRequest(options);
51
50
  const { format } = options;
52
- const sdk = createSdk((0, args_1.resolveSdkOptionsFromCommandOptions)(options));
53
- try {
51
+ return (0, sdk_command_lifecycle_1.runSdkCommand)(options, createSdk, async (sdk) => {
54
52
  const response = await sdk.sandbox.getSandboxWithdrawLimits(request);
55
53
  return (0, reporter_1.formatWithdrawLimits)(response, format);
56
- }
57
- finally {
58
- sdk.close();
59
- }
54
+ });
60
55
  }
61
56
  function createSandboxWithdrawLimitsRequest(options) {
62
- return (0, cli_1.createWithdrawLimitsRequest)(options);
57
+ return (0, request_mapper_1.createWithdrawLimitsRequest)(options);
63
58
  }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Модуль владеет повторяемым lifecycle короткой SDK-команды.
3
+ *
4
+ * Здесь допустимы создание SDK из общих CLI options и гарантированное закрытие
5
+ * ресурса после завершения handler-а.
6
+ *
7
+ * Здесь не должно быть request mapping, rendering или lifecycle stream-сессий.
8
+ */
9
+ import type { TInvestOptions } from '../../application/dto/t-invest-options';
10
+ import { type SdkCommandOptions } from '../args/sdk-options';
11
+ interface ClosableSdk {
12
+ close(): void;
13
+ }
14
+ export declare function runSdkCommand<Sdk extends ClosableSdk, Result>(options: SdkCommandOptions, createSdk: (options: TInvestOptions) => Sdk, execute: (sdk: Sdk) => Promise<Result>): Promise<Result>;
15
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ /**
3
+ * Модуль владеет повторяемым lifecycle короткой SDK-команды.
4
+ *
5
+ * Здесь допустимы создание SDK из общих CLI options и гарантированное закрытие
6
+ * ресурса после завершения handler-а.
7
+ *
8
+ * Здесь не должно быть request mapping, rendering или lifecycle stream-сессий.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.runSdkCommand = runSdkCommand;
12
+ const sdk_options_1 = require("../args/sdk-options");
13
+ async function runSdkCommand(options, createSdk, execute) {
14
+ const sdk = createSdk((0, sdk_options_1.resolveSdkOptionsFromCommandOptions)(options));
15
+ try {
16
+ return await execute(sdk);
17
+ }
18
+ finally {
19
+ sdk.close();
20
+ }
21
+ }
@@ -4,13 +4,12 @@
4
4
  * Здесь допустимы:
5
5
  * - объявление command path и option schema;
6
6
  * - преобразование CLI options в generated request;
7
- * - создание SDK через bootstrap factory и закрытие SDK resource;
7
+ * - выполнение короткого SDK lifecycle через общий bootstrap helper;
8
8
  *
9
9
  * Здесь не должно быть ручного table/json rendering или application report contracts.
10
10
  */
11
11
  import type { TInvestOptions } from '../../../application/dto/t-invest-options';
12
12
  import { type InstrumentRequest, type ShareResponse } from '../../../generated/instruments';
13
- import { formatShare } from './reporter';
14
13
  type ShareSdk = {
15
14
  instruments: {
16
15
  shareBy(request: InstrumentRequest): Promise<ShareResponse>;
@@ -80,4 +79,4 @@ export declare const shareCommand: Omit<import("icore").CommandDefinition<{
80
79
  }, undefined, string, readonly ["instrument", "share", "show"], undefined, void, readonly []>, "metadata"> & {
81
80
  metadata?: undefined;
82
81
  };
83
- export { formatShare };
82
+ export {};
@@ -5,20 +5,19 @@
5
5
  * Здесь допустимы:
6
6
  * - объявление command path и option schema;
7
7
  * - преобразование CLI options в generated request;
8
- * - создание SDK через bootstrap factory и закрытие SDK resource;
8
+ * - выполнение короткого SDK lifecycle через общий bootstrap helper;
9
9
  *
10
10
  * Здесь не должно быть ручного table/json rendering или application report contracts.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.formatShare = exports.shareCommand = void 0;
13
+ exports.shareCommand = void 0;
14
14
  exports.createShareCommand = createShareCommand;
15
15
  const contract_1 = require("../../cli/contract");
16
- const args_1 = require("../../args");
16
+ const sdk_command_lifecycle_1 = require("../sdk-command-lifecycle");
17
17
  const command_options_1 = require("../../args/command-options");
18
18
  const t_invest_node_sdk_1 = require("../../t-invest-node-sdk");
19
19
  const instruments_args_1 = require("../../args/instruments-args");
20
20
  const reporter_1 = require("./reporter");
21
- Object.defineProperty(exports, "formatShare", { enumerable: true, get: function () { return reporter_1.formatShare; } });
22
21
  const shareCommandPath = ['instrument', 'share', 'show'];
23
22
  const defaultShareSdkFactory = (options) => new t_invest_node_sdk_1.TInvestNodeSDK(options);
24
23
  const shareFormatOptionsSchema = {
@@ -42,12 +41,8 @@ exports.shareCommand = createShareCommand();
42
41
  async function runShareCommand(options, createSdk) {
43
42
  const { format } = options;
44
43
  const request = (0, instruments_args_1.createInstrumentLookupRequestFromOptions)(options);
45
- const sdk = createSdk((0, args_1.resolveSdkOptionsFromCommandOptions)(options));
46
- try {
44
+ return (0, sdk_command_lifecycle_1.runSdkCommand)(options, createSdk, async (sdk) => {
47
45
  const response = await sdk.instruments.shareBy(request);
48
46
  return (0, reporter_1.formatShare)(response, format);
49
- }
50
- finally {
51
- sdk.close();
52
- }
47
+ });
53
48
  }
@@ -4,13 +4,12 @@
4
4
  * Здесь допустимы:
5
5
  * - объявление command path и option schema;
6
6
  * - преобразование CLI options в generated request;
7
- * - создание SDK через bootstrap factory и закрытие SDK resource;
7
+ * - выполнение короткого SDK lifecycle через общий bootstrap helper;
8
8
  *
9
9
  * Здесь не должно быть ручного table/json rendering или application report contracts.
10
10
  */
11
11
  import type { TInvestOptions } from '../../../application/dto/t-invest-options';
12
12
  import { type InstrumentsRequest, type SharesResponse } from '../../../generated/instruments';
13
- import { formatShares } from './reporter';
14
13
  type SharesSdk = {
15
14
  instruments: {
16
15
  shares(request: InstrumentsRequest): Promise<SharesResponse>;
@@ -70,4 +69,4 @@ export declare const sharesCommand: Omit<import("icore").CommandDefinition<{
70
69
  }, undefined, string, readonly ["instrument", "share", "list"], undefined, void, readonly []>, "metadata"> & {
71
70
  metadata?: undefined;
72
71
  };
73
- export { formatShares };
72
+ export {};
@@ -5,20 +5,19 @@
5
5
  * Здесь допустимы:
6
6
  * - объявление command path и option schema;
7
7
  * - преобразование CLI options в generated request;
8
- * - создание SDK через bootstrap factory и закрытие SDK resource;
8
+ * - выполнение короткого SDK lifecycle через общий bootstrap helper;
9
9
  *
10
10
  * Здесь не должно быть ручного table/json rendering или application report contracts.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.formatShares = exports.sharesCommand = void 0;
13
+ exports.sharesCommand = void 0;
14
14
  exports.createSharesCommand = createSharesCommand;
15
15
  const contract_1 = require("../../cli/contract");
16
- const args_1 = require("../../args");
16
+ const sdk_command_lifecycle_1 = require("../sdk-command-lifecycle");
17
17
  const command_options_1 = require("../../args/command-options");
18
18
  const t_invest_node_sdk_1 = require("../../t-invest-node-sdk");
19
19
  const instruments_args_1 = require("../../args/instruments-args");
20
20
  const reporter_1 = require("./reporter");
21
- Object.defineProperty(exports, "formatShares", { enumerable: true, get: function () { return reporter_1.formatShares; } });
22
21
  const sharesCommandPath = ['instrument', 'share', 'list'];
23
22
  const defaultSharesSdkFactory = (options) => new t_invest_node_sdk_1.TInvestNodeSDK(options);
24
23
  const sharesFormatOptionsSchema = {
@@ -42,12 +41,8 @@ exports.sharesCommand = createSharesCommand();
42
41
  async function runSharesCommand(options, createSdk) {
43
42
  const { format } = options;
44
43
  const request = (0, instruments_args_1.createInstrumentsRequestFromOptions)(options);
45
- const sdk = createSdk((0, args_1.resolveSdkOptionsFromCommandOptions)(options));
46
- try {
44
+ return (0, sdk_command_lifecycle_1.runSdkCommand)(options, createSdk, async (sdk) => {
47
45
  const response = await sdk.instruments.shares(request);
48
46
  return (0, reporter_1.formatShares)(response.instruments, format);
49
- }
50
- finally {
51
- sdk.close();
52
- }
47
+ });
53
48
  }
@@ -4,7 +4,7 @@
4
4
  * Здесь допустимы:
5
5
  * - объявление command path и option schema;
6
6
  * - преобразование CLI options в generated request;
7
- * - создание SDK через bootstrap factory и закрытие SDK resource;
7
+ * - выполнение короткого SDK lifecycle через общий bootstrap helper;
8
8
  *
9
9
  * Здесь не должно быть ручного table/json rendering или application report contracts.
10
10
  */
@@ -12,9 +12,8 @@ import type { TInvestOptions } from '../../../application/dto/t-invest-options';
12
12
  import { GetStopOrdersRequest, type GetStopOrdersResponse } from '../../../generated/stoporders';
13
13
  import type { InferOptions } from 'icore';
14
14
  import type { CommandRequestOptions } from '../../args/command-options';
15
- import { formatStopOrders } from './reporter';
16
15
  type StopOrdersSdk = {
17
- stoporders: {
16
+ stopOrders: {
18
17
  getStopOrders(request: GetStopOrdersRequest): Promise<GetStopOrdersResponse>;
19
18
  };
20
19
  close(): void;
@@ -95,5 +94,5 @@ export declare const stopOrdersCommand: Omit<import("icore").CommandDefinition<{
95
94
  }, undefined, string, readonly ["stop-order", "list"], undefined, void, readonly []>, "metadata"> & {
96
95
  metadata?: undefined;
97
96
  };
98
- export { formatStopOrders };
99
97
  export declare function createStopOrdersRequest(options: StopOrdersRequestOptions): GetStopOrdersRequest;
98
+ export {};
@@ -5,21 +5,20 @@
5
5
  * Здесь допустимы:
6
6
  * - объявление command path и option schema;
7
7
  * - преобразование CLI options в generated request;
8
- * - создание SDK через bootstrap factory и закрытие SDK resource;
8
+ * - выполнение короткого SDK lifecycle через общий bootstrap helper;
9
9
  *
10
10
  * Здесь не должно быть ручного table/json rendering или application report contracts.
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.formatStopOrders = exports.stopOrdersCommand = void 0;
13
+ exports.stopOrdersCommand = void 0;
14
14
  exports.createStopOrdersCommand = createStopOrdersCommand;
15
15
  exports.createStopOrdersRequest = createStopOrdersRequest;
16
16
  const stoporders_1 = require("../../../generated/stoporders");
17
17
  const contract_1 = require("../../cli/contract");
18
- const args_1 = require("../../args");
18
+ const sdk_command_lifecycle_1 = require("../sdk-command-lifecycle");
19
19
  const command_options_1 = require("../../args/command-options");
20
20
  const t_invest_node_sdk_1 = require("../../t-invest-node-sdk");
21
21
  const reporter_1 = require("./reporter");
22
- Object.defineProperty(exports, "formatStopOrders", { enumerable: true, get: function () { return reporter_1.formatStopOrders; } });
23
22
  const stopOrdersCommandPath = ['stop-order', 'list'];
24
23
  const defaultStopOrdersSdkFactory = (options) => new t_invest_node_sdk_1.TInvestNodeSDK(options);
25
24
  const stopOrdersRequestOptionsSchema = {
@@ -49,14 +48,10 @@ exports.stopOrdersCommand = createStopOrdersCommand();
49
48
  async function runStopOrdersCommand(options, createSdk) {
50
49
  const request = createStopOrdersRequest(options);
51
50
  const { format } = options;
52
- const sdk = createSdk((0, args_1.resolveSdkOptionsFromCommandOptions)(options));
53
- try {
54
- const response = await sdk.stoporders.getStopOrders(request);
51
+ return (0, sdk_command_lifecycle_1.runSdkCommand)(options, createSdk, async (sdk) => {
52
+ const response = await sdk.stopOrders.getStopOrders(request);
55
53
  return (0, reporter_1.formatStopOrders)(response, format);
56
- }
57
- finally {
58
- sdk.close();
59
- }
54
+ });
60
55
  }
61
56
  function createStopOrdersRequest(options) {
62
57
  return {
@@ -3,34 +3,12 @@
3
3
  *
4
4
  * Здесь допустимы:
5
5
  * - чтение stream config и применение runtime overrides;
6
- * - выбор generated stream method через SDK facade;
7
- * - управление lifecycle долгоживущего stream-процесса;
6
+ * - передача validated config и runtime policy в stream session;
8
7
  *
9
8
  * Здесь не должно быть JSONL event formatting rules или transport adapter logic.
10
9
  */
11
- import type { TInvestCallOptions } from '../../../application/dto/t-invest-services';
12
- import type { TInvestOptions } from '../../../application/dto/t-invest-options';
13
- import type { MarketDataRequest, MarketDataResponse, MarketDataServerSideStreamRequest } from '../../../generated/marketdata';
14
- import type { PortfolioStreamRequest, PortfolioStreamResponse, PositionsStreamRequest, PositionsStreamResponse } from '../../../generated/operations';
15
- import type { TradesStreamRequest, TradesStreamResponse } from '../../../generated/orders';
16
- type StreamRunSdk = {
17
- marketdataStream: {
18
- marketDataStream(request: AsyncIterable<MarketDataRequest>, options?: TInvestCallOptions): AsyncIterable<MarketDataResponse>;
19
- marketDataServerSideStream(request: MarketDataServerSideStreamRequest, options?: TInvestCallOptions): AsyncIterable<MarketDataResponse>;
20
- };
21
- operationsStream: {
22
- portfolioStream(request: PortfolioStreamRequest, options?: TInvestCallOptions): AsyncIterable<PortfolioStreamResponse>;
23
- positionsStream(request: PositionsStreamRequest, options?: TInvestCallOptions): AsyncIterable<PositionsStreamResponse>;
24
- };
25
- ordersStream: {
26
- tradesStream(request: TradesStreamRequest, options?: TInvestCallOptions): AsyncIterable<TradesStreamResponse>;
27
- };
28
- close(): void;
29
- };
30
- type StreamRunSdkFactory = (options: TInvestOptions) => StreamRunSdk;
10
+ import { type StreamRunClock, type StreamRunElapsedClock, type StreamRunSdkFactory } from './stream-session';
31
11
  type StreamRunConfigReader = (path: string) => Promise<string>;
32
- type StreamRunClock = () => Date;
33
- type StreamRunElapsedClock = () => number;
34
12
  type StreamRunDependencies = {
35
13
  createSdk?: StreamRunSdkFactory;
36
14
  readConfig?: StreamRunConfigReader;
@@ -4,8 +4,7 @@
4
4
  *
5
5
  * Здесь допустимы:
6
6
  * - чтение stream config и применение runtime overrides;
7
- * - выбор generated stream method через SDK facade;
8
- * - управление lifecycle долгоживущего stream-процесса;
7
+ * - передача validated config и runtime policy в stream session;
9
8
  *
10
9
  * Здесь не должно быть JSONL event formatting rules или transport adapter logic.
11
10
  */
@@ -19,8 +18,8 @@ const command_options_1 = require("../../args/command-options");
19
18
  const t_invest_node_sdk_1 = require("../../t-invest-node-sdk");
20
19
  const config_1 = require("./config");
21
20
  const reporter_1 = require("./reporter");
21
+ const stream_session_1 = require("./stream-session");
22
22
  const streamRunCommandPath = ['stream', 'run'];
23
- const maxTimerDelayMs = 2_147_483_647;
24
23
  const defaultStreamRunSdkFactory = (options) => new t_invest_node_sdk_1.TInvestNodeSDK(options);
25
24
  const defaultStreamRunConfigReader = (path) => (0, promises_1.readFile)(path, 'utf8');
26
25
  const streamRunOptionsSchema = (0, command_options_1.withSdkOptions)({
@@ -72,7 +71,11 @@ async function createStreamRunOutput(options, provided, dependencies) {
72
71
  const config = (0, config_1.parseStreamRunConfig)(await dependencies.readConfig(options.config));
73
72
  const runtime = resolveStreamRunRuntime(config.runtime, options, provided);
74
73
  const sdkOptions = (0, args_1.resolveSdkOptionsFromCommandOptions)(options);
75
- return runStreamRunSession(config, runtime, sdkOptions, dependencies);
74
+ return (0, stream_session_1.runStreamRunSession)(config, runtime, sdkOptions, {
75
+ createSdk: dependencies.createSdk,
76
+ now: dependencies.now,
77
+ elapsedNow: dependencies.elapsedNow
78
+ });
76
79
  }
77
80
  function resolveStreamRunRuntime(runtime, options, provided) {
78
81
  return {
@@ -89,141 +92,3 @@ function resolveStreamRunRuntime(runtime, options, provided) {
89
92
  : runtime.raw
90
93
  };
91
94
  }
92
- function runStreamRunSession(config, runtime, sdkOptions, dependencies) {
93
- return (async function* streamRunSession() {
94
- const sdk = dependencies.createSdk(sdkOptions);
95
- const controller = new AbortController();
96
- try {
97
- const responses = createStreamResponses(config, sdk, controller.signal);
98
- yield* formatStreamRunResponses(config.stream, responses, runtime, dependencies.now, dependencies.elapsedNow, () => {
99
- controller.abort();
100
- });
101
- }
102
- finally {
103
- controller.abort();
104
- sdk.close();
105
- }
106
- })();
107
- }
108
- function createStreamResponses(config, sdk, signal) {
109
- const callOptions = {
110
- signal
111
- };
112
- switch (config.stream) {
113
- case 'marketdata.marketDataStream':
114
- return sdk.marketdataStream.marketDataStream(createInitialMarketDataRequestStream((0, config_1.createMarketDataStreamRequests)(config)), callOptions);
115
- case 'marketdata.marketDataServerSideStream':
116
- return sdk.marketdataStream.marketDataServerSideStream((0, config_1.createMarketDataServerSideStreamRequest)(config), callOptions);
117
- case 'operations.portfolioStream':
118
- return sdk.operationsStream.portfolioStream((0, config_1.createPortfolioStreamRequest)(config), callOptions);
119
- case 'operations.positionsStream':
120
- return sdk.operationsStream.positionsStream((0, config_1.createPositionsStreamRequest)(config), callOptions);
121
- case 'orders.tradesStream':
122
- return sdk.ordersStream.tradesStream((0, config_1.createTradesStreamRequest)(config), callOptions);
123
- }
124
- }
125
- async function* createInitialMarketDataRequestStream(requests) {
126
- for (const request of requests) {
127
- yield request;
128
- }
129
- }
130
- async function* formatStreamRunResponses(stream, responses, runtime, now, elapsedNow, cancelStream) {
131
- const iterator = responses[Symbol.asyncIterator]();
132
- const startedAt = elapsedNow();
133
- let lastResponseAt = startedAt;
134
- let sequence = 1;
135
- let emittedEvents = 0;
136
- let pendingRead;
137
- try {
138
- while (true) {
139
- const timeoutMs = resolveNextTimeoutMs(startedAt, lastResponseAt, runtime, elapsedNow);
140
- if (timeoutMs !== undefined && timeoutMs <= 0) {
141
- break;
142
- }
143
- pendingRead = iterator.next();
144
- const result = await readNextWithTimeout(pendingRead, timeoutMs, elapsedNow);
145
- if (result === streamReadTimedOut) {
146
- cancelStream();
147
- await settleCancelledRead(pendingRead);
148
- pendingRead = undefined;
149
- break;
150
- }
151
- pendingRead = undefined;
152
- if (result.done) {
153
- break;
154
- }
155
- lastResponseAt = elapsedNow();
156
- const line = (0, reporter_1.formatStreamRunResponse)(result.value, {
157
- stream,
158
- sequence,
159
- receivedAt: now().toISOString(),
160
- includePings: runtime.includePings,
161
- includeSubscriptionEvents: runtime.includeSubscriptionEvents,
162
- raw: runtime.raw
163
- });
164
- if (line === undefined) {
165
- continue;
166
- }
167
- yield line;
168
- sequence += 1;
169
- emittedEvents += 1;
170
- if (runtime.maxEvents !== undefined && emittedEvents >= runtime.maxEvents) {
171
- break;
172
- }
173
- }
174
- }
175
- finally {
176
- cancelStream();
177
- if (pendingRead !== undefined) {
178
- await settleCancelledRead(pendingRead);
179
- }
180
- await iterator.return?.();
181
- }
182
- }
183
- function resolveNextTimeoutMs(startedAt, lastResponseAt, runtime, elapsedNow) {
184
- const now = elapsedNow();
185
- const remainingTimeouts = [
186
- runtime.durationMs === undefined ? undefined : runtime.durationMs - (now - startedAt),
187
- runtime.idleTimeoutMs === undefined ? undefined : runtime.idleTimeoutMs - (now - lastResponseAt)
188
- ].filter((value) => value !== undefined);
189
- if (remainingTimeouts.length === 0) {
190
- return undefined;
191
- }
192
- return Math.min(...remainingTimeouts);
193
- }
194
- const streamReadTimedOut = Symbol('streamReadTimedOut');
195
- async function readNextWithTimeout(next, timeoutMs, elapsedNow) {
196
- if (timeoutMs === undefined) {
197
- return next;
198
- }
199
- const deadline = elapsedNow() + timeoutMs;
200
- let timeout;
201
- const timedOut = new Promise((resolve) => {
202
- const schedule = () => {
203
- const remaining = deadline - elapsedNow();
204
- if (remaining <= 0) {
205
- resolve(streamReadTimedOut);
206
- return;
207
- }
208
- timeout = setTimeout(schedule, Math.min(remaining, maxTimerDelayMs));
209
- };
210
- schedule();
211
- });
212
- try {
213
- return await Promise.race([next, timedOut]);
214
- }
215
- finally {
216
- if (timeout !== undefined) {
217
- clearTimeout(timeout);
218
- }
219
- }
220
- }
221
- async function settleCancelledRead(read) {
222
- try {
223
- await read;
224
- }
225
- catch {
226
- // Основной read outcome уже определен до cleanup; ошибка после session
227
- // cancellation не должна подменять timeout или ранее полученную ошибку.
228
- }
229
- }
@@ -8,12 +8,9 @@
8
8
  *
9
9
  * Здесь не должно быть SDK calls или stdout/stderr output logic.
10
10
  */
11
- import { type MarketDataRequest, SubscriptionInterval, type MarketDataServerSideStreamRequest } from '../../../generated/marketdata';
12
- import type { PortfolioStreamRequest, PositionsStreamRequest } from '../../../generated/operations';
13
- import type { TradesStreamRequest } from '../../../generated/orders';
11
+ import { type MarketDataRequest, SubscriptionInterval } from '../../../generated/marketdata';
14
12
  export declare const streamRunStreamNames: readonly ['marketdata.marketDataStream', 'marketdata.marketDataServerSideStream', 'operations.portfolioStream', 'operations.positionsStream', 'orders.tradesStream'];
15
13
  export type StreamRunStreamName = typeof streamRunStreamNames[number];
16
- export type SupportedStreamRunStreamName = StreamRunStreamName;
17
14
  export type StreamRunRuntime = {
18
15
  format: 'jsonl';
19
16
  maxEvents?: number | undefined;
@@ -24,33 +21,28 @@ export type StreamRunRuntime = {
24
21
  raw: boolean;
25
22
  };
26
23
  export type StreamRunConfig = {
27
- stream: SupportedStreamRunStreamName;
24
+ stream: StreamRunStreamName;
28
25
  accounts?: string[];
29
26
  requests?: MarketDataRequest[];
30
27
  subscriptions?: MarketDataSubscriptions;
31
28
  runtime: StreamRunRuntime;
32
29
  };
33
- type MarketDataSubscriptions = {
30
+ export type MarketDataSubscriptions = {
34
31
  candles?: CandleSubscriptionConfig[] | undefined;
35
32
  orderBooks?: OrderBookSubscriptionConfig[] | undefined;
36
33
  trades?: InstrumentSubscriptionConfig[] | undefined;
37
34
  info?: InstrumentSubscriptionConfig[] | undefined;
38
35
  lastPrices?: InstrumentSubscriptionConfig[] | undefined;
39
36
  };
40
- type CandleSubscriptionConfig = InstrumentSubscriptionConfig & {
37
+ export type CandleSubscriptionConfig = InstrumentSubscriptionConfig & {
41
38
  interval: SubscriptionInterval;
42
39
  waitingClose: boolean;
43
40
  };
44
- type OrderBookSubscriptionConfig = InstrumentSubscriptionConfig & {
41
+ export type OrderBookSubscriptionConfig = InstrumentSubscriptionConfig & {
45
42
  depth: number;
46
43
  };
47
- type InstrumentSubscriptionConfig = {
44
+ export type InstrumentSubscriptionConfig = {
48
45
  instrumentId: string;
49
46
  };
50
47
  export declare function parseStreamRunConfig(json: string): StreamRunConfig;
51
- export declare function createMarketDataStreamRequests(config: StreamRunConfig): MarketDataRequest[];
52
- export declare function createMarketDataServerSideStreamRequest(config: StreamRunConfig): MarketDataServerSideStreamRequest;
53
- export declare function createPortfolioStreamRequest(config: StreamRunConfig): PortfolioStreamRequest;
54
- export declare function createPositionsStreamRequest(config: StreamRunConfig): PositionsStreamRequest;
55
- export declare function createTradesStreamRequest(config: StreamRunConfig): TradesStreamRequest;
56
- export {};
48
+ export declare function resolveCandlesWaitingClose(candles: CandleSubscriptionConfig[]): boolean;