@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
@@ -0,0 +1,48 @@
1
+ import { Query, QueryObject } from '@lib/storage';
2
+ import { withMemo } from '@lib/with-memo';
3
+
4
+ import { useReplayStorageBuffer } from './use-replay-storage-buffer';
5
+
6
+ export interface ReplayQuery<V> {
7
+ query(
8
+ query: Query<QueryObject> & {
9
+ where: { timestamp: { type: 'between'; min: number; max: number } };
10
+ }
11
+ ): Promise<{ timestamp: number; payload: V }[]>;
12
+ }
13
+
14
+ export const useReplayStorageCursor = withMemo(() => {
15
+ const cursors = Array.of<ReturnType<typeof useReplayStorageBuffer<any>>>();
16
+
17
+ return {
18
+ get<T>(query: ReplayQuery<T>) {
19
+ const buffer = useReplayStorageBuffer<T>(query);
20
+
21
+ cursors.push(buffer);
22
+
23
+ return buffer;
24
+ },
25
+
26
+ async cursor() {
27
+ let current: ReturnType<typeof useReplayStorageBuffer<any>> | undefined;
28
+
29
+ for (const cursor of cursors) {
30
+ if (cursor.completed()) {
31
+ continue;
32
+ }
33
+
34
+ if (cursor.size() == 0) {
35
+ await cursor.fetchNextPage();
36
+ }
37
+
38
+ if (cursor.peek()) {
39
+ if (!current || current.peek().timestamp > cursor.peek().timestamp) {
40
+ current = cursor;
41
+ }
42
+ }
43
+ }
44
+
45
+ return current;
46
+ }
47
+ };
48
+ });
@@ -0,0 +1,101 @@
1
+ import { share } from 'rxjs';
2
+
3
+ import { hashCode } from '@lib/hash-code';
4
+ import {
5
+ eq,
6
+ InferQueryObject,
7
+ Query,
8
+ QueryObject,
9
+ QueryObjectType,
10
+ Storage,
11
+ useStorage
12
+ } from '@lib/storage';
13
+ import { Uri } from '@lib/uri';
14
+ import { useLogger } from '@lib/use-logger';
15
+ import { useMemo } from '@lib/use-memo';
16
+
17
+ import { useReplayOptions } from './use-replay-options';
18
+ import { useReplayScheduler } from './use-replay-scheduler';
19
+
20
+ export type ReplayStorageQuery<V> = {
21
+ sync: <T extends QueryObjectType<K>, K extends QueryObject>(
22
+ query: Query<InferQueryObject<T>> & {
23
+ where: { timestamp: { type: 'between'; min: number; max: number } };
24
+ },
25
+ storage: { save: (objects: { timestamp: number; payload: V }[]) => Promise<void> }
26
+ ) => Promise<void>;
27
+ };
28
+
29
+ const storageIndexObject = Storage.createObject('index://range', {
30
+ timestamp: 'number',
31
+ uri: 'string',
32
+ min: 'number',
33
+ max: 'number'
34
+ });
35
+
36
+ export function useReplayStorage<V, P extends Record<string, string | number>>(
37
+ uri: Uri<P>,
38
+ { sync }: ReplayStorageQuery<V>
39
+ ) {
40
+ const { watch } = useReplayScheduler();
41
+ const { info } = useLogger(useReplayStorage.name);
42
+ const options = useReplayOptions();
43
+ const storage = useStorage([options.storage]);
44
+ const storageObjectKey = uri.query;
45
+ const storageObject = Storage.createObject(storageObjectKey, {
46
+ timestamp: 'number',
47
+ payload: 'string'
48
+ });
49
+
50
+ const id = hashCode(storageObjectKey);
51
+
52
+ return {
53
+ watch: () =>
54
+ useMemo(
55
+ () =>
56
+ watch({
57
+ async query(query) {
58
+ const [index] = await storage.query(storageIndexObject, {
59
+ limit: 1,
60
+ where: { timestamp: eq(id) }
61
+ });
62
+
63
+ const { min, max } = query.where.timestamp;
64
+
65
+ if (!index || min < index.min || max > index.max) {
66
+ info(`fetching replay for ${storageObjectKey} started`);
67
+
68
+ await sync(query, {
69
+ async save(objects) {
70
+ await storage.save(
71
+ storageObject,
72
+ objects.map(it => ({
73
+ timestamp: it.timestamp,
74
+ payload: JSON.stringify(it.payload)
75
+ }))
76
+ );
77
+ }
78
+ });
79
+
80
+ await storage.save(storageIndexObject, [
81
+ {
82
+ timestamp: id,
83
+ max,
84
+ min,
85
+ uri: storageObjectKey
86
+ }
87
+ ]);
88
+
89
+ info(`fetching replay for ${storageObjectKey} finished`);
90
+ }
91
+
92
+ return (await storage.query(storageObject, query)).map(it => ({
93
+ timestamp: it.timestamp,
94
+ payload: JSON.parse(it.payload) as V
95
+ }));
96
+ }
97
+ }).pipe(share()),
98
+ [useReplayStorage.name, storageObjectKey]
99
+ )
100
+ };
101
+ }
@@ -2,16 +2,16 @@ import { finalize, Observable } from 'rxjs';
2
2
 
