@tradejs/infra 1.0.0
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/README.md +51 -0
- package/dist/chunk-LNFUOXDW.mjs +42 -0
- package/dist/files.d.mts +9 -0
- package/dist/files.d.ts +9 -0
- package/dist/files.js +103 -0
- package/dist/files.mjs +66 -0
- package/dist/http.d.mts +8 -0
- package/dist/http.d.ts +8 -0
- package/dist/http.js +79 -0
- package/dist/http.mjs +54 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.ts +5 -0
- package/dist/logger.js +66 -0
- package/dist/logger.mjs +6 -0
- package/dist/ml.d.mts +135 -0
- package/dist/ml.d.ts +135 -0
- package/dist/ml.js +1604 -0
- package/dist/ml.mjs +1512 -0
- package/dist/redis.d.mts +50 -0
- package/dist/redis.d.ts +50 -0
- package/dist/redis.js +337 -0
- package/dist/redis.mjs +296 -0
- package/dist/timescale.d.mts +68 -0
- package/dist/timescale.d.ts +68 -0
- package/dist/timescale.js +508 -0
- package/dist/timescale.mjs +471 -0
- package/package.json +60 -0
- package/proto/ml_infer.proto +19 -0
package/dist/ml.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
declare const toFileToken: (value: string) => string;
|
|
2
|
+
declare const getMlChunkFilePath: (strategyName: string, chunkId: string, outDir?: string) => string;
|
|
3
|
+
declare const appendMlDatasetRow: (params: {
|
|
4
|
+
strategyName: string;
|
|
5
|
+
chunkId: string;
|
|
6
|
+
row: Record<string, number | string | null>;
|
|
7
|
+
outDir?: string;
|
|
8
|
+
}) => Promise<string>;
|
|
9
|
+
declare const flushMlDatasetWriter: (filePath: string) => Promise<void>;
|
|
10
|
+
declare const closeMlDatasetWriter: (filePath: string) => Promise<void>;
|
|
11
|
+
declare const closeAllMlDatasetWriters: () => Promise<void>;
|
|
12
|
+
declare const listMlChunkFiles: (params: {
|
|
13
|
+
strategyName: string;
|
|
14
|
+
outDir?: string;
|
|
15
|
+
}) => Promise<string[]>;
|
|
16
|
+
declare const mergeJsonlFiles: (params: {
|
|
17
|
+
filePaths: string[];
|
|
18
|
+
outPath: string;
|
|
19
|
+
}) => Promise<void>;
|
|
20
|
+
|
|
21
|
+
type MlPredictResponse = {
|
|
22
|
+
probability: number;
|
|
23
|
+
threshold: number;
|
|
24
|
+
passed: boolean;
|
|
25
|
+
};
|
|
26
|
+
type MlPredictParams = {
|
|
27
|
+
strategy: string;
|
|
28
|
+
features: Record<string, number>;
|
|
29
|
+
threshold: number;
|
|
30
|
+
grpcAddress?: string;
|
|
31
|
+
};
|
|
32
|
+
declare const buildMlFeatures: (row: Record<string, unknown>) => Record<string, number>;
|
|
33
|
+
declare const fetchMlThreshold: ({ strategy, features, threshold, grpcAddress, }: MlPredictParams) => Promise<MlPredictResponse | null>;
|
|
34
|
+
|
|
35
|
+
type MlSignalRecord = {
|
|
36
|
+
signal: MlSignalPayload;
|
|
37
|
+
context?: {
|
|
38
|
+
strategyConfig?: Record<string, unknown>;
|
|
39
|
+
strategyName?: string;
|
|
40
|
+
symbol?: string;
|
|
41
|
+
entryTimestamp?: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
type MlSignalPayload = {
|
|
45
|
+
signalId?: string;
|
|
46
|
+
strategy?: string;
|
|
47
|
+
symbol?: string;
|
|
48
|
+
direction?: string;
|
|
49
|
+
timestamp?: number;
|
|
50
|
+
interval?: number | string;
|
|
51
|
+
prices?: {
|
|
52
|
+
currentPrice?: number;
|
|
53
|
+
takeProfitPrice?: number;
|
|
54
|
+
stopLossPrice?: number;
|
|
55
|
+
riskRatio?: number;
|
|
56
|
+
};
|
|
57
|
+
indicators?: Record<string, unknown>;
|
|
58
|
+
additionalIndicators?: Record<string, unknown>;
|
|
59
|
+
figures?: {
|
|
60
|
+
trendLine?: {
|
|
61
|
+
mode?: 'highs' | 'lows' | string;
|
|
62
|
+
distance?: number;
|
|
63
|
+
alpha?: unknown[];
|
|
64
|
+
points?: Array<{
|
|
65
|
+
value?: number;
|
|
66
|
+
timestamp?: number;
|
|
67
|
+
}>;
|
|
68
|
+
touches?: Array<{
|
|
69
|
+
value?: number;
|
|
70
|
+
timestamp?: number;
|
|
71
|
+
}>;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
type MlResultRecord = {
|
|
76
|
+
profit?: number;
|
|
77
|
+
direction?: 'LONG' | 'SHORT';
|
|
78
|
+
symbol?: string;
|
|
79
|
+
};
|
|
80
|
+
declare const buildMlTrainingRow: (signalRecord: MlSignalRecord, resultRecord: MlResultRecord | null) => Record<string, number | string | null>;
|
|
81
|
+
declare const trimMlTrainingRowWindows: (row: Record<string, number | string | null>, keep?: 5) => Record<string, number | string | null>;
|
|
82
|
+
|
|
83
|
+
declare const toIsoUtcOrNull: (value: number | null | undefined) => string | null;
|
|
84
|
+
declare const isDerivedDatasetFileName: (name: string) => boolean;
|
|
85
|
+
declare const computeWindowBoundaries: ({ maxLabeledTs, maxTrainTs, testDays, trainRecentDays, walkForwardFolds, }: {
|
|
86
|
+
maxLabeledTs: number;
|
|
87
|
+
maxTrainTs: number;
|
|
88
|
+
testDays: number;
|
|
89
|
+
trainRecentDays: number;
|
|
90
|
+
walkForwardFolds: number;
|
|
91
|
+
}) => {
|
|
92
|
+
holdoutCutoffMs: number;
|
|
93
|
+
holdoutTrainStartMs: number;
|
|
94
|
+
wfStartMs: number;
|
|
95
|
+
prodStartMs: number;
|
|
96
|
+
folds: {
|
|
97
|
+
fold: number;
|
|
98
|
+
startTs: number;
|
|
99
|
+
endTs: number;
|
|
100
|
+
}[];
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
type LookaheadViolation = {
|
|
104
|
+
key: string;
|
|
105
|
+
entryTimestampMs: number;
|
|
106
|
+
featureTimestampMs: number;
|
|
107
|
+
};
|
|
108
|
+
declare const isTimestampFeatureKey: (key: string) => boolean;
|
|
109
|
+
declare const findLookaheadViolations: (row: Record<string, unknown>) => LookaheadViolation[];
|
|
110
|
+
|
|
111
|
+
type MlSeriesAnalysisCandle = {
|
|
112
|
+
open: number;
|
|
113
|
+
high: number;
|
|
114
|
+
low: number;
|
|
115
|
+
close: number;
|
|
116
|
+
volume: number;
|
|
117
|
+
timestamp: number;
|
|
118
|
+
};
|
|
119
|
+
type MlSeriesAnalysisInput = {
|
|
120
|
+
candles: MlSeriesAnalysisCandle[];
|
|
121
|
+
benchmarkCandles?: MlSeriesAnalysisCandle[];
|
|
122
|
+
indicators?: {
|
|
123
|
+
atrPct?: number[];
|
|
124
|
+
price1hPcnt?: number[];
|
|
125
|
+
price24hPcnt?: number[];
|
|
126
|
+
macdHistogram?: number[];
|
|
127
|
+
maFast?: number[];
|
|
128
|
+
maSlow?: number[];
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
type MlSeriesAnalysisSummary = Record<string, number>;
|
|
132
|
+
declare const analyzeMlSeriesWindow: (input: MlSeriesAnalysisInput) => MlSeriesAnalysisSummary;
|
|
133
|
+
declare const buildMlSeriesAlignment: (left: MlSeriesAnalysisSummary | undefined, right: MlSeriesAnalysisSummary | undefined) => MlSeriesAnalysisSummary;
|
|
134
|
+
|
|
135
|
+
export { type LookaheadViolation, type MlPredictParams, type MlPredictResponse, type MlResultRecord, type MlSeriesAnalysisCandle, type MlSeriesAnalysisSummary, type MlSignalRecord, analyzeMlSeriesWindow, appendMlDatasetRow, buildMlFeatures, buildMlSeriesAlignment, buildMlTrainingRow, closeAllMlDatasetWriters, closeMlDatasetWriter, computeWindowBoundaries, fetchMlThreshold, findLookaheadViolations, flushMlDatasetWriter, getMlChunkFilePath, isDerivedDatasetFileName, isTimestampFeatureKey, listMlChunkFiles, mergeJsonlFiles, toFileToken, toIsoUtcOrNull, trimMlTrainingRowWindows };
|