@tradejs/node 2.0.6 → 2.0.7
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/dist/ai.js +47 -1
- package/dist/ai.mjs +1 -1
- package/dist/backtest.js +486 -84
- package/dist/backtest.mjs +30 -5
- package/dist/{chunk-2DZCHRP6.mjs → chunk-76TEMQKX.mjs} +418 -80
- package/dist/{chunk-IUZML4RK.mjs → chunk-PD25CABK.mjs} +47 -1
- package/dist/cli.js +47 -1
- package/dist/cli.mjs +1 -1
- package/dist/strategies.d.mts +49 -1
- package/dist/strategies.d.ts +49 -1
- package/dist/strategies.js +541 -90
- package/dist/strategies.mjs +78 -8
- package/package.json +4 -4
|
@@ -191,6 +191,51 @@ var buildMarketBreadthContextFromSignal = (signal) => {
|
|
|
191
191
|
dispersion: toFiniteNumber(breadth.dispersion)
|
|
192
192
|
};
|
|
193
193
|
};
|
|
194
|
+
var buildMarketBreadthsContextFromSignal = (signal) => {
|
|
195
|
+
const baseContext = toRecord(signal.additionalIndicators?.baseContext);
|
|
196
|
+
const relative = toRecord(baseContext?.relative);
|
|
197
|
+
const breadths = toRecord(relative?.marketBreadths);
|
|
198
|
+
const build = (key) => {
|
|
199
|
+
const breadth = toRecord(breadths?.[key]);
|
|
200
|
+
if (!breadth) {
|
|
201
|
+
return {
|
|
202
|
+
source: null,
|
|
203
|
+
available: false,
|
|
204
|
+
universe: null,
|
|
205
|
+
interval: null,
|
|
206
|
+
stale: null,
|
|
207
|
+
symbolsCount: null,
|
|
208
|
+
advanceDeclineRatio: null,
|
|
209
|
+
pctAboveMa20: null,
|
|
210
|
+
pctAboveMa50: null,
|
|
211
|
+
equalWeightedReturn: null,
|
|
212
|
+
volumeWeightedReturn: null,
|
|
213
|
+
dispersion: null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
source: String(breadth.source ?? ""),
|
|
218
|
+
available: true,
|
|
219
|
+
universe: String(breadth.universe ?? ""),
|
|
220
|
+
interval: String(breadth.interval ?? ""),
|
|
221
|
+
stale: typeof breadth.stale === "boolean" ? breadth.stale : null,
|
|
222
|
+
symbolsCount: toFiniteNumber(breadth.symbolsCount),
|
|
223
|
+
advanceDeclineRatio: toFiniteNumber(breadth.advanceDeclineRatio),
|
|
224
|
+
pctAboveMa20: toFiniteNumber(breadth.pctAboveMa20),
|
|
225
|
+
pctAboveMa50: toFiniteNumber(breadth.pctAboveMa50),
|
|
226
|
+
equalWeightedReturn: toFiniteNumber(breadth.equalWeightedReturn),
|
|
227
|
+
volumeWeightedReturn: toFiniteNumber(breadth.volumeWeightedReturn),
|
|
228
|
+
dispersion: toFiniteNumber(breadth.dispersion)
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
return {
|
|
232
|
+
top5: build("top5"),
|
|
233
|
+
top10: build("top10"),
|
|
234
|
+
top30: build("top30"),
|
|
235
|
+
top50: build("top50"),
|
|
236
|
+
top100: build("top100")
|
|
237
|
+
};
|
|
238
|
+
};
|
|
194
239
|
var buildTargetVsBtcContextFromSignal = (signal) => {
|
|
195
240
|
const baseContext = toRecord(signal.additionalIndicators?.baseContext);
|
|
196
241
|
const relative = toRecord(baseContext?.relative);
|
|
@@ -528,6 +573,7 @@ var buildAiMarketContext = (signal) => ({
|
|
|
528
573
|
},
|
|
529
574
|
relative: {
|
|
530
575
|
marketBreadth: buildMarketBreadthContextFromSignal(signal),
|
|
576
|
+
marketBreadths: buildMarketBreadthsContextFromSignal(signal),
|
|
531
577
|
targetVsBtc: buildTargetVsBtcContextFromSignal(signal),
|
|
532
578
|
btcAltRegime: buildBtcAltRegimeContextFromSignal(signal),
|
|
533
579
|
cmcGlobal: buildCmcGlobalContextFromSignal(signal),
|
|
@@ -806,7 +852,7 @@ Input payload structure:
|
|
|
806
852
|
\u2022 \`marketContext.execution.binanceCoinbaseSpread\`: AI-friendly BTC spread view projected from \`payload.additionalIndicators.baseContext.relative.execution.venueSpread\`; \`value=(Coinbase-Binance)/Binance\`, \`bps=value*10000\`.
|
|
807
853
|
\u2022 \`marketContext.participation.trueDelta\`: Binance taker buy/sell volume delta from kline payload when \`source=kline_taker_volume\`; otherwise absent/unavailable.
|
|
808
854
|
\u2022 \`marketContext.participation.tradeFlow\`: Binance aggTrades buy/sell pressure buckets when available.
|
|
809
|
-
\u2022 \`marketContext.relative.
|
|
855
|
+
\u2022 \`marketContext.relative.marketBreadths.top5|top10|top30|top50|top100\`: equal/volume-weighted alt-basket return, advance/decline ratio, and MA breadth for the five versioned Binance breadth universes. \`marketBreadth\` remains the top30 primary view used by existing gates.
|
|
810
856
|
\u2022 \`marketContext.relative.targetVsBtc\`: target/BTC ratio returns, alpha, beta, and short-window correlation; use it to decide whether the target is leading or lagging BTC in the signal direction.
|
|
811
857
|
\u2022 \`marketContext.relative.btcAltRegime\`: Binance-derived BTC-vs-alt basket regime, BTC/alt 24h returns, BTC turnover share, and alt dispersion; use it as a broad alt-market risk pocket.
|
|
812
858
|
\u2022 \`marketContext.relative.cmcGlobal\`: historical CoinMarketCap global market metrics: total/alt market cap, total/alt volume, BTC/ETH dominance and 24h changes, active markets, \`interval\`, and \`altLiquidityRegime\`.
|
package/dist/cli.js
CHANGED
|
@@ -5766,6 +5766,51 @@ var buildMarketBreadthContextFromSignal = (signal) => {
|
|
|
5766
5766
|
dispersion: toFiniteNumber(breadth.dispersion)
|
|
5767
5767
|
};
|
|
5768
5768
|
};
|
|
5769
|
+
var buildMarketBreadthsContextFromSignal = (signal) => {
|
|
5770
|
+
const baseContext = toRecord(signal.additionalIndicators?.baseContext);
|
|
5771
|
+
const relative = toRecord(baseContext?.relative);
|
|
5772
|
+
const breadths = toRecord(relative?.marketBreadths);
|
|
5773
|
+
const build = (key) => {
|
|
5774
|
+
const breadth = toRecord(breadths?.[key]);
|
|
5775
|
+
if (!breadth) {
|
|
5776
|
+
return {
|
|
5777
|
+
source: null,
|
|
5778
|
+
available: false,
|
|
5779
|
+
universe: null,
|
|
5780
|
+
interval: null,
|
|
5781
|
+
stale: null,
|
|
5782
|
+
symbolsCount: null,
|
|
5783
|
+
advanceDeclineRatio: null,
|
|
5784
|
+
pctAboveMa20: null,
|
|
5785
|
+
pctAboveMa50: null,
|
|
5786
|
+
equalWeightedReturn: null,
|
|
5787
|
+
volumeWeightedReturn: null,
|
|
5788
|
+
dispersion: null
|
|
5789
|
+
};
|
|
5790
|
+
}
|
|
5791
|
+
return {
|
|
5792
|
+
source: String(breadth.source ?? ""),
|
|
5793
|
+
available: true,
|
|
5794
|
+
universe: String(breadth.universe ?? ""),
|
|
5795
|
+
interval: String(breadth.interval ?? ""),
|
|
5796
|
+
stale: typeof breadth.stale === "boolean" ? breadth.stale : null,
|
|
5797
|
+
symbolsCount: toFiniteNumber(breadth.symbolsCount),
|
|
5798
|
+
advanceDeclineRatio: toFiniteNumber(breadth.advanceDeclineRatio),
|
|
5799
|
+
pctAboveMa20: toFiniteNumber(breadth.pctAboveMa20),
|
|
5800
|
+
pctAboveMa50: toFiniteNumber(breadth.pctAboveMa50),
|
|
5801
|
+
equalWeightedReturn: toFiniteNumber(breadth.equalWeightedReturn),
|
|
5802
|
+
volumeWeightedReturn: toFiniteNumber(breadth.volumeWeightedReturn),
|
|
5803
|
+
dispersion: toFiniteNumber(breadth.dispersion)
|
|
5804
|
+
};
|
|
5805
|
+
};
|
|
5806
|
+
return {
|
|
5807
|
+
top5: build("top5"),
|
|
5808
|
+
top10: build("top10"),
|
|
5809
|
+
top30: build("top30"),
|
|
5810
|
+
top50: build("top50"),
|
|
5811
|
+
top100: build("top100")
|
|
5812
|
+
};
|
|
5813
|
+
};
|
|
5769
5814
|
var buildTargetVsBtcContextFromSignal = (signal) => {
|
|
5770
5815
|
const baseContext = toRecord(signal.additionalIndicators?.baseContext);
|
|
5771
5816
|
const relative = toRecord(baseContext?.relative);
|
|
@@ -6103,6 +6148,7 @@ var buildAiMarketContext = (signal) => ({
|
|
|
6103
6148
|
},
|
|
6104
6149
|
relative: {
|
|
6105
6150
|
marketBreadth: buildMarketBreadthContextFromSignal(signal),
|
|
6151
|
+
marketBreadths: buildMarketBreadthsContextFromSignal(signal),
|
|
6106
6152
|
targetVsBtc: buildTargetVsBtcContextFromSignal(signal),
|
|
6107
6153
|
btcAltRegime: buildBtcAltRegimeContextFromSignal(signal),
|
|
6108
6154
|
cmcGlobal: buildCmcGlobalContextFromSignal(signal),
|
|
@@ -6773,7 +6819,7 @@ Input payload structure:
|
|
|
6773
6819
|
\u2022 \`marketContext.execution.binanceCoinbaseSpread\`: AI-friendly BTC spread view projected from \`payload.additionalIndicators.baseContext.relative.execution.venueSpread\`; \`value=(Coinbase-Binance)/Binance\`, \`bps=value*10000\`.
|
|
6774
6820
|
\u2022 \`marketContext.participation.trueDelta\`: Binance taker buy/sell volume delta from kline payload when \`source=kline_taker_volume\`; otherwise absent/unavailable.
|
|
6775
6821
|
\u2022 \`marketContext.participation.tradeFlow\`: Binance aggTrades buy/sell pressure buckets when available.
|
|
6776
|
-
\u2022 \`marketContext.relative.
|
|
6822
|
+
\u2022 \`marketContext.relative.marketBreadths.top5|top10|top30|top50|top100\`: equal/volume-weighted alt-basket return, advance/decline ratio, and MA breadth for the five versioned Binance breadth universes. \`marketBreadth\` remains the top30 primary view used by existing gates.
|
|
6777
6823
|
\u2022 \`marketContext.relative.targetVsBtc\`: target/BTC ratio returns, alpha, beta, and short-window correlation; use it to decide whether the target is leading or lagging BTC in the signal direction.
|
|
6778
6824
|
\u2022 \`marketContext.relative.btcAltRegime\`: Binance-derived BTC-vs-alt basket regime, BTC/alt 24h returns, BTC turnover share, and alt dispersion; use it as a broad alt-market risk pocket.
|
|
6779
6825
|
\u2022 \`marketContext.relative.cmcGlobal\`: historical CoinMarketCap global market metrics: total/alt market cap, total/alt volume, BTC/ETH dominance and 24h changes, active markets, \`interval\`, and \`altLiquidityRegime\`.
|
package/dist/cli.mjs
CHANGED
package/dist/strategies.d.mts
CHANGED
|
@@ -56,6 +56,26 @@ interface ExecuteEntryOrderParams {
|
|
|
56
56
|
beforePlaceOrder?: () => Promise<void>;
|
|
57
57
|
recordRuntimeTrade?: boolean;
|
|
58
58
|
}
|
|
59
|
+
declare const getOrderArrivalSnapshot: ({ connector, symbol, }: {
|
|
60
|
+
connector: Connector;
|
|
61
|
+
symbol: string;
|
|
62
|
+
}) => Promise<{
|
|
63
|
+
arrivalSnapshotTime: number;
|
|
64
|
+
arrivalSource: string;
|
|
65
|
+
bid: number | null;
|
|
66
|
+
ask: number | null;
|
|
67
|
+
arrivalMid: number | null;
|
|
68
|
+
spreadBps: number | null;
|
|
69
|
+
}>;
|
|
70
|
+
declare const validateEntryProtectionAtArrival: ({ direction, signalPrice, bid, ask, arrivalMid, takeProfits, stopLossPrice, }: {
|
|
71
|
+
direction: Direction;
|
|
72
|
+
signalPrice: number;
|
|
73
|
+
bid: number | null;
|
|
74
|
+
ask: number | null;
|
|
75
|
+
arrivalMid: number | null;
|
|
76
|
+
takeProfits: Tp[];
|
|
77
|
+
stopLossPrice: number | null;
|
|
78
|
+
}) => void;
|
|
59
79
|
declare const executeEntryOrder: ({ connector, userName, symbol, direction, qty, currentPrice, timestamp, takeProfits, stopLossPrice, positionIntent, signal, beforePlaceOrder, recordRuntimeTrade, leverage, }: ExecuteEntryOrderParams) => Promise<number>;
|
|
60
80
|
|
|
61
81
|
declare const enrichSignalWithBinanceMarketContext: (params: {
|
|
@@ -67,6 +87,34 @@ declare const enrichSignalWithBinanceMarketContext: (params: {
|
|
|
67
87
|
maxAgeMs?: number;
|
|
68
88
|
}) => Promise<boolean>;
|
|
69
89
|
|
|
90
|
+
declare const BINANCE_BREADTH_UNIVERSE_KEYS: readonly ["top5", "top10", "top30", "top50", "top100"];
|
|
91
|
+
type BinanceBreadthUniverseKey = (typeof BINANCE_BREADTH_UNIVERSE_KEYS)[number];
|
|
92
|
+
type BinanceBreadthUniverseDefinition = {
|
|
93
|
+
key: BinanceBreadthUniverseKey;
|
|
94
|
+
size: number;
|
|
95
|
+
fingerprint: string;
|
|
96
|
+
universe: string;
|
|
97
|
+
symbols: string[];
|
|
98
|
+
};
|
|
99
|
+
type BinanceBreadthUniverseSnapshot = {
|
|
100
|
+
schemaVersion: 1;
|
|
101
|
+
updatedAt: string;
|
|
102
|
+
source: 'binance_spot_usdt_turnover24h';
|
|
103
|
+
fingerprint: string;
|
|
104
|
+
universes: Record<BinanceBreadthUniverseKey, {
|
|
105
|
+
size: number;
|
|
106
|
+
fingerprint: string;
|
|
107
|
+
symbols: string[];
|
|
108
|
+
}>;
|
|
109
|
+
};
|
|
110
|
+
declare const buildBinanceBreadthUniverseSnapshot: ({ rankedSymbols, updatedAt, }: {
|
|
111
|
+
rankedSymbols: string[];
|
|
112
|
+
updatedAt?: string;
|
|
113
|
+
}) => BinanceBreadthUniverseSnapshot;
|
|
114
|
+
declare const getBinanceBreadthUniverseSnapshot: () => BinanceBreadthUniverseSnapshot;
|
|
115
|
+
declare const getBinanceBreadthUniverses: () => BinanceBreadthUniverseDefinition[];
|
|
116
|
+
declare const getPrimaryBinanceBreadthUniverse: () => BinanceBreadthUniverseDefinition;
|
|
117
|
+
|
|
70
118
|
declare const enrichSignalWithCoinMarketCapContext: (params: {
|
|
71
119
|
signal: Signal;
|
|
72
120
|
env: string;
|
|
@@ -99,4 +147,4 @@ interface CreateCloseAllOnGlobalProfitBeforeSignalsHookParams {
|
|
|
99
147
|
}
|
|
100
148
|
declare const createCloseAllOnGlobalProfitBeforeSignalsHook: ({ getStrategyDefaultConfig, profitRiskMultiplier, }?: CreateCloseAllOnGlobalProfitBeforeSignalsHookParams) => TradejsConfigBeforeSignalsHook;
|
|
101
149
|
|
|
102
|
-
export { closeOppositePositionsBeforeOpen, createCloseAllOnGlobalProfitBeforeSignalsHook, createCloseOppositeBeforePlaceOrderHook, createMoveStopToBreakEvenAfterCoreDecisionHook, createMoveStopToBreakEvenOnBarHook, createStrategyRuntime, enrichSignalWithAi, enrichSignalWithBinanceMarketContext, enrichSignalWithCoinMarketCapContext, enrichSignalWithMl, enrichSignalWithMlAi, executeEntryOrder, resolveStrategyConfig };
|
|
150
|
+
export { BINANCE_BREADTH_UNIVERSE_KEYS, type BinanceBreadthUniverseDefinition, type BinanceBreadthUniverseKey, type BinanceBreadthUniverseSnapshot, buildBinanceBreadthUniverseSnapshot, closeOppositePositionsBeforeOpen, createCloseAllOnGlobalProfitBeforeSignalsHook, createCloseOppositeBeforePlaceOrderHook, createMoveStopToBreakEvenAfterCoreDecisionHook, createMoveStopToBreakEvenOnBarHook, createStrategyRuntime, enrichSignalWithAi, enrichSignalWithBinanceMarketContext, enrichSignalWithCoinMarketCapContext, enrichSignalWithMl, enrichSignalWithMlAi, executeEntryOrder, getBinanceBreadthUniverseSnapshot, getBinanceBreadthUniverses, getOrderArrivalSnapshot, getPrimaryBinanceBreadthUniverse, resolveStrategyConfig, validateEntryProtectionAtArrival };
|
package/dist/strategies.d.ts
CHANGED
|
@@ -56,6 +56,26 @@ interface ExecuteEntryOrderParams {
|
|
|
56
56
|
beforePlaceOrder?: () => Promise<void>;
|
|
57
57
|
recordRuntimeTrade?: boolean;
|
|
58
58
|
}
|
|
59
|
+
declare const getOrderArrivalSnapshot: ({ connector, symbol, }: {
|
|
60
|
+
connector: Connector;
|
|
61
|
+
symbol: string;
|
|
62
|
+
}) => Promise<{
|
|
63
|
+
arrivalSnapshotTime: number;
|
|
64
|
+
arrivalSource: string;
|
|
65
|
+
bid: number | null;
|
|
66
|
+
ask: number | null;
|
|
67
|
+
arrivalMid: number | null;
|
|
68
|
+
spreadBps: number | null;
|
|
69
|
+
}>;
|
|
70
|
+
declare const validateEntryProtectionAtArrival: ({ direction, signalPrice, bid, ask, arrivalMid, takeProfits, stopLossPrice, }: {
|
|
71
|
+
direction: Direction;
|
|
72
|
+
signalPrice: number;
|
|
73
|
+
bid: number | null;
|
|
74
|
+
ask: number | null;
|
|
75
|
+
arrivalMid: number | null;
|
|
76
|
+
takeProfits: Tp[];
|
|
77
|
+
stopLossPrice: number | null;
|
|
78
|
+
}) => void;
|
|
59
79
|
declare const executeEntryOrder: ({ connector, userName, symbol, direction, qty, currentPrice, timestamp, takeProfits, stopLossPrice, positionIntent, signal, beforePlaceOrder, recordRuntimeTrade, leverage, }: ExecuteEntryOrderParams) => Promise<number>;
|
|
60
80
|
|
|
61
81
|
declare const enrichSignalWithBinanceMarketContext: (params: {
|
|
@@ -67,6 +87,34 @@ declare const enrichSignalWithBinanceMarketContext: (params: {
|
|
|
67
87
|
maxAgeMs?: number;
|
|
68
88
|
}) => Promise<boolean>;
|
|
69
89
|
|
|
90
|
+
declare const BINANCE_BREADTH_UNIVERSE_KEYS: readonly ["top5", "top10", "top30", "top50", "top100"];
|
|
91
|
+
type BinanceBreadthUniverseKey = (typeof BINANCE_BREADTH_UNIVERSE_KEYS)[number];
|
|
92
|
+
type BinanceBreadthUniverseDefinition = {
|
|
93
|
+
key: BinanceBreadthUniverseKey;
|
|
94
|
+
size: number;
|
|
95
|
+
fingerprint: string;
|
|
96
|
+
universe: string;
|
|
97
|
+
symbols: string[];
|
|
98
|
+
};
|
|
99
|
+
type BinanceBreadthUniverseSnapshot = {
|
|
100
|
+
schemaVersion: 1;
|
|
101
|
+
updatedAt: string;
|
|
102
|
+
source: 'binance_spot_usdt_turnover24h';
|
|
103
|
+
fingerprint: string;
|
|
104
|
+
universes: Record<BinanceBreadthUniverseKey, {
|
|
105
|
+
size: number;
|
|
106
|
+
fingerprint: string;
|
|
107
|
+
symbols: string[];
|
|
108
|
+
}>;
|
|
109
|
+
};
|
|
110
|
+
declare const buildBinanceBreadthUniverseSnapshot: ({ rankedSymbols, updatedAt, }: {
|
|
111
|
+
rankedSymbols: string[];
|
|
112
|
+
updatedAt?: string;
|
|
113
|
+
}) => BinanceBreadthUniverseSnapshot;
|
|
114
|
+
declare const getBinanceBreadthUniverseSnapshot: () => BinanceBreadthUniverseSnapshot;
|
|
115
|
+
declare const getBinanceBreadthUniverses: () => BinanceBreadthUniverseDefinition[];
|
|
116
|
+
declare const getPrimaryBinanceBreadthUniverse: () => BinanceBreadthUniverseDefinition;
|
|
117
|
+
|
|
70
118
|
declare const enrichSignalWithCoinMarketCapContext: (params: {
|
|
71
119
|
signal: Signal;
|
|
72
120
|
env: string;
|
|
@@ -99,4 +147,4 @@ interface CreateCloseAllOnGlobalProfitBeforeSignalsHookParams {
|
|
|
99
147
|
}
|
|
100
148
|
declare const createCloseAllOnGlobalProfitBeforeSignalsHook: ({ getStrategyDefaultConfig, profitRiskMultiplier, }?: CreateCloseAllOnGlobalProfitBeforeSignalsHookParams) => TradejsConfigBeforeSignalsHook;
|
|
101
149
|
|
|
102
|
-
export { closeOppositePositionsBeforeOpen, createCloseAllOnGlobalProfitBeforeSignalsHook, createCloseOppositeBeforePlaceOrderHook, createMoveStopToBreakEvenAfterCoreDecisionHook, createMoveStopToBreakEvenOnBarHook, createStrategyRuntime, enrichSignalWithAi, enrichSignalWithBinanceMarketContext, enrichSignalWithCoinMarketCapContext, enrichSignalWithMl, enrichSignalWithMlAi, executeEntryOrder, resolveStrategyConfig };
|
|
150
|
+
export { BINANCE_BREADTH_UNIVERSE_KEYS, type BinanceBreadthUniverseDefinition, type BinanceBreadthUniverseKey, type BinanceBreadthUniverseSnapshot, buildBinanceBreadthUniverseSnapshot, closeOppositePositionsBeforeOpen, createCloseAllOnGlobalProfitBeforeSignalsHook, createCloseOppositeBeforePlaceOrderHook, createMoveStopToBreakEvenAfterCoreDecisionHook, createMoveStopToBreakEvenOnBarHook, createStrategyRuntime, enrichSignalWithAi, enrichSignalWithBinanceMarketContext, enrichSignalWithCoinMarketCapContext, enrichSignalWithMl, enrichSignalWithMlAi, executeEntryOrder, getBinanceBreadthUniverseSnapshot, getBinanceBreadthUniverses, getOrderArrivalSnapshot, getPrimaryBinanceBreadthUniverse, resolveStrategyConfig, validateEntryProtectionAtArrival };
|