@quantform/core 0.7.22 → 0.7.24

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 (194) hide show
  1. package/lib/app.d.ts +12 -0
  2. package/lib/app.d.ts.map +1 -0
  3. package/lib/app.js +35 -0
  4. package/lib/cli/build.d.ts.map +1 -1
  5. package/lib/cli/build.js +8 -18
  6. package/lib/cli/index.js +3 -12
  7. package/lib/cli/internal/script.d.ts +1 -1
  8. package/lib/cli/internal/script.d.ts.map +1 -1
  9. package/lib/cli/internal/script.js +8 -28
  10. package/lib/cli/live.js +10 -22
  11. package/lib/cli/paper.js +10 -22
  12. package/lib/cli/replay.d.ts.map +1 -1
  13. package/lib/cli/replay.js +15 -26
  14. package/lib/index.d.ts +1 -6
  15. package/lib/index.d.ts.map +1 -1
  16. package/lib/index.js +1 -6
  17. package/lib/make-test-module.d.ts.map +1 -1
  18. package/lib/make-test-module.js +18 -20
  19. package/lib/module.d.ts.map +1 -1
  20. package/lib/module.js +9 -24
  21. package/lib/module.spec.js +8 -17
  22. package/lib/replay/use-replay-options.d.ts +5 -4
  23. package/lib/replay/use-replay-options.d.ts.map +1 -1
  24. package/lib/replay/use-replay-options.js +5 -1
  25. package/lib/replay/use-replay-scheduler.d.ts +7 -6
  26. package/lib/replay/use-replay-scheduler.d.ts.map +1 -1
  27. package/lib/replay/use-replay-scheduler.js +64 -70
  28. package/lib/replay/use-replay-storage-buffer.d.ts +3 -2
  29. package/lib/replay/use-replay-storage-buffer.d.ts.map +1 -1
  30. package/lib/replay/use-replay-storage-buffer.js +12 -23
  31. package/lib/replay/use-replay-storage-cursor.d.ts +9 -8
  32. package/lib/replay/use-replay-storage-cursor.d.ts.map +1 -1
  33. package/lib/replay/use-replay-storage-cursor.js +17 -25
  34. package/lib/replay/use-replay-storage.d.ts +5 -4
  35. package/lib/replay/use-replay-storage.d.ts.map +1 -1
  36. package/lib/replay/use-replay-storage.js +32 -39
  37. package/lib/session/use-session-storage.d.ts +1 -1
  38. package/lib/session/use-session-storage.d.ts.map +1 -1
  39. package/lib/session/use-session-storage.js +8 -5
  40. package/lib/shared/environment.js +1 -1
  41. package/lib/shared/index.d.ts +0 -1
  42. package/lib/shared/index.d.ts.map +1 -1
  43. package/lib/shared/index.js +0 -1
  44. package/lib/simulator/use-simulator.spec.js +17 -30
  45. package/lib/storage/in-memory/in-memory-storage.d.ts.map +1 -1
  46. package/lib/storage/in-memory/in-memory-storage.factory.js +2 -2
  47. package/lib/storage/in-memory/in-memory-storage.js +56 -55
  48. package/lib/storage/in-memory/in-memory-storage.spec.js +90 -100
  49. package/lib/storage/storage.d.ts +9 -8
  50. package/lib/storage/storage.d.ts.map +1 -1
  51. package/lib/storage/storage.js +8 -2
  52. package/lib/storage/use-cache.d.ts +1 -1
  53. package/lib/storage/use-cache.d.ts.map +1 -1
  54. package/lib/storage/use-cache.js +5 -5
  55. package/lib/storage/use-cache.spec.js +14 -25
  56. package/lib/storage/use-storage.d.ts +1 -1
  57. package/lib/storage/use-storage.d.ts.map +1 -1
  58. package/lib/storage/use-storage.js +9 -6
  59. package/lib/use-execution-mode.js +2 -2
  60. package/lib/use-hash.spec.js +3 -6
  61. package/lib/use-logger.d.ts +1 -1
  62. package/lib/use-logger.d.ts.map +1 -1
  63. package/lib/use-logger.js +10 -7
  64. package/lib/use-memo.spec.js +14 -25
  65. package/lib/use-socket.d.ts +3 -2
  66. package/lib/use-socket.d.ts.map +1 -1
  67. package/lib/use-socket.js +2 -2
  68. package/lib/use-timestamp.d.ts +14 -1
  69. package/lib/use-timestamp.d.ts.map +1 -1
  70. package/lib/use-timestamp.js +30 -3
  71. package/lib/with-request.d.ts +2 -1
  72. package/lib/with-request.d.ts.map +1 -1
  73. package/lib/with-request.js +4 -13
  74. package/package.json +6 -10
  75. package/src/app.ts +52 -0
  76. package/src/cli/build.ts +11 -6
  77. package/src/cli/internal/script.ts +25 -54
  78. package/src/cli/replay.ts +13 -2
  79. package/src/index.ts +1 -6
  80. package/src/make-test-module.ts +12 -2
  81. package/src/module.ts +0 -3
  82. package/src/replay/use-replay-options.ts +7 -3
  83. package/src/replay/use-replay-scheduler.ts +75 -67
  84. package/src/replay/use-replay-storage-buffer.ts +2 -1
  85. package/src/replay/use-replay-storage-cursor.ts +33 -28
  86. package/src/replay/use-replay-storage.ts +36 -27
  87. package/src/session/use-session-storage.ts +7 -5
  88. package/src/shared/index.ts +0 -1
  89. package/src/storage/in-memory/in-memory-storage.spec.ts +55 -54
  90. package/src/storage/in-memory/in-memory-storage.ts +24 -7
  91. package/src/storage/storage.ts +16 -7
  92. package/src/storage/use-cache.ts +4 -4
  93. package/src/storage/use-storage.ts +8 -6
  94. package/src/use-hash.spec.ts +3 -6
  95. package/src/use-logger.ts +9 -6
  96. package/src/use-socket.ts +5 -5
  97. package/src/use-timestamp.ts +41 -3
  98. package/src/with-request.ts +3 -3
  99. package/lib/asset/asset.d.ts +0 -41
  100. package/lib/asset/asset.d.ts.map +0 -1
  101. package/lib/asset/asset.js +0 -76
  102. package/lib/asset/asset.spec.d.ts +0 -2
  103. package/lib/asset/asset.spec.d.ts.map +0 -1
  104. package/lib/asset/asset.spec.js +0 -54
  105. package/lib/asset/index.d.ts +0 -2
  106. package/lib/asset/index.d.ts.map +0 -1
  107. package/lib/asset/index.js +0 -17
  108. package/lib/component/distinct-until-timesamp-changed.d.ts +0 -5
  109. package/lib/component/distinct-until-timesamp-changed.d.ts.map +0 -1
  110. package/lib/component/distinct-until-timesamp-changed.js +0 -9
  111. package/lib/component/error.d.ts +0 -17
  112. package/lib/component/error.d.ts.map +0 -1
  113. package/lib/component/error.js +0 -33
  114. package/lib/component/index.d.ts +0 -8
  115. package/lib/component/index.d.ts.map +0 -1
  116. package/lib/component/index.js +0 -23
  117. package/lib/component/ohlc-operator.d.ts +0 -11
  118. package/lib/component/ohlc-operator.d.ts.map +0 -1
  119. package/lib/component/ohlc-operator.js +0 -69
  120. package/lib/component/ohlc-operator.spec.d.ts +0 -2
  121. package/lib/component/ohlc-operator.spec.d.ts.map +0 -1
  122. package/lib/component/ohlc-operator.spec.js +0 -110
  123. package/lib/component/ohlc.d.ts +0 -12
  124. package/lib/component/ohlc.d.ts.map +0 -1
  125. package/lib/component/ohlc.js +0 -20
  126. package/lib/component/ohlc.spec.d.ts +0 -2
  127. package/lib/component/ohlc.spec.d.ts.map +0 -1
  128. package/lib/component/ohlc.spec.js +0 -25
  129. package/lib/component/timeframe.d.ts +0 -15
  130. package/lib/component/timeframe.d.ts.map +0 -1
  131. package/lib/component/timeframe.js +0 -21
  132. package/lib/core.d.ts +0 -3
  133. package/lib/core.d.ts.map +0 -1
  134. package/lib/core.js +0 -17
  135. package/lib/instrument/commission/commission.d.ts +0 -16
  136. package/lib/instrument/commission/commission.d.ts.map +0 -1
  137. package/lib/instrument/commission/commission.js +0 -28
  138. package/lib/instrument/commission/commission.spec.d.ts +0 -2
  139. package/lib/instrument/commission/commission.spec.d.ts.map +0 -1
  140. package/lib/instrument/commission/commission.spec.js +0 -30
  141. package/lib/instrument/index.d.ts +0 -3
  142. package/lib/instrument/index.d.ts.map +0 -1
  143. package/lib/instrument/index.js +0 -18
  144. package/lib/instrument/instrument.d.ts +0 -28
  145. package/lib/instrument/instrument.d.ts.map +0 -1
  146. package/lib/instrument/instrument.js +0 -53
  147. package/lib/instrument/instrument.spec.d.ts +0 -2
  148. package/lib/instrument/instrument.spec.d.ts.map +0 -1
  149. package/lib/instrument/instrument.spec.js +0 -51
  150. package/lib/operators.d.ts +0 -5
  151. package/lib/operators.d.ts.map +0 -1
  152. package/lib/operators.js +0 -16
  153. package/lib/shared/datetime.d.ts +0 -3
  154. package/lib/shared/datetime.d.ts.map +0 -1
  155. package/lib/shared/datetime.js +0 -7
  156. package/lib/strategy.d.ts +0 -15
  157. package/lib/strategy.d.ts.map +0 -1
  158. package/lib/strategy.js +0 -26
  159. package/lib/strategy.spec.d.ts +0 -2
  160. package/lib/strategy.spec.d.ts.map +0 -1
  161. package/lib/strategy.spec.js +0 -34
  162. package/lib/when-socket.d.ts +0 -8
  163. package/lib/when-socket.d.ts.map +0 -1
  164. package/lib/when-socket.js +0 -53
  165. package/lib/with-memo.d.ts +0 -5
  166. package/lib/with-memo.d.ts.map +0 -1
  167. package/lib/with-memo.js +0 -20
  168. package/lib/with-memo.spec.d.ts +0 -2
  169. package/lib/with-memo.spec.d.ts.map +0 -1
  170. package/lib/with-memo.spec.js +0 -47
  171. package/src/asset/asset.spec.ts +0 -70
  172. package/src/asset/asset.ts +0 -89
  173. package/src/asset/index.ts +0 -1
  174. package/src/component/distinct-until-timesamp-changed.ts +0 -11
  175. package/src/component/error.ts +0 -32
  176. package/src/component/index.ts +0 -7
  177. package/src/component/ohlc-operator.spec.ts +0 -125
  178. package/src/component/ohlc-operator.ts +0 -122
  179. package/src/component/ohlc.spec.ts +0 -30
  180. package/src/component/ohlc.ts +0 -18
  181. package/src/component/timeframe.ts +0 -17
  182. package/src/core.ts +0 -16
  183. package/src/instrument/commission/commission.spec.ts +0 -35
  184. package/src/instrument/commission/commission.ts +0 -27
  185. package/src/instrument/index.ts +0 -2
  186. package/src/instrument/instrument.spec.ts +0 -76
  187. package/src/instrument/instrument.ts +0 -65
  188. package/src/operators.ts +0 -18
  189. package/src/shared/datetime.ts +0 -5
  190. package/src/strategy.spec.ts +0 -42
  191. package/src/strategy.ts +0 -36
  192. package/src/when-socket.ts +0 -61
  193. package/src/with-memo.spec.ts +0 -46
  194. package/src/with-memo.ts +0 -33
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const asset_1 = require("./asset");
4
- const instrument_1 = require("./instrument");
5
3
  const use_hash_1 = require("./use-hash");
