@quantform/core 0.7.18 → 0.7.19
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/backtest/use-backtest-query-buffer.d.ts +1 -1
- package/lib/backtest/use-backtest-query-buffer.d.ts.map +1 -1
- package/lib/backtest/use-backtest-query-buffer.js +5 -5
- package/lib/backtest/use-backtest-storage.d.ts.map +1 -1
- package/lib/backtest/use-backtest-storage.js +4 -2
- package/lib/hash-code.d.ts +2 -0
- package/lib/hash-code.d.ts.map +1 -0
- package/lib/hash-code.js +12 -0
- package/package.json +1 -1
- package/src/backtest/use-backtest-query-buffer.ts +4 -5
- package/src/backtest/use-backtest-storage.ts +5 -2
- package/src/hash-code.ts +8 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-backtest-query-buffer.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-query-buffer.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -10,11 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.useBacktestQueryBuffer = void 0;
|
|
13
|
-
const replay_1 = require("../replay");
|
|
14
13
|
const storage_1 = require("../storage");
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const { from, to } = (0,
|
|
14
|
+
const use_backtest_options_1 = require("./use-backtest-options");
|
|
15
|
+
function useBacktestQueryBuffer(storage) {
|
|
16
|
+
const { from, to } = (0, use_backtest_options_1.useBacktestOptions)();
|
|
18
17
|
let page = [];
|
|
19
18
|
let index = 0;
|
|
20
19
|
let completed = false;
|
|
@@ -49,4 +48,5 @@ exports.useBacktestQueryBuffer = (0, with_memo_1.withMemo)((storage) => {
|
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
50
|
};
|
|
52
|
-
}
|
|
51
|
+
}
|
|
52
|
+
exports.useBacktestQueryBuffer = useBacktestQueryBuffer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-backtest-storage.d.ts","sourceRoot":"","sources":["../../src/backtest/use-backtest-storage.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.useBacktestStorage = void 0;
|
|
13
|
+
const hash_code_1 = require("../hash-code");
|
|
13
14
|
const storage_1 = require("../storage");
|
|
14
15
|
const storageIndexObject = storage_1.Storage.createObject('index://range', {
|
|
15
16
|
timestamp: 'number',
|
|
@@ -24,12 +25,13 @@ function useBacktestStorage(uri, { sync }) {
|
|
|
24
25
|
timestamp: 'number',
|
|
25
26
|
payload: 'string'
|
|
26
27
|
});
|
|
28
|
+
const id = (0, hash_code_1.hashCode)(storageObjectKey);
|
|
27
29
|
return {
|
|
28
30
|
query(query) {
|
|
29
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
30
32
|
const [index] = yield storage.query(storageIndexObject, {
|
|
31
33
|
limit: 1,
|
|
32
|
-
where: {
|
|
34
|
+
where: { timestamp: (0, storage_1.eq)(id) }
|
|
33
35
|
});
|
|
34
36
|
const { min, max } = query.where.timestamp;
|
|
35
37
|
if (!index || min < index.min || max > index.max) {
|
|
@@ -45,7 +47,7 @@ function useBacktestStorage(uri, { sync }) {
|
|
|
45
47
|
});
|
|
46
48
|
yield storage.save(storageIndexObject, [
|
|
47
49
|
{
|
|
48
|
-
timestamp:
|
|
50
|
+
timestamp: id,
|
|
49
51
|
max,
|
|
50
52
|
min,
|
|
51
53
|
uri: storageObjectKey
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-code.d.ts","sourceRoot":"","sources":["../src/hash-code.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,UAOnC"}
|
package/lib/hash-code.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashCode = void 0;
|
|
4
|
+
function hashCode(str) {
|
|
5
|
+
let hash = 0;
|
|
6
|
+
for (let i = 0; i < str.length; i++) {
|
|
7
|
+
hash = (hash << 5) - hash + str.charCodeAt(i);
|
|
8
|
+
hash |= 0;
|
|
9
|
+
}
|
|
10
|
+
return hash;
|
|
11
|
+
}
|
|
12
|
+
exports.hashCode = hashCode;
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { useReplayOptions } from '@lib/replay';
|
|
2
1
|
import { between } from '@lib/storage';
|
|
3
|
-
import { withMemo } from '@lib/with-memo';
|
|
4
2
|
|
|
5
3
|
import { BacktestStorage } from './use-backtest';
|
|
4
|
+
import { useBacktestOptions } from './use-backtest-options';
|
|
6
5
|
|
|
7
|
-
export
|
|
8
|
-
const { from, to } =
|
|
6
|
+
export function useBacktestQueryBuffer<T>(storage: BacktestStorage<T>) {
|
|
7
|
+
const { from, to } = useBacktestOptions();
|
|
9
8
|
|
|
10
9
|
let page: Array<{ timestamp: number; payload: T }> = [];
|
|
11
10
|
let index = 0;
|
|
@@ -47,4 +46,4 @@ export const useBacktestQueryBuffer = withMemo(<T>(storage: BacktestStorage<T>)
|
|
|
47
46
|
completed = page.length === 0;
|
|
48
47
|
}
|
|
49
48
|
};
|
|
50
|
-
}
|
|
49
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { hashCode } from '@lib/hash-code';
|
|
1
2
|
import {
|
|
2
3
|
eq,
|
|
3
4
|
InferQueryObject,
|
|
@@ -38,11 +39,13 @@ export function useBacktestStorage<V, P extends Record<string, string | number>>
|
|
|
38
39
|
payload: 'string'
|
|
39
40
|
});
|
|
40
41
|
|
|
42
|
+
const id = hashCode(storageObjectKey);
|
|
43
|
+
|
|
41
44
|
return {
|
|
42
45
|
async query(query) {
|
|
43
46
|
const [index] = await storage.query(storageIndexObject, {
|
|
44
47
|
limit: 1,
|
|
45
|
-
where: {
|
|
48
|
+
where: { timestamp: eq(id) }
|
|
46
49
|
});
|
|
47
50
|
|
|
48
51
|
const { min, max } = query.where.timestamp;
|
|
@@ -62,7 +65,7 @@ export function useBacktestStorage<V, P extends Record<string, string | number>>
|
|
|
62
65
|
|
|
63
66
|
await storage.save(storageIndexObject, [
|
|
64
67
|
{
|
|
65
|
-
timestamp:
|
|
68
|
+
timestamp: id,
|
|
66
69
|
max,
|
|
67
70
|
min,
|
|
68
71
|
uri: storageObjectKey
|