@quantform/core 0.7.20 → 0.7.22
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.
- package/lib/cli/replay.d.ts +1 -0
- package/lib/cli/replay.d.ts.map +1 -1
- package/lib/cli/replay.js +4 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/replay/index.d.ts +3 -6
- package/lib/replay/index.d.ts.map +1 -1
- package/lib/replay/index.js +3 -6
- package/lib/replay/use-replay-options.d.ts +6 -1
- package/lib/replay/use-replay-options.d.ts.map +1 -1
- package/lib/replay/use-replay-options.js +1 -1
- package/lib/replay/{use-replay-manager.d.ts → use-replay-scheduler.d.ts} +4 -4
- package/lib/replay/use-replay-scheduler.d.ts.map +1 -0
- package/lib/{backtest/use-backtest-scheduler.js → replay/use-replay-scheduler.js} +6 -6
- package/lib/replay/{storage/use-replay-storage-buffer.d.ts → use-replay-storage-buffer.d.ts} +2 -2
- package/lib/replay/use-replay-storage-buffer.d.ts.map +1 -0
- package/lib/{backtest/use-backtest-storage-buffer.js → replay/use-replay-storage-buffer.js} +6 -6
- package/lib/{backtest/use-backtest-storage-cursor.d.ts → replay/use-replay-storage-cursor.d.ts} +4 -4
- package/lib/replay/use-replay-storage-cursor.d.ts.map +1 -0
- package/lib/{backtest/use-backtest-storage-cursor.js → replay/use-replay-storage-cursor.js} +4 -4
- package/lib/{backtest/use-backtest-storage.d.ts → replay/use-replay-storage.d.ts} +3 -3
- package/lib/replay/use-replay-storage.d.ts.map +1 -0
- package/lib/{backtest/use-backtest-storage.js → replay/use-replay-storage.js} +16 -9
- package/lib/replay/use-replay-sync.d.ts +3 -0
- package/lib/replay/use-replay-sync.d.ts.map +1 -0
- package/lib/{backtest/use-backtest-sync.js → replay/use-replay-sync.js} +5 -5
- package/lib/replay/use-replay.d.ts +1 -9
- package/lib/replay/use-replay.d.ts.map +1 -1
- package/lib/replay/use-replay.js +3 -14
- package/lib/replay/when-replay-finished.js +2 -2
- package/lib/use-timestamp.js +2 -2
- package/package.json +1 -1
- package/src/cli/replay.ts +3 -2
- package/src/index.ts +1 -1
- package/src/replay/index.ts +3 -6
- package/src/replay/use-replay-options.ts +10 -2
- package/src/{backtest/use-backtest-scheduler.ts → replay/use-replay-scheduler.ts} +8 -11
- package/src/{backtest/use-backtest-storage-buffer.ts → replay/use-replay-storage-buffer.ts} +5 -5
- package/src/{backtest/use-backtest-storage-cursor.ts → replay/use-replay-storage-cursor.ts} +7 -7
- package/src/replay/use-replay-storage.ts +101 -0
- package/src/{backtest/use-backtest-sync.ts → replay/use-replay-sync.ts} +3 -3
- package/src/replay/use-replay.ts +3 -24
- package/src/replay/when-replay-finished.ts +2 -2
- package/src/use-timestamp.ts +2 -2
- package/lib/backtest/index.d.ts +0 -7
- package/lib/backtest/index.d.ts.map +0 -1
- package/lib/backtest/index.js +0 -22
- package/lib/backtest/use-backtest-options.d.ts +0 -15
- package/lib/backtest/use-backtest-options.d.ts.map +0 -1
- package/lib/backtest/use-backtest-options.js +0 -20
- package/lib/backtest/use-backtest-scheduler.d.ts +0 -28
- package/lib/backtest/use-backtest-scheduler.d.ts.map +0 -1
- package/lib/backtest/use-backtest-storage-buffer.d.ts +0 -15
- package/lib/backtest/use-backtest-storage-buffer.d.ts.map +0 -1
- package/lib/backtest/use-backtest-storage-cursor.d.ts.map +0 -1
- package/lib/backtest/use-backtest-storage.d.ts.map +0 -1
- package/lib/backtest/use-backtest-sync.d.ts +0 -3
- package/lib/backtest/use-backtest-sync.d.ts.map +0 -1
- package/lib/backtest/use-backtest.d.ts +0 -2
- package/lib/backtest/use-backtest.d.ts.map +0 -1
- package/lib/backtest/use-backtest.js +0 -9
- package/lib/backtest/when-backtest-finished.d.ts +0 -2
- package/lib/backtest/when-backtest-finished.d.ts.map +0 -1
- package/lib/backtest/when-backtest-finished.js +0 -15
- package/lib/replay/replay-guard.d.ts +0 -10
- package/lib/replay/replay-guard.d.ts.map +0 -1
- package/lib/replay/replay-guard.js +0 -8
- package/lib/replay/replay.d.ts +0 -10
- package/lib/replay/replay.d.ts.map +0 -1
- package/lib/replay/replay.js +0 -9
- package/lib/replay/storage/use-replay-storage-buffer.d.ts.map +0 -1
- package/lib/replay/storage/use-replay-storage-buffer.js +0 -57
- package/lib/replay/storage/use-replay-storage-cursor.d.ts +0 -30
- package/lib/replay/storage/use-replay-storage-cursor.d.ts.map +0 -1
- package/lib/replay/storage/use-replay-storage-cursor.js +0 -49
- package/lib/replay/storage/use-replay-storage.d.ts +0 -13
- package/lib/replay/storage/use-replay-storage.d.ts.map +0 -1
- package/lib/replay/storage/use-replay-storage.js +0 -39
- package/lib/replay/storage/use-replay-storage.spec.d.ts +0 -2
- package/lib/replay/storage/use-replay-storage.spec.d.ts.map +0 -1
- package/lib/replay/storage/use-replay-storage.spec.js +0 -74
- package/lib/replay/use-replay-lock.d.ts +0 -3
- package/lib/replay/use-replay-lock.d.ts.map +0 -1
- package/lib/replay/use-replay-lock.js +0 -22
- package/lib/replay/use-replay-manager.d.ts.map +0 -1
- package/lib/replay/use-replay-manager.js +0 -68
- package/lib/replay/use-replay.spec.d.ts +0 -2
- package/lib/replay/use-replay.spec.d.ts.map +0 -1
- package/lib/replay/use-replay.spec.js +0 -130
- package/src/backtest/index.ts +0 -6
- package/src/backtest/use-backtest-options.ts +0 -23
- package/src/backtest/use-backtest-storage.ts +0 -87
- package/src/backtest/use-backtest.ts +0 -7
- package/src/backtest/when-backtest-finished.ts +0 -20
- package/src/replay/replay-guard.ts +0 -11
- package/src/replay/replay.ts +0 -13
- package/src/replay/storage/use-replay-storage-buffer.ts +0 -52
- package/src/replay/storage/use-replay-storage-cursor.ts +0 -44
- package/src/replay/storage/use-replay-storage.spec.ts +0 -84
- package/src/replay/storage/use-replay-storage.ts +0 -29
- package/src/replay/use-replay-lock.ts +0 -29
- package/src/replay/use-replay-manager.ts +0 -83
- package/src/replay/use-replay.spec.ts +0 -138
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Query, QueryObject } from '@lib/storage';
|
|
2
2
|
import { withMemo } from '@lib/with-memo';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { useReplayStorageBuffer } from './use-replay-storage-buffer';
|
|
5
5
|
|
|
6
|
-
export interface
|
|
6
|
+
export interface ReplayQuery<V> {
|
|
7
7
|
query(
|
|
8
8
|
query: Query<QueryObject> & {
|
|
9
9
|
where: { timestamp: { type: 'between'; min: number; max: number } };
|
|
@@ -11,12 +11,12 @@ export interface BacktestQuery<V> {
|
|
|
11
11
|
): Promise<{ timestamp: number; payload: V }[]>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export const
|
|
15
|
-
const cursors = Array.of<ReturnType<typeof
|
|
14
|
+
export const useReplayStorageCursor = withMemo(() => {
|
|
15
|
+
const cursors = Array.of<ReturnType<typeof useReplayStorageBuffer<any>>>();
|
|
16
16
|
|
|
17
17
|
return {
|
|
18
|
-
get<T>(query:
|
|
19
|
-
const buffer =
|
|
18
|
+
get<T>(query: ReplayQuery<T>) {
|
|
19
|
+
const buffer = useReplayStorageBuffer<T>(query);
|
|
20
20
|
|
|
21
21
|
cursors.push(buffer);
|
|
22
22
|
|
|
@@ -24,7 +24,7 @@ export const useBacktestStorageCursor = withMemo(() => {
|
|
|
24
24
|
},
|
|
25
25
|
|
|
26
26
|
async cursor() {
|
|
27
|
-
let current: ReturnType<typeof
|
|
27
|
+
let current: ReturnType<typeof useReplayStorageBuffer<any>> | undefined;
|
|
28
28
|
|
|
29
29
|
for (const cursor of cursors) {
|
|
30
30
|
if (cursor.completed()) {
|
|
@@ -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 {
|
|
5
|
+
import { useReplayScheduler } from './use-replay-scheduler';
|
|
6
6
|
|
|
7
|
-
export function
|
|
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 } =
|
|
14
|
+
const { stop, tryContinue } = useReplayScheduler();
|
|
15
15
|
|
|
16
16
|
stop();
|
|
17
17
|
|
package/src/replay/use-replay.ts
CHANGED
|
@@ -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
|
-
|
|
25
|
-
}
|
|
3
|
+
export function useReplay<T>(backtest: T, real: T) {
|
|
4
|
+
const { isReplay } = useExecutionMode();
|
|
26
5
|
|
|
27
|
-
return
|
|
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 {
|
|
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 } =
|
|
14
|
+
const { stream } = useReplayScheduler();
|
|
15
15
|
|
|
16
16
|
return from(stream).pipe(
|
|
17
17
|
last(),
|
package/src/use-timestamp.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { useExecutionMode } from '@lib/use-execution-mode';
|
|
2
2
|
|
|
3
|
-
import {
|
|
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
|
|
9
|
+
return useReplayScheduler().timestamp();
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
return Date.now();
|
package/lib/backtest/index.d.ts
DELETED
|
@@ -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"}
|
package/lib/backtest/index.js
DELETED
|
@@ -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,28 +0,0 @@
|
|
|
1
|
-
import { Observable } from 'rxjs';
|
|
2
|
-
import { BacktestQuery } from './use-backtest-storage-cursor';
|
|
3
|
-
export declare const useBacktestScheduler: () => {
|
|
4
|
-
stream: Observable<[{
|
|
5
|
-
size(): number;
|
|
6
|
-
peek(): {
|
|
7
|
-
timestamp: number;
|
|
8
|
-
payload: any;
|
|
9
|
-
};
|
|
10
|
-
dequeue(): {
|
|
11
|
-
timestamp: number;
|
|
12
|
-
payload: any;
|
|
13
|
-
};
|
|
14
|
-
completed(): boolean;
|
|
15
|
-
fetchNextPage(): Promise<void>;
|
|
16
|
-
}, {
|
|
17
|
-
timestamp: number;
|
|
18
|
-
payload: any;
|
|
19
|
-
}]>;
|
|
20
|
-
timestamp(): number;
|
|
21
|
-
stop(): void;
|
|
22
|
-
tryContinue: () => void;
|
|
23
|
-
watch<T>(query: BacktestQuery<T>): Observable<{
|
|
24
|
-
timestamp: number;
|
|
25
|
-
payload: T;
|
|
26
|
-
}>;
|
|
27
|
-
};
|
|
28
|
-
//# sourceMappingURL=use-backtest-scheduler.d.ts.map
|
|
@@ -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;AAM/D,OAAO,EAAE,aAAa,EAA4B,MAAM,+BAA+B,CAAC;AAExF,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;mBAWd,MAAM;iBAAW,GAAG;;;;;;mBAgEwB,MAAM;;;CAgBnE,CAAC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BacktestQuery } from './use-backtest-storage-cursor';
|
|
2
|
-
export declare function useBacktestStorageBuffer<T>(storage: BacktestQuery<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-storage-buffer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-backtest-storage-buffer.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-storage-buffer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC;;;mBAGtC,MAAM;iBAAW,CAAC;;;mBAAlB,MAAM;iBAAW,CAAC;;;;EAwChD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-backtest-storage-cursor.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-storage-cursor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAKlD,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,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,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCnC,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;AAI/B,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;;;;;EAsDlC"}
|
|
@@ -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-backtest.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,KAIlD"}
|
|
@@ -1,9 +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
|
-
function useBacktest(backtest, real) {
|
|
6
|
-
const { isReplay } = (0, use_execution_mode_1.useExecutionMode)();
|
|
7
|
-
return isReplay ? backtest : real;
|
|
8
|
-
}
|
|
9
|
-
exports.useBacktest = useBacktest;
|
|
@@ -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;
|
package/lib/replay/replay.d.ts
DELETED
|
@@ -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"}
|
package/lib/replay/replay.js
DELETED
|
@@ -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,30 +0,0 @@
|
|
|
1
|
-
import { dependency } from '../../use-hash';
|
|
2
|
-
export declare const useReplayStorageCursor: () => {
|
|
3
|
-
get<T>(dependencies: dependency[]): {
|
|
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-replay-storage-cursor.d.ts.map
|
|
@@ -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"}
|
|
@@ -1,49 +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.useReplayStorageCursor = void 0;
|
|
13
|
-
const use_hash_1 = require("../../use-hash");
|
|
14
|
-
const use_logger_1 = require("../../use-logger");
|
|
15
|
-
const with_memo_1 = require("../../with-memo");
|
|
16
|
-
const use_replay_storage_buffer_1 = require("./use-replay-storage-buffer");
|
|
17
|
-
exports.useReplayStorageCursor = (0, with_memo_1.withMemo)(() => {
|
|
18
|
-
const { info } = (0, use_logger_1.useLogger)('useReplayStorageCursor');
|
|
19
|
-
const storages = Array.of();
|
|
20
|
-
return {
|
|
21
|
-
get(dependencies) {
|
|
22
|
-
const storage = (0, use_replay_storage_buffer_1.useReplayStorageBuffer)(dependencies);
|
|
23
|
-
if (!storages.includes(storage)) {
|
|
24
|
-
info('opening a new replay buffer', (0, use_hash_1.useHash)(dependencies));
|
|
25
|
-
storages.push(storage);
|
|
26
|
-
}
|
|
27
|
-
return storage;
|
|
28
|
-
},
|
|
29
|
-
cursor() {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
let current;
|
|
32
|
-
for (const storage of storages) {
|
|
33
|
-
if (storage.completed()) {
|
|
34
|
-
continue;
|
|
35
|
-
}
|
|
36
|
-
if (storage.size() == 0) {
|
|
37
|
-
yield storage.fetchNextPage();
|
|
38
|
-
}
|
|
39
|
-
if (storage.peek()) {
|
|
40
|
-
if (!current || current.peek().timestamp > storage.peek().timestamp) {
|
|
41
|
-
current = storage;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return current;
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Query, QueryObject } from '../../storage';
|
|
2
|
-
import { dependency } from '../../use-hash';
|
|
3
|
-
export declare function useReplayStorage<T>(dependencies: dependency[]): {
|
|
4
|
-
query(query: Query<QueryObject>): Promise<{
|
|
5
|
-
timestamp: number;
|
|
6
|
-
payload: T;
|
|
7
|
-
}[]>;
|
|
8
|
-
save(objects: {
|
|
9
|
-
timestamp: number;
|
|
10
|
-
payload: T;
|
|
11
|
-
}[]): Promise<void>;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=use-replay-storage.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-replay-storage.d.ts","sourceRoot":"","sources":["../../../src/replay/storage/use-replay-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAuB,MAAM,cAAc,CAAC;AACvE,OAAO,EAAE,UAAU,EAAW,MAAM,eAAe,CAAC;AAEpD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE;iBASvC,MAAM,WAAW,CAAC;;;;kBAMvB;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,CAAC,CAAA;KAAE,EAAE;EAUpD"}
|