@quantform/core 0.7.19 → 0.7.21

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 (106) hide show
  1. package/lib/cli/replay.d.ts +1 -0
  2. package/lib/cli/replay.d.ts.map +1 -1
  3. package/lib/cli/replay.js +4 -3
  4. package/lib/index.d.ts +1 -1
  5. package/lib/index.d.ts.map +1 -1
  6. package/lib/index.js +1 -1
  7. package/lib/replay/index.d.ts +3 -6
  8. package/lib/replay/index.d.ts.map +1 -1
  9. package/lib/replay/index.js +3 -6
  10. package/lib/replay/use-replay-options.d.ts +6 -1
  11. package/lib/replay/use-replay-options.d.ts.map +1 -1
  12. package/lib/replay/use-replay-options.js +1 -1
  13. package/lib/{backtest/use-backtest-scheduler.d.ts → replay/use-replay-scheduler.d.ts} +4 -4
  14. package/lib/replay/use-replay-scheduler.d.ts.map +1 -0
  15. package/lib/{backtest/use-backtest-scheduler.js → replay/use-replay-scheduler.js} +6 -6
  16. package/lib/replay/{storage/use-replay-storage-buffer.d.ts → use-replay-storage-buffer.d.ts} +2 -2
  17. package/lib/replay/use-replay-storage-buffer.d.ts.map +1 -0
  18. package/lib/{backtest/use-backtest-query-buffer.js → replay/use-replay-storage-buffer.js} +6 -6
  19. package/lib/replay/{storage/use-replay-storage-cursor.d.ts → use-replay-storage-cursor.d.ts} +16 -2
  20. package/lib/replay/use-replay-storage-cursor.d.ts.map +1 -0
  21. package/lib/{backtest/use-backtest-query-cursor.js → replay/use-replay-storage-cursor.js} +4 -4
  22. package/lib/{backtest/use-backtest-storage.d.ts → replay/use-replay-storage.d.ts} +8 -4
  23. package/lib/replay/use-replay-storage.d.ts.map +1 -0
  24. package/lib/replay/use-replay-storage.js +77 -0
  25. package/lib/replay/use-replay-sync.d.ts +3 -0
  26. package/lib/replay/use-replay-sync.d.ts.map +1 -0
  27. package/lib/{backtest/use-backtest-sync.js → replay/use-replay-sync.js} +5 -5
  28. package/lib/replay/use-replay.d.ts +1 -9
  29. package/lib/replay/use-replay.d.ts.map +1 -1
  30. package/lib/replay/use-replay.js +3 -14
  31. package/lib/replay/when-replay-finished.js +2 -2
  32. package/lib/use-timestamp.js +2 -2
  33. package/package.json +1 -1
  34. package/src/cli/replay.ts +3 -2
  35. package/src/index.ts +1 -1
  36. package/src/replay/index.ts +3 -6
  37. package/src/replay/use-replay-options.ts +10 -2
  38. package/src/{backtest/use-backtest-scheduler.ts → replay/use-replay-scheduler.ts} +8 -9
  39. package/src/{backtest/use-backtest-query-buffer.ts → replay/use-replay-storage-buffer.ts} +5 -5
  40. package/src/replay/use-replay-storage-cursor.ts +48 -0
  41. package/src/replay/use-replay-storage.ts +101 -0
  42. package/src/{backtest/use-backtest-sync.ts → replay/use-replay-sync.ts} +3 -3
  43. package/src/replay/use-replay.ts +3 -24
  44. package/src/replay/when-replay-finished.ts +2 -2
  45. package/src/use-timestamp.ts +2 -2
  46. package/lib/backtest/index.d.ts +0 -7
  47. package/lib/backtest/index.d.ts.map +0 -1
  48. package/lib/backtest/index.js +0 -22
  49. package/lib/backtest/use-backtest-options.d.ts +0 -15
  50. package/lib/backtest/use-backtest-options.d.ts.map +0 -1
  51. package/lib/backtest/use-backtest-options.js +0 -20
  52. package/lib/backtest/use-backtest-query-buffer.d.ts +0 -15
  53. package/lib/backtest/use-backtest-query-buffer.d.ts.map +0 -1
  54. package/lib/backtest/use-backtest-query-cursor.d.ts +0 -30
  55. package/lib/backtest/use-backtest-query-cursor.d.ts.map +0 -1
  56. package/lib/backtest/use-backtest-scheduler.d.ts.map +0 -1
  57. package/lib/backtest/use-backtest-storage.d.ts.map +0 -1
  58. package/lib/backtest/use-backtest-storage.js +0 -65
  59. package/lib/backtest/use-backtest-sync.d.ts +0 -3
  60. package/lib/backtest/use-backtest-sync.d.ts.map +0 -1
  61. package/lib/backtest/use-backtest.d.ts +0 -24
  62. package/lib/backtest/use-backtest.d.ts.map +0 -1
  63. package/lib/backtest/use-backtest.js +0 -14
  64. package/lib/backtest/when-backtest-finished.d.ts +0 -2
  65. package/lib/backtest/when-backtest-finished.d.ts.map +0 -1
  66. package/lib/backtest/when-backtest-finished.js +0 -15
  67. package/lib/replay/replay-guard.d.ts +0 -10
  68. package/lib/replay/replay-guard.d.ts.map +0 -1
  69. package/lib/replay/replay-guard.js +0 -8
  70. package/lib/replay/replay.d.ts +0 -10
  71. package/lib/replay/replay.d.ts.map +0 -1
  72. package/lib/replay/replay.js +0 -9
  73. package/lib/replay/storage/use-replay-storage-buffer.d.ts.map +0 -1
  74. package/lib/replay/storage/use-replay-storage-buffer.js +0 -57
  75. package/lib/replay/storage/use-replay-storage-cursor.d.ts.map +0 -1
  76. package/lib/replay/storage/use-replay-storage-cursor.js +0 -49
  77. package/lib/replay/storage/use-replay-storage.d.ts +0 -13
  78. package/lib/replay/storage/use-replay-storage.d.ts.map +0 -1
  79. package/lib/replay/storage/use-replay-storage.js +0 -39
  80. package/lib/replay/storage/use-replay-storage.spec.d.ts +0 -2
  81. package/lib/replay/storage/use-replay-storage.spec.d.ts.map +0 -1
  82. package/lib/replay/storage/use-replay-storage.spec.js +0 -74
  83. package/lib/replay/use-replay-lock.d.ts +0 -3
  84. package/lib/replay/use-replay-lock.d.ts.map +0 -1
  85. package/lib/replay/use-replay-lock.js +0 -22
  86. package/lib/replay/use-replay-manager.d.ts +0 -28
  87. package/lib/replay/use-replay-manager.d.ts.map +0 -1
  88. package/lib/replay/use-replay-manager.js +0 -68
  89. package/lib/replay/use-replay.spec.d.ts +0 -2
  90. package/lib/replay/use-replay.spec.d.ts.map +0 -1
  91. package/lib/replay/use-replay.spec.js +0 -130
  92. package/src/backtest/index.ts +0 -6
  93. package/src/backtest/use-backtest-options.ts +0 -23
  94. package/src/backtest/use-backtest-query-cursor.ts +0 -40
  95. package/src/backtest/use-backtest-storage.ts +0 -82
  96. package/src/backtest/use-backtest.ts +0 -28
  97. package/src/backtest/when-backtest-finished.ts +0 -20
  98. package/src/replay/replay-guard.ts +0 -11
  99. package/src/replay/replay.ts +0 -13
  100. package/src/replay/storage/use-replay-storage-buffer.ts +0 -52
  101. package/src/replay/storage/use-replay-storage-cursor.ts +0 -44
  102. package/src/replay/storage/use-replay-storage.spec.ts +0 -84
  103. package/src/replay/storage/use-replay-storage.ts +0 -29
  104. package/src/replay/use-replay-lock.ts +0 -29
  105. package/src/replay/use-replay-manager.ts +0 -83
  106. package/src/replay/use-replay.spec.ts +0 -138
