@tradejs/core 1.0.9 → 1.0.11
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 +1 -1
- package/dist/backtest.d.mts +109 -9
- package/dist/backtest.d.ts +109 -9
- package/dist/backtest.js +487 -145
- package/dist/backtest.mjs +414 -82
- package/dist/{chunk-FNLPYYML.mjs → chunk-BOETNABM.mjs} +22 -1
- package/dist/chunk-EQEIRB6P.mjs +11847 -0
- package/dist/{chunk-2ORZC66W.mjs → chunk-MKCQSB4H.mjs} +65 -6
- package/dist/chunk-OJPHC3S2.mjs +8 -0
- package/dist/constants.d.mts +26 -5
- package/dist/constants.d.ts +26 -5
- package/dist/constants.js +81 -9
- package/dist/constants.mjs +31 -5
- package/dist/data.mjs +3 -5
- package/dist/grid.d.mts +9 -0
- package/dist/grid.d.ts +9 -0
- package/dist/grid.js +168 -0
- package/dist/grid.mjs +98 -0
- package/dist/indicators-Da_i06-8.d.mts +288 -0
- package/dist/indicators-Da_i06-8.d.ts +288 -0
- package/dist/indicators.d.mts +4 -39
- package/dist/indicators.d.ts +4 -39
- package/dist/indicators.js +10488 -423
- package/dist/indicators.mjs +11 -3
- package/dist/strategies.d.mts +31 -12
- package/dist/strategies.d.ts +31 -12
- package/dist/strategies.js +11283 -336
- package/dist/strategies.mjs +1246 -119
- package/dist/{time-BMkFD4Kd.d.mts → time-BQ3AXmxo.d.mts} +3 -1
- package/dist/{time-BMkFD4Kd.d.ts → time-BQ3AXmxo.d.ts} +3 -1
- package/dist/time.d.mts +1 -1
- package/dist/time.d.ts +1 -1
- package/dist/time.js +38 -0
- package/dist/time.mjs +6 -2
- package/dist/trade.d.mts +54 -0
- package/dist/trade.d.ts +54 -0
- package/dist/trade.js +352 -0
- package/dist/trade.mjs +264 -0
- package/package.json +19 -5
- package/dist/chunk-UK6VTOUX.mjs +0 -1810
- package/dist/indicators-B-GGjP5F.d.mts +0 -65
- package/dist/indicators-B-GGjP5F.d.ts +0 -65
package/dist/indicators.mjs
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
+
COMPACT_INDICATORS_SNAPSHOT_KEY,
|
|
3
|
+
COMPACT_INDICATORS_SNAPSHOT_SYMBOL,
|
|
2
4
|
alignSortedCandlesByTimestamp,
|
|
3
5
|
alignSpreadRows,
|
|
4
6
|
applyIndicatorsToHistory,
|
|
@@ -11,12 +13,14 @@ import {
|
|
|
11
13
|
coinalyzePointsToRows,
|
|
12
14
|
coinbaseProductFromSymbol,
|
|
13
15
|
createIndicators,
|
|
16
|
+
createSerializableSpreadSmoother,
|
|
14
17
|
createSpreadSmoother,
|
|
15
18
|
createTrendlineEngine,
|
|
16
19
|
detectRawSupportResistance,
|
|
17
20
|
getPluginIndicatorCatalog,
|
|
18
21
|
getPluginIndicatorRenderers,
|
|
19
22
|
getRegisteredIndicatorEntries,
|
|
23
|
+
getRequiredControllerSeedWindow,
|
|
20
24
|
getSupportResistanceLevels,
|
|
21
25
|
intervalToMs,
|
|
22
26
|
mergeCoinalyzeMetrics,
|
|
@@ -29,12 +33,14 @@ import {
|
|
|
29
33
|
toArrayData,
|
|
30
34
|
toCoinalyzeTimestampMs,
|
|
31
35
|
toFiniteNumber
|
|
32
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-EQEIRB6P.mjs";
|
|
33
37
|
import "./chunk-AYC2QVKI.mjs";
|
|
34
|
-
import "./chunk-FNLPYYML.mjs";
|
|
35
|
-
import "./chunk-2ORZC66W.mjs";
|
|
36
38
|
import "./chunk-M7QGVZ3J.mjs";
|
|
39
|
+
import "./chunk-BOETNABM.mjs";
|
|
40
|
+
import "./chunk-MKCQSB4H.mjs";
|
|
37
41
|
export {
|
|
42
|
+
COMPACT_INDICATORS_SNAPSHOT_KEY,
|
|
43
|
+
COMPACT_INDICATORS_SNAPSHOT_SYMBOL,
|
|
38
44
|
alignSortedCandlesByTimestamp,
|
|
39
45
|
alignSpreadRows,
|
|
40
46
|
applyIndicatorsToHistory,
|
|
@@ -47,12 +53,14 @@ export {
|
|
|
47
53
|
coinalyzePointsToRows,
|
|
48
54
|
coinbaseProductFromSymbol,
|
|
49
55
|
createIndicators,
|
|
56
|
+
createSerializableSpreadSmoother,
|
|
50
57
|
createSpreadSmoother,
|
|
51
58
|
createTrendlineEngine,
|
|
52
59
|
detectRawSupportResistance,
|
|
53
60
|
getPluginIndicatorCatalog,
|
|
54
61
|
getPluginIndicatorRenderers,
|
|
55
62
|
getRegisteredIndicatorEntries,
|
|
63
|
+
getRequiredControllerSeedWindow,
|
|
56
64
|
getSupportResistanceLevels,
|
|
57
65
|
intervalToMs,
|
|
58
66
|
mergeCoinalyzeMetrics,
|
package/dist/strategies.d.mts
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, BacktestPriceMode,
|
|
2
|
-
import { I as IndicatorPeriods } from './indicators-
|
|
1
|
+
import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, KlineChartItem, BacktestPriceMode, BaseStrategyContextSnapshot, StrategySignalPriceParams, BuildStrategySignalDraft, StrategyEntrySignalContext, StrategyEntryOrderPlan, StrategyEntryRuntimeOptions, StrategyDecision, BuildStrategySignalParams, Signal, IndicatorsHistorySnapshot, StrategySharedReplayStateGetter, StrategyAPI, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions } from '@tradejs/types';
|
|
2
|
+
import { I as IndicatorPeriods, a as IndicatorsControllerRuntimeState, b as IndicatorsControllerCheckpointState } from './indicators-Da_i06-8.mjs';
|
|
3
3
|
|
|
4
4
|
type IndicatorPeriodsConfig = Partial<Record<'MA_FAST' | 'MA_MEDIUM' | 'MA_SLOW' | 'OBV_SMA' | 'ATR' | 'ATR_PCT_SHORT' | 'ATR_PCT_LONG' | 'BB' | 'BB_STD' | 'MACD_FAST' | 'MACD_SLOW' | 'MACD_SIGNAL' | 'LEVEL_LOOKBACK' | 'LEVEL_DELAY', number>>;
|
|
5
5
|
declare const buildDefaultIndicatorPeriods: (config: IndicatorPeriodsConfig) => Partial<IndicatorPeriods>;
|
|
6
|
+
declare const releaseStrategyIndicatorsReplayCache: (keyPrefix: string) => void;
|
|
6
7
|
interface StrategyIndicatorsStateParams {
|
|
7
8
|
env: string;
|
|
8
9
|
data: KlineChartData;
|
|
9
10
|
btcData: KlineChartData;
|
|
11
|
+
ethData?: KlineChartData;
|
|
10
12
|
btcBinanceData?: KlineChartData;
|
|
11
13
|
btcCoinbaseData?: KlineChartData;
|
|
12
14
|
periods?: Partial<IndicatorPeriods>;
|
|
13
15
|
pluginRegistryScope?: string;
|
|
16
|
+
initialRuntimeState?: IndicatorsControllerRuntimeState | IndicatorsControllerCheckpointState | null;
|
|
17
|
+
replayStartIndex?: number;
|
|
18
|
+
sharedReplayKey?: string;
|
|
19
|
+
useBtcReference?: boolean;
|
|
14
20
|
}
|
|
15
|
-
declare const createStrategyIndicatorsState: ({ env, data, btcData, btcBinanceData, btcCoinbaseData, periods, pluginRegistryScope, }: StrategyIndicatorsStateParams) => StrategyIndicatorsState;
|
|
21
|
+
declare const createStrategyIndicatorsState: ({ env, data, btcData, ethData, btcBinanceData, btcCoinbaseData, periods, pluginRegistryScope, initialRuntimeState, replayStartIndex, sharedReplayKey, useBtcReference, }: StrategyIndicatorsStateParams) => StrategyIndicatorsState;
|
|
16
22
|
|
|
23
|
+
interface StrategyMarketSnapshot {
|
|
24
|
+
fullData: KlineChartData;
|
|
25
|
+
lastCandle: KlineChartItem;
|
|
26
|
+
timestamp: number;
|
|
27
|
+
currentPrice: number;
|
|
28
|
+
}
|
|
17
29
|
interface StrategyMarketSnapshotParams {
|
|
18
30
|
env: string;
|
|
19
31
|
connector: Connector;
|
|
@@ -21,9 +33,9 @@ interface StrategyMarketSnapshotParams {
|
|
|
21
33
|
interval: Interval;
|
|
22
34
|
cachedData: KlineChartData;
|
|
23
35
|
preloadStart: number;
|
|
24
|
-
backtestPriceMode?: BacktestPriceMode;
|
|
25
36
|
}
|
|
26
|
-
declare const
|
|
37
|
+
declare const resolveBacktestExecutionPrice: (candle: KlineChartItem, backtestPriceMode?: BacktestPriceMode) => number;
|
|
38
|
+
declare const getStrategyMarketSnapshot: ({ env, connector, symbol, interval, cachedData, preloadStart, }: StrategyMarketSnapshotParams) => Promise<StrategyMarketSnapshot>;
|
|
27
39
|
declare const calculateRiskRatio: ({ direction, currentPrice, takeProfitPrice, stopLossPrice, }: {
|
|
28
40
|
direction: Direction;
|
|
29
41
|
currentPrice: number;
|
|
@@ -57,6 +69,12 @@ type MlRuntimeConfigLike = {
|
|
|
57
69
|
ML_ENABLED?: boolean;
|
|
58
70
|
ML_THRESHOLD?: number;
|
|
59
71
|
};
|
|
72
|
+
declare const buildBaseContextGateFeatures: ({ baseContext, direction, prices, }: {
|
|
73
|
+
baseContext: BaseStrategyContextSnapshot;
|
|
74
|
+
direction: Direction | null;
|
|
75
|
+
prices?: StrategySignalPriceParams | null;
|
|
76
|
+
}) => NonNullable<BaseStrategyContextSnapshot["gateFeatures"]>;
|
|
77
|
+
declare const refreshSignalBaseContextGateFeatures: (signal: Signal) => Signal;
|
|
60
78
|
declare const mapAiRuntimeFromConfig: <TConfig extends AiRuntimeConfigLike>(config: TConfig, overrides?: Partial<StrategyRuntimeAiOptions>) => StrategyRuntimeAiOptions;
|
|
61
79
|
declare const mapMlRuntimeFromConfig: <TConfig extends MlRuntimeConfigLike>(config: TConfig, overrides?: Partial<StrategyRuntimeMlOptions>) => StrategyRuntimeMlOptions;
|
|
62
80
|
declare const buildStrategySignal: ({ signalId, strategy, symbol, interval, direction, timestamp, prices, figures, indicators, additionalIndicators, isConfigFromBacktest, }: BuildStrategySignalParams) => Signal;
|
|
@@ -82,14 +100,15 @@ interface CreateStrategyAPIParams {
|
|
|
82
100
|
env: string;
|
|
83
101
|
connector: Connector;
|
|
84
102
|
cachedData: KlineChartData;
|
|
85
|
-
indicatorsState?:
|
|
86
|
-
next: (candle: KlineChartData[number], btcCandle: KlineChartData[number]) => unknown;
|
|
87
|
-
};
|
|
88
|
-
preloadStart?: number;
|
|
89
|
-
backtestPriceMode?: BacktestPriceMode;
|
|
103
|
+
indicatorsState?: StrategyIndicatorsState;
|
|
90
104
|
isConfigFromBacktest?: Signal['isConfigFromBacktest'];
|
|
105
|
+
sharedReplayKey?: string;
|
|
106
|
+
getSharedReplayState?: StrategySharedReplayStateGetter;
|
|
91
107
|
}
|
|
92
|
-
declare const createStrategyAPI: ({ strategy, symbol, interval, env, connector, cachedData, indicatorsState,
|
|
108
|
+
declare const createStrategyAPI: <TIndicators = IndicatorsHistorySnapshot | Record<string, unknown>>({ strategy, symbol, interval, env, connector, cachedData, indicatorsState, isConfigFromBacktest, sharedReplayKey, getSharedReplayState, }: CreateStrategyAPIParams) => StrategyAPI<TIndicators>;
|
|
109
|
+
|
|
110
|
+
declare const getSharedStrategyReplayState: <TState>(key: string | undefined, createState: () => TState) => TState;
|
|
111
|
+
declare const releaseStrategyReplayCache: (keyPrefix: string) => void;
|
|
93
112
|
|
|
94
113
|
interface LastTradeController {
|
|
95
114
|
isInCooldown: (timestamp: number) => boolean;
|
|
@@ -103,4 +122,4 @@ interface CreateLastTradeControllerParams {
|
|
|
103
122
|
}
|
|
104
123
|
declare const createLastTradeController: ({ env, enabled, cooldownMs, }: CreateLastTradeControllerParams) => LastTradeController;
|
|
105
124
|
|
|
106
|
-
export { buildDefaultIndicatorPeriods, buildEntrySignalDecision, buildStrategySignal, calculateRiskRatio, createLastTradeController, createStrategyAPI, createStrategyIndicatorsState, getDirectionalTpSlPrices, getStrategyMarketSnapshot, mapAiRuntimeFromConfig, mapMlRuntimeFromConfig };
|
|
125
|
+
export { buildBaseContextGateFeatures, buildDefaultIndicatorPeriods, buildEntrySignalDecision, buildStrategySignal, calculateRiskRatio, createLastTradeController, createStrategyAPI, createStrategyIndicatorsState, getDirectionalTpSlPrices, getSharedStrategyReplayState, getStrategyMarketSnapshot, mapAiRuntimeFromConfig, mapMlRuntimeFromConfig, refreshSignalBaseContextGateFeatures, releaseStrategyIndicatorsReplayCache, releaseStrategyReplayCache, resolveBacktestExecutionPrice };
|
package/dist/strategies.d.ts
CHANGED
|
@@ -1,19 +1,31 @@
|
|
|
1
|
-
import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, BacktestPriceMode,
|
|
2
|
-
import { I as IndicatorPeriods } from './indicators-
|
|
1
|
+
import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, KlineChartItem, BacktestPriceMode, BaseStrategyContextSnapshot, StrategySignalPriceParams, BuildStrategySignalDraft, StrategyEntrySignalContext, StrategyEntryOrderPlan, StrategyEntryRuntimeOptions, StrategyDecision, BuildStrategySignalParams, Signal, IndicatorsHistorySnapshot, StrategySharedReplayStateGetter, StrategyAPI, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions } from '@tradejs/types';
|
|
2
|
+
import { I as IndicatorPeriods, a as IndicatorsControllerRuntimeState, b as IndicatorsControllerCheckpointState } from './indicators-Da_i06-8.js';
|
|
3
3
|
|
|
4
4
|
type IndicatorPeriodsConfig = Partial<Record<'MA_FAST' | 'MA_MEDIUM' | 'MA_SLOW' | 'OBV_SMA' | 'ATR' | 'ATR_PCT_SHORT' | 'ATR_PCT_LONG' | 'BB' | 'BB_STD' | 'MACD_FAST' | 'MACD_SLOW' | 'MACD_SIGNAL' | 'LEVEL_LOOKBACK' | 'LEVEL_DELAY', number>>;
|
|
5
5
|
declare const buildDefaultIndicatorPeriods: (config: IndicatorPeriodsConfig) => Partial<IndicatorPeriods>;
|
|
6
|
+
declare const releaseStrategyIndicatorsReplayCache: (keyPrefix: string) => void;
|
|
6
7
|
interface StrategyIndicatorsStateParams {
|
|
7
8
|
env: string;
|
|
8
9
|
data: KlineChartData;
|
|
9
10
|
btcData: KlineChartData;
|
|
11
|
+
ethData?: KlineChartData;
|
|
10
12
|
btcBinanceData?: KlineChartData;
|
|
11
13
|
btcCoinbaseData?: KlineChartData;
|
|
12
14
|
periods?: Partial<IndicatorPeriods>;
|
|
13
15
|
pluginRegistryScope?: string;
|
|
16
|
+
initialRuntimeState?: IndicatorsControllerRuntimeState | IndicatorsControllerCheckpointState | null;
|
|
17
|
+
replayStartIndex?: number;
|
|
18
|
+
sharedReplayKey?: string;
|
|
19
|
+
useBtcReference?: boolean;
|
|
14
20
|
}
|
|
15
|
-
declare const createStrategyIndicatorsState: ({ env, data, btcData, btcBinanceData, btcCoinbaseData, periods, pluginRegistryScope, }: StrategyIndicatorsStateParams) => StrategyIndicatorsState;
|
|
21
|
+
declare const createStrategyIndicatorsState: ({ env, data, btcData, ethData, btcBinanceData, btcCoinbaseData, periods, pluginRegistryScope, initialRuntimeState, replayStartIndex, sharedReplayKey, useBtcReference, }: StrategyIndicatorsStateParams) => StrategyIndicatorsState;
|
|
16
22
|
|
|
23
|
+
interface StrategyMarketSnapshot {
|
|
24
|
+
fullData: KlineChartData;
|
|
25
|
+
lastCandle: KlineChartItem;
|
|
26
|
+
timestamp: number;
|
|
27
|
+
currentPrice: number;
|
|
28
|
+
}
|
|
17
29
|
interface StrategyMarketSnapshotParams {
|
|
18
30
|
env: string;
|
|
19
31
|
connector: Connector;
|
|
@@ -21,9 +33,9 @@ interface StrategyMarketSnapshotParams {
|
|
|
21
33
|
interval: Interval;
|
|
22
34
|
cachedData: KlineChartData;
|
|
23
35
|
preloadStart: number;
|
|
24
|
-
backtestPriceMode?: BacktestPriceMode;
|
|
25
36
|
}
|
|
26
|
-
declare const
|
|
37
|
+
declare const resolveBacktestExecutionPrice: (candle: KlineChartItem, backtestPriceMode?: BacktestPriceMode) => number;
|
|
38
|
+
declare const getStrategyMarketSnapshot: ({ env, connector, symbol, interval, cachedData, preloadStart, }: StrategyMarketSnapshotParams) => Promise<StrategyMarketSnapshot>;
|
|
27
39
|
declare const calculateRiskRatio: ({ direction, currentPrice, takeProfitPrice, stopLossPrice, }: {
|
|
28
40
|
direction: Direction;
|
|
29
41
|
currentPrice: number;
|
|
@@ -57,6 +69,12 @@ type MlRuntimeConfigLike = {
|
|
|
57
69
|
ML_ENABLED?: boolean;
|
|
58
70
|
ML_THRESHOLD?: number;
|
|
59
71
|
};
|
|
72
|
+
declare const buildBaseContextGateFeatures: ({ baseContext, direction, prices, }: {
|
|
73
|
+
baseContext: BaseStrategyContextSnapshot;
|
|
74
|
+
direction: Direction | null;
|
|
75
|
+
prices?: StrategySignalPriceParams | null;
|
|
76
|
+
}) => NonNullable<BaseStrategyContextSnapshot["gateFeatures"]>;
|
|
77
|
+
declare const refreshSignalBaseContextGateFeatures: (signal: Signal) => Signal;
|
|
60
78
|
declare const mapAiRuntimeFromConfig: <TConfig extends AiRuntimeConfigLike>(config: TConfig, overrides?: Partial<StrategyRuntimeAiOptions>) => StrategyRuntimeAiOptions;
|
|
61
79
|
declare const mapMlRuntimeFromConfig: <TConfig extends MlRuntimeConfigLike>(config: TConfig, overrides?: Partial<StrategyRuntimeMlOptions>) => StrategyRuntimeMlOptions;
|
|
62
80
|
declare const buildStrategySignal: ({ signalId, strategy, symbol, interval, direction, timestamp, prices, figures, indicators, additionalIndicators, isConfigFromBacktest, }: BuildStrategySignalParams) => Signal;
|
|
@@ -82,14 +100,15 @@ interface CreateStrategyAPIParams {
|
|
|
82
100
|
env: string;
|
|
83
101
|
connector: Connector;
|
|
84
102
|
cachedData: KlineChartData;
|
|
85
|
-
indicatorsState?:
|
|
86
|
-
next: (candle: KlineChartData[number], btcCandle: KlineChartData[number]) => unknown;
|
|
87
|
-
};
|
|
88
|
-
preloadStart?: number;
|
|
89
|
-
backtestPriceMode?: BacktestPriceMode;
|
|
103
|
+
indicatorsState?: StrategyIndicatorsState;
|
|
90
104
|
isConfigFromBacktest?: Signal['isConfigFromBacktest'];
|
|
105
|
+
sharedReplayKey?: string;
|
|
106
|
+
getSharedReplayState?: StrategySharedReplayStateGetter;
|
|
91
107
|
}
|
|
92
|
-
declare const createStrategyAPI: ({ strategy, symbol, interval, env, connector, cachedData, indicatorsState,
|
|
108
|
+
declare const createStrategyAPI: <TIndicators = IndicatorsHistorySnapshot | Record<string, unknown>>({ strategy, symbol, interval, env, connector, cachedData, indicatorsState, isConfigFromBacktest, sharedReplayKey, getSharedReplayState, }: CreateStrategyAPIParams) => StrategyAPI<TIndicators>;
|
|
109
|
+
|
|
110
|
+
declare const getSharedStrategyReplayState: <TState>(key: string | undefined, createState: () => TState) => TState;
|
|
111
|
+
declare const releaseStrategyReplayCache: (keyPrefix: string) => void;
|
|
93
112
|
|
|
94
113
|
interface LastTradeController {
|
|
95
114
|
isInCooldown: (timestamp: number) => boolean;
|
|
@@ -103,4 +122,4 @@ interface CreateLastTradeControllerParams {
|
|
|
103
122
|
}
|
|
104
123
|
declare const createLastTradeController: ({ env, enabled, cooldownMs, }: CreateLastTradeControllerParams) => LastTradeController;
|
|
105
124
|
|
|
106
|
-
export { buildDefaultIndicatorPeriods, buildEntrySignalDecision, buildStrategySignal, calculateRiskRatio, createLastTradeController, createStrategyAPI, createStrategyIndicatorsState, getDirectionalTpSlPrices, getStrategyMarketSnapshot, mapAiRuntimeFromConfig, mapMlRuntimeFromConfig };
|
|
125
|
+
export { buildBaseContextGateFeatures, buildDefaultIndicatorPeriods, buildEntrySignalDecision, buildStrategySignal, calculateRiskRatio, createLastTradeController, createStrategyAPI, createStrategyIndicatorsState, getDirectionalTpSlPrices, getSharedStrategyReplayState, getStrategyMarketSnapshot, mapAiRuntimeFromConfig, mapMlRuntimeFromConfig, refreshSignalBaseContextGateFeatures, releaseStrategyIndicatorsReplayCache, releaseStrategyReplayCache, resolveBacktestExecutionPrice };
|