@tradejs/core 1.0.9 → 1.0.10

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 (41) hide show
  1. package/dist/backtest.d.mts +109 -9
  2. package/dist/backtest.d.ts +109 -9
  3. package/dist/backtest.js +487 -145
  4. package/dist/backtest.mjs +414 -82
  5. package/dist/chunk-7P2KNFD4.mjs +11847 -0
  6. package/dist/{chunk-2ORZC66W.mjs → chunk-DXJ4NCFJ.mjs} +63 -6
  7. package/dist/chunk-OJPHC3S2.mjs +8 -0
  8. package/dist/{chunk-FNLPYYML.mjs → chunk-PNBS6J3G.mjs} +22 -1
  9. package/dist/constants.d.mts +25 -5
  10. package/dist/constants.d.ts +25 -5
  11. package/dist/constants.js +78 -9
  12. package/dist/constants.mjs +29 -5
  13. package/dist/data.mjs +3 -5
  14. package/dist/grid.d.mts +9 -0
  15. package/dist/grid.d.ts +9 -0
  16. package/dist/grid.js +168 -0
  17. package/dist/grid.mjs +98 -0
  18. package/dist/indicators-Da_i06-8.d.mts +288 -0
  19. package/dist/indicators-Da_i06-8.d.ts +288 -0
  20. package/dist/indicators.d.mts +4 -39
  21. package/dist/indicators.d.ts +4 -39
  22. package/dist/indicators.js +10488 -423
  23. package/dist/indicators.mjs +11 -3
  24. package/dist/strategies.d.mts +31 -12
  25. package/dist/strategies.d.ts +31 -12
  26. package/dist/strategies.js +11283 -336
  27. package/dist/strategies.mjs +1246 -119
  28. package/dist/{time-BMkFD4Kd.d.mts → time-BQ3AXmxo.d.mts} +3 -1
  29. package/dist/{time-BMkFD4Kd.d.ts → time-BQ3AXmxo.d.ts} +3 -1
  30. package/dist/time.d.mts +1 -1
  31. package/dist/time.d.ts +1 -1
  32. package/dist/time.js +38 -0
  33. package/dist/time.mjs +6 -2
  34. package/dist/trade.d.mts +54 -0
  35. package/dist/trade.d.ts +54 -0
  36. package/dist/trade.js +352 -0
  37. package/dist/trade.mjs +264 -0
  38. package/package.json +19 -5
  39. package/dist/chunk-UK6VTOUX.mjs +0 -1810
  40. package/dist/indicators-B-GGjP5F.d.mts +0 -65
  41. package/dist/indicators-B-GGjP5F.d.ts +0 -65
@@ -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-UK6VTOUX.mjs";
36
+ } from "./chunk-7P2KNFD4.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-PNBS6J3G.mjs";
40
+ import "./chunk-DXJ4NCFJ.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,
@@ -1,19 +1,31 @@
1
- import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, BacktestPriceMode, StrategyMarketSnapshot, BuildStrategySignalDraft, StrategyEntrySignalContext, StrategyEntryOrderPlan, StrategyEntryRuntimeOptions, StrategyDecision, BuildStrategySignalParams, Signal, StrategyAPI, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions } from '@tradejs/types';
2
- import { I as IndicatorPeriods } from './indicators-B-GGjP5F.mjs';
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 getStrategyMarketSnapshot: ({ env, connector, symbol, interval, cachedData, preloadStart, backtestPriceMode, }: StrategyMarketSnapshotParams) => Promise<StrategyMarketSnapshot>;
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, preloadStart, backtestPriceMode, isConfigFromBacktest, }: CreateStrategyAPIParams) => StrategyAPI;
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 };
@@ -1,19 +1,31 @@
1
- import { KlineChartData, StrategyIndicatorsState, Direction, Connector, Interval, BacktestPriceMode, StrategyMarketSnapshot, BuildStrategySignalDraft, StrategyEntrySignalContext, StrategyEntryOrderPlan, StrategyEntryRuntimeOptions, StrategyDecision, BuildStrategySignalParams, Signal, StrategyAPI, StrategyRuntimeAiOptions, StrategyRuntimeMlOptions } from '@tradejs/types';
2
- import { I as IndicatorPeriods } from './indicators-B-GGjP5F.js';
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 getStrategyMarketSnapshot: ({ env, connector, symbol, interval, cachedData, preloadStart, backtestPriceMode, }: StrategyMarketSnapshotParams) => Promise<StrategyMarketSnapshot>;
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, preloadStart, backtestPriceMode, isConfigFromBacktest, }: CreateStrategyAPIParams) => StrategyAPI;
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 };