@@ -2,5 +2,6 @@ export default function (name: string, options: {
2
2
  id?: string;
3
3
  from?: string;
4
4
  to?: string;
5
+ storage?: string;
5
6
  }): Promise<void>;
6
7
  //# sourceMappingURL=replay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/cli/replay.ts"],"names":[],"mappings":"AAOA,yBACE,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,iBAiBrD"}
1
+ {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/cli/replay.ts"],"names":[],"mappings":"AAOA,yBACE,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,iBAkBvE"}
package/lib/cli/replay.js CHANGED
@@ -18,16 +18,17 @@ const session_1 = require("../session");
18
18
  const use_execution_mode_1 = require("../use-execution-mode");
19
19
  const script_1 = require("./internal/script");
20
20
  function default_1(name, options) {
21
- var _a;
21
+ var _a, _b;
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
23
  if (yield (0, build_1.default)()) {
24
24
  return;
25
25
  }
26
26
  const from = options.from ? new Date(options.from).getTime() : 0;
27
27
  const to = options.to ? new Date(options.to).getTime() : 1893452400; // 01-01-2030;
28
+ const storage = (_a = options.storage) !== null && _a !== void 0 ? _a : 'backtest';
28
29
  const script = new script_1.Script(name, [
29
- session_1.useSession.options({ id: (_a = options.id) !== null && _a !== void 0 ? _a : Date.now().toString() }),
30
- (0, replay_1.replayOptions)({ from, to }),
30
+ session_1.useSession.options({ id: (_b = options.id) !== null && _b !== void 0 ? _b : Date.now().toString() }),
31
+ (0, replay_1.replayOptions)({ from, to, storage }),
31
32
  use_execution_mode_1.useExecutionMode.replayOptions()
32
33
  ]);
33
34
  const output = yield script.run();
package/lib/index.d.ts CHANGED
@@ -18,6 +18,6 @@ export * from './with-memo';
18
18
  export * from './session';
19
19
  export * from './strategy';
20
20
  export * from './operators';
21
- export * from './backtest';
21
+ export * from './replay';
22
22
  export * from './uri';
23
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,yBAAyB,CAAC;AACxC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
package/lib/index.js CHANGED
@@ -34,5 +34,5 @@ __exportStar(require("./with-memo"), exports);
34
34
  __exportStar(require("./session"), exports);
35
35
  __exportStar(require("./strategy"), exports);
36
36
  __exportStar(require("./operators"), exports);
37
- __exportStar(require("./backtest"), exports);
37
+ __exportStar(require("./replay"), exports);
38
38
  __exportStar(require("./uri"), exports);
@@ -1,10 +1,7 @@
1
1
  export * from './use-replay';
2
- export * from './use-replay-lock';
3
2
  export * from './use-replay-options';
4
- export * from './storage/use-replay-storage';
5
- export * from './storage/use-replay-storage-buffer';
6
- export * from './use-replay-manager';
3
+ export * from './use-replay-scheduler';
4
+ export * from './use-replay-storage';
5
+ export * from './use-replay-sync';
7
6
  export * from './when-replay-finished';
8
- export * from './replay';
9
- export * from './replay-guard';
10
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/replay/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,qCAAqC,CAAC;AACpD,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/replay/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC"}
@@ -15,11 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./use-replay"), exports);
18
- __exportStar(require("./use-replay-lock"), exports);
19
18
  __exportStar(require("./use-replay-options"), exports);
20
- __exportStar(require("./storage/use-replay-storage"), exports);
21
- __exportStar(require("./storage/use-replay-storage-buffer"), exports);
22
- __exportStar(require("./use-replay-manager"), exports);
19
+ __exportStar(require("./use-replay-scheduler"), exports);
20
+ __exportStar(require("./use-replay-storage"), exports);
21
+ __exportStar(require("./use-replay-sync"), exports);
23
22
  __exportStar(require("./when-replay-finished"), exports);
24
- __exportStar(require("./replay"), exports);
25
- __exportStar(require("./replay-guard"), exports);
@@ -2,11 +2,16 @@ import { Dependency } from '../module';
2
2
  type ReplayOptions = {
3
3
  from: number;
4
4
  to: number;
5
+ limit?: number;
6
+ storage?: string;
5
7
  };
6
8
  /**
7
9
  *
8
10
  */
9
- export declare function replayOptions(options: ReplayOptions): Dependency;
11
+ export declare function replayOptions(options: Omit<ReplayOptions, 'from' | 'to'> & {
12
+ from: number;
13
+ to: number;
14
+ }): Dependency;
10
15
  /**
11
16
  * Will return current replay execution options.
12
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay-options.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAIrD,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,UAAU,CAKhE;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,qBAAkD,CAAC"}
1
+ {"version":3,"file":"use-replay-options.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAIrD,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,GACzE,UAAU,CASZ;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,qBAAkD,CAAC"}
@@ -9,7 +9,7 @@ const injectionToken = Symbol('replay-options');
9
9
  function replayOptions(options) {
10
10
  return {
11
11
  provide: injectionToken,
12
- useValue: options
12
+ useValue: Object.assign({ storage: 'backtest', limit: 10000 }, options)
13
13
  };
14
14
  }
15
15
  exports.replayOptions = replayOptions;
@@ -1,6 +1,6 @@
1
1
  import { Observable } from 'rxjs';
2
- import { BacktestStorage } from './use-backtest';
3
- export declare const useBacktestScheduler: () => {
2
+ import { ReplayQuery } from './use-replay-storage-cursor';
3
+ export declare const useReplayScheduler: () => {
4
4
  stream: Observable<[{
5
5
  size(): number;
6
6
  peek(): {
@@ -20,9 +20,9 @@ export declare const useBacktestScheduler: () => {
20
20
  timestamp(): number;
21
21
  stop(): void;
22
22
  tryContinue: () => void;
23
- watch<T>(query: BacktestStorage<T>): Observable<{
23
+ watch<T>(query: ReplayQuery<T>): Observable<{
24
24
  timestamp: number;
25
25
  payload: T;
26
26
  }>;
27
27
  };
28
- //# sourceMappingURL=use-backtest-scheduler.d.ts.map
28
+ //# sourceMappingURL=use-replay-scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-scheduler.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAW,MAAM,MAAM,CAAC;AAM/D,OAAO,EAAE,WAAW,EAA0B,MAAM,6BAA6B,CAAC;AAElF,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;mBASmC,MAAM;iBAAW,GAAG;;;;;;mBA+DzB,MAAM;;;CAgBjE,CAAC"}
@@ -9,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.useBacktestScheduler = void 0;
12
+ exports.useReplayScheduler = void 0;
13
13
  const rxjs_1 = require("rxjs");
14
14
  const with_memo_1 = require("../with-memo");
15
- const use_backtest_options_1 = require("./use-backtest-options");
16
- const use_backtest_query_cursor_1 = require("./use-backtest-query-cursor");
17
- exports.useBacktestScheduler = (0, with_memo_1.withMemo)(() => {
18
- const { from } = (0, use_backtest_options_1.useBacktestOptions)();
19
- const { get, cursor } = (0, use_backtest_query_cursor_1.useBacktestQueryCursor)();
15
+ const use_replay_options_1 = require("./use-replay-options");
16
+ const use_replay_storage_cursor_1 = require("./use-replay-storage-cursor");
17
+ exports.useReplayScheduler = (0, with_memo_1.withMemo)(() => {
18
+ const { from } = (0, use_replay_options_1.useReplayOptions)();
19
+ const { get, cursor } = (0, use_replay_storage_cursor_1.useReplayStorageCursor)();
20
20
  let timestamp = from;
21
21
  let stopAcquire = 1;
22
22
  let processing = false;
@@ -1,5 +1,5 @@
1
- import { dependency } from '../../use-hash';
2
- export declare const useReplayStorageBuffer: <T>(dependencies: dependency[]) => {
1
+ import { ReplayQuery } from './use-replay-storage-cursor';
2
+ export declare function useReplayStorageBuffer<T>(storage: ReplayQuery<T>): {
3
3
  size(): number;
4
4
  peek(): {
5
5
  timestamp: number;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-storage-buffer.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage-buffer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC;;;mBAGlC,MAAM;iBAAW,CAAC;;;mBAAlB,MAAM;iBAAW,CAAC;;;;EAwChD"}
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.useBacktestQueryBuffer = void 0;
12
+ exports.useReplayStorageBuffer = void 0;
13
13
  const storage_1 = require("../storage");
14
- const use_backtest_options_1 = require("./use-backtest-options");
15
- function useBacktestQueryBuffer(storage) {
16
- const { from, to } = (0, use_backtest_options_1.useBacktestOptions)();
14
+ const use_replay_options_1 = require("./use-replay-options");
15
+ function useReplayStorageBuffer(storage) {
16
+ const { from, to, limit } = (0, use_replay_options_1.useReplayOptions)();
17
17
  let page = [];
18
18
  let index = 0;
19
19
  let completed = false;
@@ -39,7 +39,7 @@ function useBacktestQueryBuffer(storage) {
39
39
  index = 0;
40
40
  page = yield storage.query({
41
41
  where: { timestamp: (0, storage_1.between)(from, to) },
42
- limit: 10000,
42
+ limit,
43
43
  offset: count,
44
44
  orderBy: 'ASC'
45
45
  });
@@ -49,4 +49,4 @@ function useBacktestQueryBuffer(storage) {
49
49
  }
50
50
  };
51
51
  }
52
- exports.useBacktestQueryBuffer = useBacktestQueryBuffer;
52
+ exports.useReplayStorageBuffer = useReplayStorageBuffer;
@@ -1,6 +1,20 @@
1
- import { dependency } from '../../use-hash';
1
+ import { Query, QueryObject } from '../storage';
2
+ export interface ReplayQuery<V> {
3
+ query(query: Query<QueryObject> & {
4
+ where: {
5
+ timestamp: {
6
+ type: 'between';
7
+ min: number;
8
+ max: number;
9
+ };
10
+ };
11
+ }): Promise<{
12
+ timestamp: number;
13
+ payload: V;
14
+ }[]>;
15
+ }
2
16
  export declare const useReplayStorageCursor: () => {
3
- get<T>(dependencies: dependency[]): {
17
+ get<T>(query: ReplayQuery<T>): {
4
18
  size(): number;
5
19
  peek(): {
6
20
  timestamp: number;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-storage-cursor.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlD,MAAM,WAAW,WAAW,CAAC,CAAC;IAC5B,KAAK,CACH,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,GAAG;QAC1B,KAAK,EAAE;YAAE,SAAS,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAC;KACrE,GACA,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,CAAC,CAAA;KAAE,EAAE,CAAC,CAAC;CACjD;AAED,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCjC,CAAC"}
@@ -9,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.useBacktestQueryCursor = void 0;
12
+ exports.useReplayStorageCursor = void 0;
13
13
  const with_memo_1 = require("../with-memo");
14
- const use_backtest_query_buffer_1 = require("./use-backtest-query-buffer");
15
- exports.useBacktestQueryCursor = (0, with_memo_1.withMemo)(() => {
14
+ const use_replay_storage_buffer_1 = require("./use-replay-storage-buffer");
15
+ exports.useReplayStorageCursor = (0, with_memo_1.withMemo)(() => {
16
16
  const cursors = Array.of();
17
17
  return {
18
18
  get(query) {
19
- const buffer = (0, use_backtest_query_buffer_1.useBacktestQueryBuffer)(query);
19
+ const buffer = (0, use_replay_storage_buffer_1.useReplayStorageBuffer)(query);
20
20
  cursors.push(buffer);
21
21
  return buffer;
22
22
  },
@@ -1,7 +1,6 @@
1
1
  import { InferQueryObject, Query, QueryObject, QueryObjectType } from '../storage';
2
2
  import { Uri } from '../uri';
3
- import { BacktestStorage } from './use-backtest';
4
- export type BacktestStorageQuery<V> = {
3
+ export type ReplayStorageQuery<V> = {
5
4
  sync: <T extends QueryObjectType<K>, K extends QueryObject>(query: Query<InferQueryObject<T>> & {
6
5
  where: {
7
6
  timestamp: {
@@ -17,5 +16,10 @@ export type BacktestStorageQuery<V> = {
17
16
  }[]) => Promise<void>;
18
17
  }) => Promise<void>;
19
18
  };
20
- export declare function useBacktestStorage<V, P extends Record<string, string | number>>(uri: Uri<P>, { sync }: BacktestStorageQuery<V>): BacktestStorage<V>;
21
- //# sourceMappingURL=use-backtest-storage.d.ts.map
19
+ export declare function useReplayStorage<V, P extends Record<string, string | number>>(uri: Uri<P>, { sync }: ReplayStorageQuery<V>): {
20
+ watch: () => import("rxjs").Observable<{
21
+ timestamp: number;
22
+ payload: V;
23
+ }>;
24
+ };
25
+ //# sourceMappingURL=use-replay-storage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-storage.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-storage.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EAGhB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAO/B,MAAM,MAAM,kBAAkB,CAAC,CAAC,IAAI;IAClC,IAAI,EAAE,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,EACxD,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,GAAG;QAClC,KAAK,EAAE;YAAE,SAAS,EAAE;gBAAE,IAAI,EAAE,SAAS,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAC;KACrE,EACD,OAAO,EAAE;QAAE,IAAI,EAAE,CAAC,OAAO,EAAE;YAAE,SAAS,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,CAAC,CAAA;SAAE,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,KAC/E,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AASF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC3E,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EACX,EAAE,IAAI,EAAE,EAAE,kBAAkB,CAAC,CAAC,CAAC;;;;;EA+DhC"}
@@ -0,0 +1,77 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.useReplayStorage = void 0;
13
+ const rxjs_1 = require("rxjs");
14
+ const hash_code_1 = require("../hash-code");
15
+ const storage_1 = require("../storage");
16
+ const use_logger_1 = require("../use-logger");
17
+ const use_memo_1 = require("../use-memo");
18
+ const use_replay_options_1 = require("./use-replay-options");
19
+ const use_replay_scheduler_1 = require("./use-replay-scheduler");
20
+ const storageIndexObject = storage_1.Storage.createObject('index://range', {
21
+ timestamp: 'number',
22
+ uri: 'string',
23
+ min: 'number',
24
+ max: 'number'
25
+ });
26
+ function useReplayStorage(uri, { sync }) {
27
+ const { watch } = (0, use_replay_scheduler_1.useReplayScheduler)();
28
+ const { info } = (0, use_logger_1.useLogger)(useReplayStorage.name);
29
+ const options = (0, use_replay_options_1.useReplayOptions)();
30
+ const storage = (0, storage_1.useStorage)([options.storage]);
31
+ const storageObjectKey = uri.query;
32
+ const storageObject = storage_1.Storage.createObject(storageObjectKey, {
33
+ timestamp: 'number',
34
+ payload: 'string'
35
+ });
36
+ const id = (0, hash_code_1.hashCode)(storageObjectKey);
37
+ return {
38
+ watch: () => (0, use_memo_1.useMemo)(() => watch({
39
+ query(query) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const [index] = yield storage.query(storageIndexObject, {
42
+ limit: 1,
43
+ where: { timestamp: (0, storage_1.eq)(id) }
44
+ });
45
+ const { min, max } = query.where.timestamp;
46
+ if (!index || min < index.min || max > index.max) {
47
+ info(`fetching replay for ${storageObjectKey} started`);
48
+ yield sync(query, {
49
+ save(objects) {
50
+ return __awaiter(this, void 0, void 0, function* () {
51
+ yield storage.save(storageObject, objects.map(it => ({
52
+ timestamp: it.timestamp,
53
+ payload: JSON.stringify(it.payload)
54
+ })));
55
+ });
56
+ }
57
+ });
58
+ yield storage.save(storageIndexObject, [
59
+ {
60
+ timestamp: id,
61
+ max,
62
+ min,
63
+ uri: storageObjectKey
64
+ }
65
+ ]);
66
+ info(`fetching replay for ${storageObjectKey} finished`);
67
+ }
68
+ return (yield storage.query(storageObject, query)).map(it => ({
69
+ timestamp: it.timestamp,
70
+ payload: JSON.parse(it.payload)
71
+ }));
72
+ });
73
+ }
74
+ }).pipe((0, rxjs_1.share)()), [useReplayStorage.name, storageObjectKey])
75
+ };
76
+ }
77
+ exports.useReplayStorage = useReplayStorage;
@@ -0,0 +1,3 @@
1
+ import { Observable } from 'rxjs';
2
+ export declare function useReplaySync<T>(input: Observable<T>): Observable<T>;
3
+ //# sourceMappingURL=use-replay-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-replay-sync.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,UAAU,EAAE,MAAM,MAAM,CAAC;AAM5C,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAYpE"}
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBacktestSync = void 0;
3
+ exports.useReplaySync = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const use_execution_mode_1 = require("../use-execution-mode");
6
- const use_backtest_scheduler_1 = require("./use-backtest-scheduler");
7
- function useBacktestSync(input) {
6
+ const use_replay_scheduler_1 = require("./use-replay-scheduler");
7
+ function useReplaySync(input) {
8
8
  const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
9
9
  if (!isReplay) {
10
10
  return input;
11
11
  }
12
- const { stop, tryContinue } = (0, use_backtest_scheduler_1.useBacktestScheduler)();
12
+ const { stop, tryContinue } = (0, use_replay_scheduler_1.useReplayScheduler)();
13
13
  stop();
14
14
  return input.pipe((0, rxjs_1.finalize)(() => tryContinue()));
15
15
  }
16
- exports.useBacktestSync = useBacktestSync;
16
+ exports.useReplaySync = useReplaySync;
@@ -1,10 +1,2 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from '../use-hash';
3
- export declare function useReplay<T>(input: Observable<{
4
- timestamp: number;
5
- payload: T;
6
- }>, dependencies: dependency[]): Observable<{
7
- timestamp: number;
8
- payload: T;
9
- }>;
1
+ export declare function useReplay<T>(backtest: T, real: T): T;
10
2
  //# sourceMappingURL=use-replay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-replay.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAO,MAAM,MAAM,CAAC;AAGvC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,wBAAgB,SAAS,CAAC,CAAC,EACzB,KAAK,EAAE,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,EACpD,YAAY,EAAE,UAAU,EAAE;eADK,MAAM;aAAW,CAAC;GAkBlD"}
1
+ {"version":3,"file":"use-replay.d.ts","sourceRoot":"","sources":["../../src/replay/use-replay.ts"],"names":[],"mappings":"AAEA,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAIhD"}
@@ -1,20 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useReplay = void 0;
4
- const rxjs_1 = require("rxjs");
5
4
  const use_execution_mode_1 = require("../use-execution-mode");
6
- const use_replay_storage_1 = require("./storage/use-replay-storage");
7
- const use_replay_manager_1 = require("./use-replay-manager");
8
- function useReplay(input, dependencies) {
9
- const { isReplay, recording } = (0, use_execution_mode_1.useExecutionMode)();
10
- if (isReplay) {
11
- const { watch } = (0, use_replay_manager_1.useReplayManager)();
12
- return watch(dependencies);
13
- }
14
- if (recording) {
15
- const { save } = (0, use_replay_storage_1.useReplayStorage)(dependencies);
16
- return input.pipe((0, rxjs_1.tap)(it => save([it])));
17
- }
18
- return input;
5
+ function useReplay(backtest, real) {
6
+ const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
7
+ return isReplay ? backtest : real;
19
8
  }
20
9
  exports.useReplay = useReplay;
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.whenReplayFinished = void 0;
4
4
  const rxjs_1 = require("rxjs");
5
5
  const use_execution_mode_1 = require("../use-execution-mode");
6
- const use_replay_manager_1 = require("./use-replay-manager");
6
+ const use_replay_scheduler_1 = require("./use-replay-scheduler");
7
7
  function whenReplayFinished() {
8
8
  const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
9
9
  if (!isReplay) {
10
10
  return new rxjs_1.Subject().asObservable();
11
11
  }
12
- const { stream } = (0, use_replay_manager_1.useReplayManager)();
12
+ const { stream } = (0, use_replay_scheduler_1.useReplayScheduler)();
13
13
  return (0, rxjs_1.from)(stream).pipe((0, rxjs_1.last)(), (0, rxjs_1.map)(() => true));
14
14
  }
15
15
  exports.whenReplayFinished = whenReplayFinished;
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useTimestamp = void 0;
4
4
  const use_execution_mode_1 = require("./use-execution-mode");
5
- const backtest_1 = require("./backtest");
5
+ const replay_1 = require("./replay");
6
6
  function useTimestamp() {
7
7
  const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
8
8
  if (isReplay) {
9
- return (0, backtest_1.useBacktestScheduler)().timestamp();
9
+ return (0, replay_1.useReplayScheduler)().timestamp();
10
10
  }
11
11
  return Date.now();
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quantform/core",
3
- "version": "0.7.19",
3
+ "version": "0.7.21",
4
4
  "license": "MIT",
5
5
  "author": "Mateusz Majchrzak",
6
6
  "description": "Node.js library for building systematic trading strategies in reactive way.",
package/src/cli/replay.ts CHANGED
@@ -7,7 +7,7 @@ import { Script } from './internal/script';
7
7
 
8
8
  export default async function (
9
9
  name: string,
10
- options: { id?: string; from?: string; to?: string }
10
+ options: { id?: string; from?: string; to?: string; storage?: string }
11
11
  ) {
12
12
  if (await build()) {
13
13
  return;
@@ -15,10 +15,11 @@ export default async function (
15
15
 
16
16
  const from = options.from ? new Date(options.from).getTime() : 0;
17
17
  const to = options.to ? new Date(options.to).getTime() : 1893452400; // 01-01-2030;
18
+ const storage = options.storage ?? 'backtest';
18
19
 
19
20
  const script = new Script(name, [
20
21
  useSession.options({ id: options.id ?? Date.now().toString() }),
21
- replayOptions({ from, to }),
22
+ replayOptions({ from, to, storage }),
22
23
  useExecutionMode.replayOptions()
23
24
  ]);
24
25
  const output = await script.run();
package/src/index.ts CHANGED
@@ -18,5 +18,5 @@ export * from '@lib/with-memo';
18
18
  export * from '@lib/session';
19
19
  export * from '@lib/strategy';
20
20
  export * from '@lib/operators';
21
- export * from '@lib/backtest';
21
+ export * from '@lib/replay';
22
22
  export * from '@lib/uri';
@@ -1,9 +1,6 @@
1
1
  export * from './use-replay';
2
- export * from './use-replay-lock';
3
2
  export * from './use-replay-options';
4
- export * from './storage/use-replay-storage';
5
- export * from './storage/use-replay-storage-buffer';
6
- export * from './use-replay-manager';
3
+ export * from './use-replay-scheduler';
4
+ export * from './use-replay-storage';
5
+ export * from './use-replay-sync';
7
6
  export * from './when-replay-finished';
8
- export * from './replay';
9
- export * from './replay-guard';
@@ -5,15 +5,23 @@ const injectionToken = Symbol('replay-options');
5
5
  type ReplayOptions = {
6
6
  from: number;
7
7
  to: number;
8
+ limit?: number;
9
+ storage?: string;
8
10
  };
9
11
 
10
12
  /**
11
13
  *
12
14
  */
13
- export function replayOptions(options: ReplayOptions): Dependency {
15
+ export function replayOptions(
16
+ options: Omit<ReplayOptions, 'from' | 'to'> & { from: number; to: number }
17
+ ): Dependency {
14
18
  return {
15
19
  provide: injectionToken,
16
- useValue: options
20
+ useValue: {
21
+ storage: 'backtest',
22
+ limit: 10000,
23
+ ...options
24
+ } satisfies ReplayOptions
17
25
  };
18
26
  }
19
27
 
@@ -2,21 +2,20 @@ import { defer, filter, map, Observable, Subject } from 'rxjs';
2
2
 
3
3
  import { withMemo } from '@lib/with-memo';
4
4
 
5
- import { BacktestStorage } from './use-backtest';
6
- import { useBacktestOptions } from './use-backtest-options';
7
- import { useBacktestQueryBuffer } from './use-backtest-query-buffer';
8
- import { useBacktestQueryCursor } from './use-backtest-query-cursor';
5
+ import { useReplayOptions } from './use-replay-options';
6
+ import { useReplayStorageBuffer } from './use-replay-storage-buffer';
7
+ import { ReplayQuery, useReplayStorageCursor } from './use-replay-storage-cursor';
9
8
 
10
- export const useBacktestScheduler = withMemo(() => {
11
- const { from } = useBacktestOptions();
12
- const { get, cursor } = useBacktestQueryCursor();
9
+ export const useReplayScheduler = withMemo(() => {
10
+ const { from } = useReplayOptions();
11
+ const { get, cursor } = useReplayStorageCursor();
13
12
 
14
13
  let timestamp = from;
15
14
  let stopAcquire = 1;
16
15
  let processing = false;
17
16
 
18
17
  const stream$ = new Subject<
19
- [ReturnType<typeof useBacktestQueryBuffer<any>>, { timestamp: number; payload: any }]
18
+ [ReturnType<typeof useReplayStorageBuffer<any>>, { timestamp: number; payload: any }]
20
19
  >();
21
20
 
22
21
  const processNext = async () => {
@@ -79,7 +78,7 @@ export const useBacktestScheduler = withMemo(() => {
79
78
 
80
79
  tryContinue,
81
80
 
82
- watch<T>(query: BacktestStorage<T>): Observable<{ timestamp: number; payload: T }> {
81
+ watch<T>(query: ReplayQuery<T>): Observable<{ timestamp: number; payload: T }> {
83
82
  const storage = get<T>(query);
84
83
 
85
84
  return defer(() => {
@@ -1,10 +1,10 @@
1
1
  import { between } from '@lib/storage';
2
2
 
3
- import { BacktestStorage } from './use-backtest';
4
- import { useBacktestOptions } from './use-backtest-options';
3
+ import { useReplayOptions } from './use-replay-options';
4
+ import { ReplayQuery } from './use-replay-storage-cursor';
5
5
 
6
- export function useBacktestQueryBuffer<T>(storage: BacktestStorage<T>) {
7
- const { from, to } = useBacktestOptions();
6
+ export function useReplayStorageBuffer<T>(storage: ReplayQuery<T>) {
7
+ const { from, to, limit } = useReplayOptions();
8
8
 
9
9
  let page: Array<{ timestamp: number; payload: T }> = [];
10
10
  let index = 0;
@@ -37,7 +37,7 @@ export function useBacktestQueryBuffer<T>(storage: BacktestStorage<T>) {
37
37
 
38
38
  page = await storage.query({
39
39
  where: { timestamp: between(from, to) },
40
- limit: 10000,
40
+ limit,
41
41
  offset: count,
42
42
  orderBy: 'ASC'
43
43
  });