6
4
  describe(use_hash_1.useHash.name, () => {
7
5
  it.each([
8
- [[(0, asset_1.assetOf)('binance:btc')], 'binance:btc'],
9
- [[(0, asset_1.assetOf)('binance:btc'), 'test'], 'binance:btc/test'],
10
- [[(0, instrument_1.instrumentOf)('binance:btc-usdt')], 'binance:btc-usdt'],
11
- [[(0, instrument_1.instrumentOf)('binance:btc-usdt'), 123], 'binance:btc-usdt/123']
6
+ [['binance:btc'], 'binance:btc'],
7
+ [['binance:btc', 'test'], 'binance:btc/test'],
8
+ [['binance:btc-usdt', 123], 'binance:btc-usdt/123']
12
9
  ])('hash list of dependencies from %p to %p', (dependencies, hashed) => {
13
10
  const hash = (0, use_hash_1.useHash)(dependencies);
14
11
  expect(hash).toEqual(hashed);
@@ -16,5 +16,5 @@ export declare class ConsoleLoggerFactory implements ILoggerFactory {
16
16
  /**
17
17
  *
18
18
  */
19
- export declare const useLogger: (context: string, tint?: string | undefined) => ILogger;
19
+ export declare function useLogger(context: string, tint?: string): ILogger;
20
20
  //# sourceMappingURL=use-logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-logger.d.ts","sourceRoot":"","sources":["../src/use-logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAC;AAMlD,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACjD;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC9C;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,UAAU,CAKzD;AAED,qBAAa,oBAAqB,YAAW,cAAc;IACzD,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IA6B5C,OAAO,CAAC,QAAQ,CASd;CACH;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,yDAErB,CAAC"}
1
+ {"version":3,"file":"use-logger.d.ts","sourceRoot":"","sources":["../src/use-logger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAc,MAAM,UAAU,CAAC;AAMlD,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/C,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;CACjD;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC9C;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,cAAc,GAAG,UAAU,CAKzD;AAED,qBAAa,oBAAqB,YAAW,cAAc;IACzD,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO;IA6B5C,OAAO,CAAC,QAAQ,CASd;CACH;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,WAKvD"}
package/lib/use-logger.js CHANGED
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useLogger = exports.ConsoleLoggerFactory = exports.logger = void 0;
7
7
  const chalk_1 = __importDefault(require("chalk"));
8
8
  const module_1 = require("./module");
9
+ const use_memo_1 = require("./use-memo");
9
10
  const use_timestamp_1 = require("./use-timestamp");
10
- const with_memo_1 = require("./with-memo");
11
11
  const token = Symbol('logger');
12
12
  function logger(logger) {
13
13
  return {
@@ -28,18 +28,18 @@ class ConsoleLoggerFactory {
28
28
  };
29
29
  }
30
30
  for(context, tint) {
31
- const prefix = () => `${chalk_1.default.hex(tint !== null && tint !== void 0 ? tint : this.colorize(context))(new Date((0, use_timestamp_1.useTimestamp)()).toISOString())} ${chalk_1.default.hex(tint !== null && tint !== void 0 ? tint : this.colorize(context))(context)}`;
31
+ const prefix = () => `${chalk_1.default.hex(tint ?? this.colorize(context))(new Date(Number((0, use_timestamp_1.convert)((0, use_timestamp_1.useTimestamp)().timestamp, 'ns', 'ms'))).toISOString())} ${chalk_1.default.hex(tint ?? this.colorize(context))(context)}`;
32
32
  return {
33
- info: (message, ...params) => (params === null || params === void 0 ? void 0 : params.length)
33
+ info: (message, ...params) => params?.length
34
34
  ? console.info(`${prefix()}: ${message}`, params)
35
35
  : console.info(`${prefix()}: ${message}`),
36
- debug: (message, ...params) => (params === null || params === void 0 ? void 0 : params.length)
36
+ debug: (message, ...params) => params?.length
37
37
  ? console.debug(`${prefix()}: ${message}`, params)
38
38
  : console.debug(`${prefix()}: ${message}`),
39
- warn: (message, ...params) => (params === null || params === void 0 ? void 0 : params.length)
39
+ warn: (message, ...params) => params?.length
40
40
  ? console.warn(`${prefix()}: ${message}`, params)
41
41
  : console.warn(`${prefix()}: ${message}`),
42
- error: (message, ...params) => (params === null || params === void 0 ? void 0 : params.length)
42
+ error: (message, ...params) => params?.length
43
43
  ? console.error(`${prefix()}: ${chalk_1.default.red(message)}`, params)
44
44
  : console.error(`${prefix()}: ${chalk_1.default.red(message)}`)
45
45
  };
@@ -49,4 +49,7 @@ exports.ConsoleLoggerFactory = ConsoleLoggerFactory;
49
49
  /**
50
50
  *
51
51
  */
52
- exports.useLogger = (0, with_memo_1.withMemo)((context, tint) => (0, module_1.useContext)(token).for(context, tint));
52
+ function useLogger(context, tint) {
53
+ return (0, use_memo_1.useMemo)(() => (0, module_1.useContext)(token).for(context, tint), [context, tint]);
54
+ }
55
+ exports.useLogger = useLogger;
@@ -1,35 +1,24 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const make_test_module_1 = require("./make-test-module");
13
4
  const use_memo_1 = require("./use-memo");
14
5
  describe(use_memo_1.useMemo.name, () => {
15
6
  let fixtures;
16
- beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
17
- fixtures = yield getFixtures();
18
- }));
19
- test('memorize value for dependencies', () => __awaiter(void 0, void 0, void 0, function* () {
20
- const value1 = yield fixtures.givenMemoValue(() => 1, [use_memo_1.useMemo.name]);
21
- const value2 = yield fixtures.givenMemoValue(() => 2, [use_memo_1.useMemo.name]);
7
+ beforeEach(async () => {
8
+ fixtures = await getFixtures();
9
+ });
10
+ test('memorize value for dependencies', async () => {
11
+ const value1 = await fixtures.givenMemoValue(() => 1, [use_memo_1.useMemo.name]);
12
+ const value2 = await fixtures.givenMemoValue(() => 2, [use_memo_1.useMemo.name]);
22
13
  expect(value1).toEqual(1);
23
14
  expect(value2).toEqual(1);
24
- }));
25
- });
26
- function getFixtures() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const { act } = yield (0, make_test_module_1.makeTestModule)([]);
29
- return {
30
- givenMemoValue(value, dependencies) {
31
- return act(() => (0, use_memo_1.useMemo)(value, dependencies));
32
- }
33
- };
34
15
  });
16
+ });
17
+ async function getFixtures() {
18
+ const { act } = await (0, make_test_module_1.makeTestModule)([]);
19
+ return {
20
+ givenMemoValue(value, dependencies) {
21
+ return act(() => (0, use_memo_1.useMemo)(value, dependencies));
22
+ }
23
+ };
35
24
  }
@@ -1,4 +1,5 @@
1
1
  import { Observable } from 'rxjs';
2
+ import { Timestamp } from './use-timestamp';
2
3
  export declare function useSocket(url: string, options?: {
3
4
  pingInterval?: number;
4
5
  }): {
@@ -7,13 +8,13 @@ export declare function useSocket(url: string, options?: {
7
8
  * @returns observable emitting message events with timestamps and parsed payloads
8
9
  */
9
10
  watch(): Observable<{
10
- timestamp: number;
11
+ timestamp: Timestamp<'ns'>;
11
12
  payload: unknown;
12
13
  }>;
13
14
  send(message: {
14
15
  payload: unknown;
15
16
  }): Observable<{
16
- timestamp: number;
17
+ timestamp: Timestamp<'ns'>;
17
18
  }>;
18
19
  monitor(): Observable<"opened" | "closed" | "errored">;
19
20
  };
@@ -1 +1 @@
1
- {"version":3,"file":"use-socket.d.ts","sourceRoot":"","sources":["../src/use-socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAqB,MAAM,MAAM,CAAC;AAM5D,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAA2B;IAsBzD;;;OAGG;aACM,WAAW;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;kBAgD9C;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;;EAczE"}
1
+ {"version":3,"file":"use-socket.d.ts","sourceRoot":"","sources":["../src/use-socket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAqB,MAAM,MAAM,CAAC;AAI5D,OAAO,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAE1D,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,YAAY,CAAC,EAAE,MAAM,CAAA;CAA2B;IAsBzD;;;OAGG;aACM,WAAW;QAAE,SAAS,EAAE,UAAU,IAAI,CAAC,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;kBAgDvD;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,WAAW;QAAE,SAAS,EAAE,UAAU,IAAI,CAAC,CAAA;KAAE,CAAC;;EAclF"}
package/lib/use-socket.js CHANGED
@@ -31,7 +31,7 @@ function useSocket(url, options = { pingInterval: 5000 }) {
31
31
  let interval;
32
32
  return new rxjs_1.Observable(stream => {
33
33
  socket.onmessage = it => stream.next({
34
- timestamp: (0, use_timestamp_1.useTimestamp)(),
34
+ ...(0, use_timestamp_1.useTimestamp)(),
35
35
  payload: JSON.parse(it.data)
36
36
  });
37
37
  socket.onerror = it => {
@@ -72,7 +72,7 @@ function useSocket(url, options = { pingInterval: 5000 }) {
72
72
  return (0, rxjs_1.defer)(() => {
73
73
  debug('sent', url, message.payload);
74
74
  socket.send(JSON.stringify(message.payload));
75
- return (0, rxjs_1.of)({ timestamp: (0, use_timestamp_1.useTimestamp)() });
75
+ return (0, rxjs_1.of)((0, use_timestamp_1.useTimestamp)());
76
76
  });
77
77
  },
78
78
  monitor() {
@@ -1,2 +1,15 @@
1
- export declare function useTimestamp(): number;
1
+ export type Unit = 'ns' | 'us' | 'ms' | 's';
2
+ export type Timestamp<Unit> = bigint & {
3
+ readonly __unit: Unit;
4
+ };
5
+ export declare function now(): Timestamp<'ns'>;
6
+ export declare const ns: (value: bigint | number) => Timestamp<'ns'>;
7
+ export declare const us: (value: bigint | number) => Timestamp<'us'>;
8
+ export declare const ms: (value: bigint | number) => Timestamp<'ms'>;
9
+ export declare const s: (value: bigint | number) => Timestamp<'s'>;
10
+ export declare function convert<F extends Unit, T extends Unit>(value: Timestamp<F>, from: F, to: T): Timestamp<T>;
11
+ export declare function add<U extends Unit>(a: Timestamp<U>, b: Timestamp<U>): Timestamp<U>;
12
+ export declare function useTimestamp(): {
13
+ timestamp: Timestamp<'ns'>;
14
+ };
2
15
  //# sourceMappingURL=use-timestamp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-timestamp.d.ts","sourceRoot":"","sources":["../src/use-timestamp.ts"],"names":[],"mappings":"AAIA,wBAAgB,YAAY,WAQ3B"}
1
+ {"version":3,"file":"use-timestamp.d.ts","sourceRoot":"","sources":["../src/use-timestamp.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,GAAG,CAAC;AAE5C,MAAM,MAAM,SAAS,CAAC,IAAI,IAAI,MAAM,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAA;CAAE,CAAC;AAEjE,wBAAgB,GAAG,IAAI,SAAS,CAAC,IAAI,CAAC,CAErC;AAED,eAAO,MAAM,EAAE,UAAW,MAAM,GAAG,MAAM,KAAG,UAAU,IAAI,CACxB,CAAC;AACnC,eAAO,MAAM,EAAE,UAAW,MAAM,GAAG,MAAM,KAAG,UAAU,IAAI,CACxB,CAAC;AACnC,eAAO,MAAM,EAAE,UAAW,MAAM,GAAG,MAAM,KAAG,UAAU,IAAI,CACxB,CAAC;AACnC,eAAO,MAAM,CAAC,UAAW,MAAM,GAAG,MAAM,KAAG,UAAU,GAAG,CACvB,CAAC;AASlC,wBAAgB,OAAO,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,SAAS,IAAI,EACpD,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EACnB,IAAI,EAAE,CAAC,EACP,EAAE,EAAE,CAAC,GACJ,SAAS,CAAC,CAAC,CAAC,CAId;AAED,wBAAgB,GAAG,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAElF;AAED,wBAAgB,YAAY,IAAI;IAAE,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;CAAE,CAQ7D"}
@@ -1,13 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTimestamp = void 0;
3
+ exports.useTimestamp = exports.add = exports.convert = exports.s = exports.ms = exports.us = exports.ns = exports.now = void 0;
4
4
  const use_execution_mode_1 = require("./use-execution-mode");
5
5
  const replay_1 = require("./replay");
6
+ function now() {
7
+ return process.hrtime.bigint();
8
+ }
9
+ exports.now = now;
10
+ const ns = (value) => BigInt(value);
11
+ exports.ns = ns;
12
+ const us = (value) => BigInt(value);
13
+ exports.us = us;
14
+ const ms = (value) => BigInt(value);
15
+ exports.ms = ms;
16
+ const s = (value) => BigInt(value);
17
+ exports.s = s;
18
+ const factors = {
19
+ ns: 1n,
20
+ us: 1000n,
21
+ ms: 1000000n,
22
+ s: 1000000000n
23
+ };
24
+ function convert(value, from, to) {
25
+ const ns = BigInt(value) * factors[from];
26
+ return BigInt(ns / factors[to]);
27
+ }
28
+ exports.convert = convert;
29
+ function add(a, b) {
30
+ return (a + b);
31
+ }
32
+ exports.add = add;
6
33
  function useTimestamp() {
7
34
  const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
8
35
  if (isReplay) {
9
- return (0, replay_1.useReplayScheduler)().timestamp();
36
+ return { timestamp: (0, replay_1.useReplayScheduler)().timestamp() };
10
37
  }
11
- return Date.now();
38
+ return { timestamp: now() };
12
39
  }
13
40
  exports.useTimestamp = useTimestamp;
@@ -1,4 +1,5 @@
1
1
  import { Observable } from 'rxjs';
2
+ import { Timestamp } from './use-timestamp';
2
3
  export type RequestMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
3
4
  export declare class RequestNetworkError extends Error {
4
5
  readonly statusCode: number;
@@ -10,7 +11,7 @@ export declare function withRequest({ method, url, headers, body }: {
10
11
  headers?: Record<string, any>;
11
12
  body?: string;
12
13
  }): Observable<{
13
- timestamp: number;
14
+ timestamp: Timestamp<'ns'>;
14
15
  payload: unknown;
15
16
  }>;
16
17
  //# sourceMappingURL=with-request.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"with-request.d.ts","sourceRoot":"","sources":["../src/with-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAMlC,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,OAAO,CAAC;AAEZ,qBAAa,mBAAoB,SAAQ,KAAK;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CAGxC;AAED,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,GAAG,EACH,OAAO,EACP,IAAI,EACL,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;eAGoC,MAAM;aAAW,OAAO;GA6C5D"}
1
+ {"version":3,"file":"with-request.d.ts","sourceRoot":"","sources":["../src/with-request.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAIlC,OAAO,EAAE,SAAS,EAAgB,MAAM,iBAAiB,CAAC;AAE1D,MAAM,MAAM,aAAa,GACrB,KAAK,GACL,MAAM,GACN,MAAM,GACN,KAAK,GACL,QAAQ,GACR,SAAS,GACT,SAAS,GACT,OAAO,GACP,OAAO,CAAC;AAEZ,qBAAa,mBAAoB,SAAQ,KAAK;IAChC,QAAQ,CAAC,UAAU,EAAE,MAAM;gBAAlB,UAAU,EAAE,MAAM;CAGxC;AAED,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,GAAG,EACH,OAAO,EACP,IAAI,EACL,EAAE;IACD,MAAM,EAAE,aAAa,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;eAGoC,UAAU,IAAI,CAAC;aAAW,OAAO;GA6CrE"}
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.withRequest = exports.RequestNetworkError = void 0;
13
4
  const node_crypto_1 = require("node:crypto");
@@ -28,8 +19,8 @@ function withRequest({ method, url, headers, body }) {
28
19
  const correlationId = (0, node_crypto_1.randomUUID)();
29
20
  debug('requesting', { correlationId, method, url, headers, body });
30
21
  (0, undici_1.request)(url, { method, headers, body })
31
- .then(({ statusCode, body }) => __awaiter(this, void 0, void 0, function* () {
32
- const json = yield body.json();
22
+ .then(async ({ statusCode, body }) => {
23
+ const json = await body.json();
33
24
  debug('received', {
34
25
  correlationId,
35
26
  method,
@@ -49,9 +40,9 @@ function withRequest({ method, url, headers, body }) {
49
40
  subscriber.error(new RequestNetworkError(statusCode));
50
41
  }
51
42
  else {
52
- subscriber.next({ timestamp: (0, use_timestamp_1.useTimestamp)(), payload: json });
43
+ subscriber.next({ ...(0, use_timestamp_1.useTimestamp)(), payload: json });
53
44
  }
54
- }))
45
+ })
55
46
  .catch((e) => {
56
47
  error(`errored`, {
57
48
  method,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantform/core",
3
- "version": "0.7.22",
3
+ "version": "0.7.24",
4
4
  "license": "MIT",
5
5
  "author": "Mateusz Majchrzak",
6
6
  "description": "Node.js library for building systematic trading strategies in reactive way.",
@@ -17,24 +17,20 @@
17
17
  "main": "lib/index.js",
18
18
  "typings": "lib/index.d.ts",
19
19
  "dependencies": {
20
- "@swc/cli": "^0.1.62",
21
- "@swc/core": "^1.3.44",
22
- "@types/ws": "^8.5.4",
23
- "chalk": "4.1.2",
24
- "cli-progress": "^3.12.0",
20
+ "chalk": "^4.1.2",
25
21
  "commander": "^10.0.0",
26
22
  "decimal.js": "^10.4.3",
27
- "node-watch": "^0.7.3",
23
+ "node-watch": "^0.7.4",
28
24
  "reflect-metadata": "^0.1.13",
29
25
  "tsyringe": "^4.7.0",
30
26
  "undici": "^5.21.0",
31
27
  "ws": "^8.13.0"
32
28
  },
33
29
  "devDependencies": {
34
- "@types/cli-progress": "^3.11.0",
35
- "@types/tsc-watch": "^4.2.0",
36
30
  "@types/uuid": "^9.0.1",
37
- "rxjs": "^7.8.0"
31
+ "@types/ws": "^8.18.1",
32
+ "rxjs": "^7.8.0",
33
+ "typescript": "^5.0.2"
38
34
  },
39
35
  "peerDependencies": {
40
36
  "rxjs": "^7.8.0"
package/src/app.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { defaultIfEmpty, firstValueFrom, last, Observable } from 'rxjs';
2
+
3
+ import { Dependency, Module } from '@lib/module';
4
+
5
+ import { InMemoryStorageFactory, useStorageFactory } from './storage';
6
+ import { useExecutionMode } from './use-execution-mode';
7
+ import { ConsoleLoggerFactory, logger } from './use-logger';
8
+ import { useMemo } from './use-memo';
9
+
10
+ export type AppStart<T> = {
11
+ run: (dependencies: Dependency[]) => Promise<T | undefined>;
12
+ };
13
+
14
+ export type AppHandle = {
15
+ use: AppUse;
16
+ start: <T>(strategy: () => Observable<T>) => AppStart<T | undefined>;
17
+ };
18
+
19
+ export type AppUse = (module: Dependency | Dependency[]) => AppHandle;
20
+
21
+ export function app(): AppHandle {
22
+ const deps: Dependency[] = [
23
+ useMemo.options(),
24
+ logger(new ConsoleLoggerFactory()),
25
+ useExecutionMode.paperOptions({ recording: false }),
26
+ useStorageFactory.options(new InMemoryStorageFactory())
27
+ ];
28
+
29
+ const start = <T>(strategy: () => Observable<T>): AppStart<T> => ({
30
+ async run(dependencies: Dependency[] = []) {
31
+ const module = new Module([...deps, ...dependencies]);
32
+
33
+ const { act } = await module.awake();
34
+
35
+ return await act(() =>
36
+ firstValueFrom(strategy().pipe(defaultIfEmpty(undefined), last()))
37
+ );
38
+ }
39
+ });
40
+
41
+ const use = (module: Dependency | Dependency[]) => {
42
+ if (Array.isArray(module)) {
43
+ deps.push(...module);
44
+ } else {
45
+ deps.push(module);
46
+ }
47
+
48
+ return { use, start };
49
+ };
50
+
51
+ return { use, start };
52
+ }
package/src/cli/build.ts CHANGED
@@ -4,12 +4,17 @@ import { buildDirectory } from '@lib/cli/internal/workspace';
4
4
 
5
5
  export default async function (): Promise<number> {
6
6
  return new Promise<number>((resolve, reject) => {
7
- const process = spawn('swc', ['./src', '--out-dir', buildDirectory()], {
8
- stdio: 'inherit',
9
- shell: true
10
- });
7
+ const child = spawn(
8
+ 'tsc',
9
+ ['--project', 'tsconfig.json', '--outDir', buildDirectory()],
10
+ {
11
+ cwd: process.cwd(),
12
+ stdio: 'inherit',
13
+ shell: true
14
+ }
15
+ );
11
16
 
12
- process.once('exit', resolve);
13
- process.once('error', reject);
17
+ child.once('exit', resolve);
18
+ child.once('error', reject);
14
19
  });
15
20
  }
@@ -1,21 +1,8 @@
1
1
  import { join } from 'path';
2
- import {
3
- catchError,
4
- finalize,
5
- firstValueFrom,
6
- forkJoin,
7
- fromEvent,
8
- last,
9
- merge,
10
- of,
11
- switchMap,
12
- take
13
- } from 'rxjs';
2
+ import { catchError, finalize, firstValueFrom, fromEvent, merge, of, take } from 'rxjs';
14
3
 
15
- import { core } from '@lib/core';
16
- import { Dependency, Module } from '@lib/module';
17
- import { whenReplayFinished } from '@lib/replay';
18
- import { strategy } from '@lib/strategy';
4
+ import { AppStart } from '@lib/app';
5
+ import { Dependency } from '@lib/module';
19
6
 
20
7
  import { buildDirectory } from './workspace';
21
8
 
@@ -28,43 +15,27 @@ export class Script {
28
15
  async run() {
29
16
  const script = await import(join(buildDirectory(), this.filename));
30
17
 
31
- const { dependencies, description } = script.default as ReturnType<typeof strategy>;
32
-
33
- const module = new Module([...core(), ...dependencies, ...this.dependencies]);
34
-
35
- const { act } = await module.awake();
36
-
37
- return await act(() => {
38
- process.stdin.resume();
39
-
40
- return firstValueFrom(
41
- merge(
42
- forkJoin(description.before.map(before => before()))
43
- .pipe(
44
- switchMap(() =>
45
- forkJoin(description.behavior.map(behavior => behavior())).pipe(last())
46
- )
47
- )
48
- .pipe(last()),
49
- whenReplayFinished().pipe(last()),
50
- fromEvent(process, 'exit'),
51
- fromEvent(process, 'SIGINT'),
52
- fromEvent(process, 'SIGUSR1'),
53
- fromEvent(process, 'SIGUSR2'),
54
- fromEvent(process, 'uncaughtException')
55
- ).pipe(
56
- catchError(e => {
57
- console.error(e);
58
-
59
- return of(e);
60
- }),
61
- take(1),
62
- switchMap(
63
- it => forkJoin(description.after.map(after => after())).pipe(last()) ?? of(it)
64
- ),
65
- finalize(() => process.exit(0))
66
- )
67
- );
68
- });
18
+ const { run } = script.default as AppStart<unknown>;
19
+
20
+ process.stdin.resume();
21
+
22
+ return firstValueFrom(
23
+ merge(
24
+ run(this.dependencies),
25
+ fromEvent(process, 'exit'),
26
+ fromEvent(process, 'SIGINT'),
27
+ fromEvent(process, 'SIGUSR1'),
28
+ fromEvent(process, 'SIGUSR2'),
29
+ fromEvent(process, 'uncaughtException')
30
+ ).pipe(
31
+ catchError(e => {
32
+ console.error(e);
33
+
34
+ return of(e);
35
+ }),
36
+ take(1),
37
+ finalize(() => process.exit(0))
38
+ )
39
+ );
69
40
  }
70
41
  }
package/src/cli/replay.ts CHANGED
@@ -2,6 +2,7 @@ import build from '@lib/cli/build';
2
2
  import { replayOptions } from '@lib/replay';
3
3
  import { useSession } from '@lib/session';
4
4
  import { useExecutionMode } from '@lib/use-execution-mode';
5
+ import { convert, s } from '@lib/use-timestamp';
5
6
 
6
7
  import { Script } from './internal/script';
7
8
 
@@ -13,8 +14,18 @@ export default async function (
13
14
  return;
14
15
  }
15
16
 
16
- const from = options.from ? new Date(options.from).getTime() : 0;
17
- const to = options.to ? new Date(options.to).getTime() : 1893452400; // 01-01-2030;
17
+ const from = convert(
18
+ s(options.from ? new Date(options.from).getTime() : 0),
19
+ 'ms',
20
+ 'ns'
21
+ );
22
+
23
+ const to = convert(
24
+ s(options.to ? new Date(options.to).getTime() : new Date().getTime()),
25
+ 'ms',
26
+ 'ns'
27
+ );
28
+
18
29
  const storage = options.storage ?? 'backtest';
19
30
 
20
31
  const script = new Script(name, [
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from '@lib/component';
1
+ export * from '@lib/app';
2
2
  export * from '@lib/shared';
3
3
  export * from '@lib/storage';
4
4
  export * from '@lib/module';
@@ -6,17 +6,12 @@ export * from '@lib/use-memo';
6
6
  export * from '@lib/use-timestamp';
7
7
  export * from '@lib/simulator';
8
8
  export * from '@lib/make-test-module';
9
- export * from '@lib/core';
10
9
  export * from '@lib/use-execution-mode';
11
10
  export * from '@lib/storage';
12
11
  export * from '@lib/use-logger';
13
12
  export * from '@lib/replay';
14
13
  export * from '@lib/use-socket';
15
- export * from '@lib/when-socket';
16
14
  export * from '@lib/with-request';
17
- export * from '@lib/with-memo';
18
15
  export * from '@lib/session';
19
- export * from '@lib/strategy';
20
- export * from '@lib/operators';
21
16
  export * from '@lib/replay';
22
17
  export * from '@lib/uri';
@@ -1,10 +1,20 @@
1
1
  import { Observable, Subject } from 'rxjs';
2
2
 
3
- import { core } from '@lib/core';
4
3
  import { Dependency, Module } from '@lib/module';
5
4
 
5
+ import { InMemoryStorageFactory, useStorageFactory } from './storage';
6
+ import { useExecutionMode } from './use-execution-mode';
7
+ import { ConsoleLoggerFactory, logger } from './use-logger';
8
+ import { useMemo } from './use-memo';
9
+
6
10
  export async function makeTestModule(dependencies: Dependency[]) {
7
- const module = new Module([...core(), ...dependencies]);
11
+ const module = new Module([
12
+ useMemo.options(),
13
+ logger(new ConsoleLoggerFactory()),
14
+ useExecutionMode.paperOptions({ recording: false }),
15
+ useStorageFactory.options(new InMemoryStorageFactory()),
16
+ ...dependencies
17
+ ]);
8
18
 
9
19
  const { act } = await module.awake();
10
20
 
package/src/module.ts CHANGED
@@ -37,9 +37,6 @@ function missingInjectionTokenError(token: InjectionToken) {
37
37
  return new Error(`Unable to resolve unregistered dependency: ${token.toString()}`);
38
38
  }
39
39
 
40
- /**
41
- *
42
- */
43
40
  let moduleLocalStorage = new AsyncLocalStorage<Module>();
44
41
 
45
42
  export function setAsyncLocalStorage(als: AsyncLocalStorage<Module>) {
@@ -1,10 +1,11 @@
1
1
  import { Dependency, useContext } from '@lib/module';
2
+ import { Timestamp } from '@lib/use-timestamp';
2
3
 
3
4
  const injectionToken = Symbol('replay-options');
4
5
 
5
6
  type ReplayOptions = {
6
- from: number;
7
- to: number;
7
+ from: Timestamp<'ns'>;
8
+ to: Timestamp<'ns'>;
8
9
  limit?: number;
9
10
  storage?: string;
10
11
  };
@@ -13,7 +14,10 @@ type ReplayOptions = {
13
14
  *
14
15
  */
15
16
  export function replayOptions(
16
- options: Omit<ReplayOptions, 'from' | 'to'> & { from: number; to: number }
17
+ options: Omit<ReplayOptions, 'from' | 'to'> & {
18
+ from: Timestamp<'ns'>;
19
+ to: Timestamp<'ns'>;
20
+ }
17
21
  ): Dependency {
18
22
  return {
19
23
  provide: injectionToken,