3
3
  import { useExecutionMode } from '@lib/use-execution-mode';
4
4
 
5
- import { useBacktestScheduler } from './use-backtest-scheduler';
5
+ import { useReplayScheduler } from './use-replay-scheduler';
6
6
 
7
- export function useBacktestSync<T>(input: Observable<T>): Observable<T> {
7
+ export function useReplaySync<T>(input: Observable<T>): Observable<T> {
8
8
  const { isReplay } = useExecutionMode();
9
9
 
10
10
  if (!isReplay) {
11
11
  return input;
12
12
  }
13
13
 
14
- const { stop, tryContinue } = useBacktestScheduler();
14
+ const { stop, tryContinue } = useReplayScheduler();
15
15
 
16
16
  stop();
17
17
 
@@ -1,28 +1,7 @@
1
- import { Observable, tap } from 'rxjs';
2
-
3
1
  import { useExecutionMode } from '@lib/use-execution-mode';
4
- import { dependency } from '@lib/use-hash';
5
-
6
- import { useReplayStorage } from './storage/use-replay-storage';
7
- import { useReplayManager } from './use-replay-manager';
8
-
9
- export function useReplay<T>(
10
- input: Observable<{ timestamp: number; payload: T }>,
11
- dependencies: dependency[]
12
- ) {
13
- const { isReplay, recording } = useExecutionMode();
14
-
15
- if (isReplay) {
16
- const { watch } = useReplayManager();
17
-
18
- return watch<T>(dependencies);
19
- }
20
-
21
- if (recording) {
22
- const { save } = useReplayStorage<T>(dependencies);
23
2
 
24
- return input.pipe(tap(it => save([it])));
25
- }
3
+ export function useReplay<T>(backtest: T, real: T) {
4
+ const { isReplay } = useExecutionMode();
26
5
 
27
- return input;
6
+ return isReplay ? backtest : real;
28
7
  }
@@ -2,7 +2,7 @@ import { from, last, map, Subject } from 'rxjs';
2
2
 
3
3
  import { useExecutionMode } from '@lib/use-execution-mode';
4
4
 
5
- import { useReplayManager } from './use-replay-manager';
5
+ import { useReplayScheduler } from './use-replay-scheduler';
6
6
 
7
7
  export function whenReplayFinished() {
8
8
  const { isReplay } = useExecutionMode();
@@ -11,7 +11,7 @@ export function whenReplayFinished() {
11
11
  return new Subject<boolean>().asObservable();
12
12
  }
13
13
 
14
- const { stream } = useReplayManager();
14
+ const { stream } = useReplayScheduler();
15
15
 
16
16
  return from(stream).pipe(
17
17
  last(),
@@ -1,12 +1,12 @@
1
1
  import { useExecutionMode } from '@lib/use-execution-mode';
2
2
 
3
- import { useBacktestScheduler } from './backtest';
3
+ import { useReplayScheduler } from './replay';
4
4
 
5
5
  export function useTimestamp() {
6
6
  const { isReplay } = useExecutionMode();
7
7
 
8
8
  if (isReplay) {
9
- return useBacktestScheduler().timestamp();
9
+ return useReplayScheduler().timestamp();
10
10
  }
11
11
 
12
12
  return Date.now();
@@ -1,7 +0,0 @@
1
- export * from './use-backtest';
2
- export * from './use-backtest-options';
3
- export * from './use-backtest-scheduler';
4
- export * from './use-backtest-storage';
5
- export * from './use-backtest-sync';
6
- export * from './when-backtest-finished';
7
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/backtest/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC"}
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./use-backtest"), exports);
18
- __exportStar(require("./use-backtest-options"), exports);
19
- __exportStar(require("./use-backtest-scheduler"), exports);
20
- __exportStar(require("./use-backtest-storage"), exports);
21
- __exportStar(require("./use-backtest-sync"), exports);
22
- __exportStar(require("./when-backtest-finished"), exports);
@@ -1,15 +0,0 @@
1
- import { Dependency } from '../module';
2
- type BacktestOptions = {
3
- from: number;
4
- to: number;
5
- };
6
- /**
7
- *
8
- */
9
- export declare function backtestOptions(options: BacktestOptions): Dependency;
10
- /**
11
- * Will return current backtest execution options.
12
- */
13
- export declare const useBacktestOptions: () => BacktestOptions;
14
- export {};
15
- //# sourceMappingURL=use-backtest-options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-backtest-options.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAc,MAAM,aAAa,CAAC;AAIrD,KAAK,eAAe,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,UAAU,CAKpE;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,uBAAoD,CAAC"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBacktestOptions = exports.backtestOptions = void 0;
4
- const module_1 = require("../module");
5
- const injectionToken = Symbol('backtest-options');
6
- /**
7
- *
8
- */
9
- function backtestOptions(options) {
10
- return {
11
- provide: injectionToken,
12
- useValue: options
13
- };
14
- }
15
- exports.backtestOptions = backtestOptions;
16
- /**
17
- * Will return current backtest execution options.
18
- */
19
- const useBacktestOptions = () => (0, module_1.useContext)(injectionToken);
20
- exports.useBacktestOptions = useBacktestOptions;
@@ -1,15 +0,0 @@
1
- import { BacktestStorage } from './use-backtest';
2
- export declare function useBacktestQueryBuffer<T>(storage: BacktestStorage<T>): {
3
- size(): number;
4
- peek(): {
5
- timestamp: number;
6
- payload: T;
7
- };
8
- dequeue(): {
9
- timestamp: number;
10
- payload: T;
11
- };
12
- completed(): boolean;
13
- fetchNextPage(): Promise<void>;
14
- };
15
- //# sourceMappingURL=use-backtest-query-buffer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-backtest-query-buffer.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-query-buffer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC;;;mBAGtC,MAAM;iBAAW,CAAC;;;mBAAlB,MAAM;iBAAW,CAAC;;;;EAwChD"}
@@ -1,30 +0,0 @@
1
- import { BacktestStorage } from './use-backtest';
2
- export declare const useBacktestQueryCursor: () => {
3
- get<T>(query: BacktestStorage<T>): {
4
- size(): number;
5
- peek(): {
6
- timestamp: number;
7
- payload: T;
8
- };
9
- dequeue(): {
10
- timestamp: number;
11
- payload: T;
12
- };
13
- completed(): boolean;
14
- fetchNextPage(): Promise<void>;
15
- };
16
- cursor(): Promise<{
17
- size(): number;
18
- peek(): {
19
- timestamp: number;
20
- payload: any;
21
- };
22
- dequeue(): {
23
- timestamp: number;
24
- payload: any;
25
- };
26
- completed(): boolean;
27
- fetchNextPage(): Promise<void>;
28
- } | undefined>;
29
- };
30
- //# sourceMappingURL=use-backtest-query-cursor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-backtest-query-cursor.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-query-cursor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjD,eAAO,MAAM,sBAAsB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCjC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-backtest-scheduler.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,UAAU,EAAW,MAAM,MAAM,CAAC;AAI/D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKjD,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;mBASiC,MAAM;iBAAW,GAAG;;;;;;mBA+DrB,MAAM;;;CAgBrE,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-backtest-storage.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-storage.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EAGhB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;IACpC,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,kBAAkB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,EAC7E,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC,EACX,EAAE,IAAI,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAChC,eAAe,CAAC,CAAC,CAAC,CAgDpB"}
@@ -1,65 +0,0 @@
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.useBacktestStorage = void 0;
13
- const hash_code_1 = require("../hash-code");
14
- const storage_1 = require("../storage");
15
- const storageIndexObject = storage_1.Storage.createObject('index://range', {
16
- timestamp: 'number',
17
- uri: 'string',
18
- min: 'number',
19
- max: 'number'
20
- });
21
- function useBacktestStorage(uri, { sync }) {
22
- const storage = (0, storage_1.useStorage)(['backtest']);
23
- const storageObjectKey = uri.query;
24
- const storageObject = storage_1.Storage.createObject(storageObjectKey, {
25
- timestamp: 'number',
26
- payload: 'string'
27
- });
28
- const id = (0, hash_code_1.hashCode)(storageObjectKey);
29
- return {
30
- query(query) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- const [index] = yield storage.query(storageIndexObject, {
33
- limit: 1,
34
- where: { timestamp: (0, storage_1.eq)(id) }
35
- });
36
- const { min, max } = query.where.timestamp;
37
- if (!index || min < index.min || max > index.max) {
38
- yield sync(query, {
39
- save(objects) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- yield storage.save(storageObject, objects.map(it => ({
42
- timestamp: it.timestamp,
43
- payload: JSON.stringify(it.payload)
44
- })));
45
- });
46
- }
47
- });
48
- yield storage.save(storageIndexObject, [
49
- {
50
- timestamp: id,
51
- max,
52
- min,
53
- uri: storageObjectKey
54
- }
55
- ]);
56
- }
57
- return (yield storage.query(storageObject, query)).map(it => ({
58
- timestamp: it.timestamp,
59
- payload: JSON.parse(it.payload)
60
- }));
61
- });
62
- }
63
- };
64
- }
65
- exports.useBacktestStorage = useBacktestStorage;
@@ -1,3 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- export declare function useBacktestSync<T>(input: Observable<T>): Observable<T>;
3
- //# sourceMappingURL=use-backtest-sync.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-backtest-sync.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,UAAU,EAAE,MAAM,MAAM,CAAC;AAM5C,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAYtE"}
@@ -1,24 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { Query, QueryObject } from '../storage';
3
- export interface BacktestStorage<V> {
4
- query(query: Query<QueryObject> & {
5
- where: {
6
- timestamp: {
7
- type: 'between';
8
- min: number;
9
- max: number;
10
- };
11
- };
12
- }): Promise<{
13
- timestamp: number;
14
- payload: V;
15
- }[]>;
16
- }
17
- export declare function useBacktest<T>(input: Observable<{
18
- timestamp: number;
19
- payload: T;
20
- }>, query: BacktestStorage<T>): Observable<{
21
- timestamp: number;
22
- payload: T;
23
- }>;
24
- //# sourceMappingURL=use-backtest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-backtest.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlD,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,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,wBAAgB,WAAW,CAAC,CAAC,EAC3B,KAAK,EAAE,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,EACpD,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC;eADM,MAAM;aAAW,CAAC;GAWlD"}
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useBacktest = void 0;
4
- const use_execution_mode_1 = require("../use-execution-mode");
5
- const use_backtest_scheduler_1 = require("./use-backtest-scheduler");
6
- function useBacktest(input, query) {
7
- const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
8
- if (isReplay) {
9
- const { watch } = (0, use_backtest_scheduler_1.useBacktestScheduler)();
10
- return watch(query);
11
- }
12
- return input;
13
- }
14
- exports.useBacktest = useBacktest;
@@ -1,2 +0,0 @@
1
- export declare function whenBacktestFinished(): import("rxjs").Observable<boolean>;
2
- //# sourceMappingURL=when-backtest-finished.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"when-backtest-finished.d.ts","sourceRoot":"","sources":["../../src/backtest/when-backtest-finished.ts"],"names":[],"mappings":"AAMA,wBAAgB,oBAAoB,uCAanC"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.whenBacktestFinished = void 0;
4
- const rxjs_1 = require("rxjs");
5
- const use_execution_mode_1 = require("../use-execution-mode");
6
- const use_backtest_scheduler_1 = require("./use-backtest-scheduler");
7
- function whenBacktestFinished() {
8
- const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
9
- if (!isReplay) {
10
- return new rxjs_1.Subject().asObservable();
11
- }
12
- const { stream } = (0, use_backtest_scheduler_1.useBacktestScheduler)();
13
- return (0, rxjs_1.from)(stream).pipe((0, rxjs_1.last)(), (0, rxjs_1.map)(() => true));
14
- }
15
- exports.whenBacktestFinished = whenBacktestFinished;
@@ -1,10 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from '../use-hash';
3
- export declare function replayGuard<T extends Array<dependency>, K>(fn: (...args: T) => Observable<{
4
- timestamp: number;
5
- payload: K;
6
- }>): (...args: T) => Observable<{
7
- timestamp: number;
8
- payload: K;
9
- }>;
10
- //# sourceMappingURL=replay-guard.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replay-guard.d.ts","sourceRoot":"","sources":["../../src/replay/replay-guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,wBAAgB,WAAW,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACxD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,GAChE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAE/D"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replayGuard = void 0;
4
- const use_replay_lock_1 = require("./use-replay-lock");
5
- function replayGuard(fn) {
6
- return (...args) => (0, use_replay_lock_1.useReplayLock)(fn(...args));
7
- }
8
- exports.replayGuard = replayGuard;
@@ -1,10 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { dependency } from '../use-hash';
3
- export declare function replay<T extends Array<dependency>, K>(fn: (...args: T) => Observable<{
4
- timestamp: number;
5
- payload: K;
6
- }>, dependencies: dependency[]): (...args: T) => Observable<{
7
- timestamp: number;
8
- payload: K;
9
- }>;
10
- //# sourceMappingURL=replay.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../../src/replay/replay.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,wBAAgB,MAAM,CAAC,CAAC,SAAS,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,EACnD,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,EACjE,YAAY,EAAE,UAAU,EAAE,GACzB,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,CAAC,CAAA;CAAE,CAAC,CAE/D"}
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.replay = void 0;
4
- const with_memo_1 = require("../with-memo");
5
- const use_replay_1 = require("./use-replay");
6
- function replay(fn, dependencies) {
7
- return (0, with_memo_1.withMemo)((...args) => (0, use_replay_1.useReplay)(fn(...args), [...dependencies, ...args]));
8
- }
9
- exports.replay = replay;
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-replay-storage-buffer.d.ts","sourceRoot":"","sources":["../../../src/replay/storage/use-replay-storage-buffer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,eAAO,MAAM,sBAAsB;;;mBAMC,MAAM;;;;mBAAN,MAAM;;;;;CAsCxC,CAAC"}
@@ -1,57 +0,0 @@
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.useReplayStorageBuffer = void 0;
13
- const use_replay_options_1 = require("../../replay/use-replay-options");
14
- const storage_1 = require("../../storage");
15
- const with_memo_1 = require("../../with-memo");
16
- const use_replay_storage_1 = require("./use-replay-storage");
17
- exports.useReplayStorageBuffer = (0, with_memo_1.withMemo)((dependencies) => {
18
- const { query } = (0, use_replay_storage_1.useReplayStorage)(dependencies);
19
- const { from, to } = (0, use_replay_options_1.useReplayOptions)();
20
- console.log(from, to);
21
- let page = new Array();
22
- let index = 0;
23
- let completed = false;
24
- let count = 0;
25
- return {
26
- size() {
27
- return page.length - index;
28
- },
29
- peek() {
30
- return page[index];
31
- },
32
- dequeue() {
33
- return page[index++];
34
- },
35
- completed() {
36
- return completed;
37
- },
38
- fetchNextPage() {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- if (completed) {
41
- return;
42
- }
43
- index = 0;
44
- page = yield query({
45
- where: {
46
- timestamp: (0, storage_1.between)(from, to)
47
- },
48
- limit: 10000,
49
- offset: count,
50
- orderBy: 'ASC'
51
- });
52
- count += page.length;
53
- completed = page.length == 0;
54
- });
55
- }
56
- };
57
- });
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-replay-storage-cursor.d.ts","sourceRoot":"","sources":["../../../src/replay/storage/use-replay-storage-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAMpD,eAAO,MAAM,sBAAsB;yBAKV,UAAU,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCnC,CAAC"}