@elizaos/plugin-auto-trader 2.0.0-alpha.1 → 2.0.0-alpha.2
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/LICENSE +21 -0
- package/dist/{MeanReversionStrategy-4ZBKT4XN.js → MeanReversionStrategy-VQJGG3DE.js} +2 -2
- package/dist/{chunk-BSXTWI5Q.js → chunk-7GI4G3ZN.js} +1 -2
- package/dist/chunk-7GI4G3ZN.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/dist/chunk-BSXTWI5Q.js.map +0 -1
- /package/dist/{MeanReversionStrategy-4ZBKT4XN.js.map → MeanReversionStrategy-VQJGG3DE.js.map} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shaw Walters and elizaOS Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
MeanReversionStrategy
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7GI4G3ZN.js";
|
|
4
4
|
import "./chunk-AS6N6A3H.js";
|
|
5
5
|
import "./chunk-PZ5AY32C.js";
|
|
6
6
|
export {
|
|
7
7
|
MeanReversionStrategy
|
|
8
8
|
};
|
|
9
|
-
//# sourceMappingURL=MeanReversionStrategy-
|
|
9
|
+
//# sourceMappingURL=MeanReversionStrategy-VQJGG3DE.js.map
|
|
@@ -6,7 +6,6 @@ var MeanReversionStrategy = class {
|
|
|
6
6
|
description = "A strategy that trades on mean reversion patterns using Bollinger Bands and RSI";
|
|
7
7
|
config;
|
|
8
8
|
initialized = false;
|
|
9
|
-
runtime = null;
|
|
10
9
|
constructor(config) {
|
|
11
10
|
this.config = {
|
|
12
11
|
// Default configuration
|
|
@@ -159,4 +158,4 @@ var MeanReversionStrategy = class {
|
|
|
159
158
|
export {
|
|
160
159
|
MeanReversionStrategy
|
|
161
160
|
};
|
|
162
|
-
//# sourceMappingURL=chunk-
|
|
161
|
+
//# sourceMappingURL=chunk-7GI4G3ZN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/strategies/MeanReversionStrategy.ts"],"sourcesContent":["import type { AgentRuntime } from \"@elizaos/core\";\nimport * as talib from \"technicalindicators\";\nimport {\n type AgentState,\n type OHLCV,\n OrderType,\n type PortfolioSnapshot,\n type StrategyContextMarketData,\n type TradeOrder,\n TradeType,\n type TradingStrategy,\n} from \"../types.ts\";\n\nexport interface MeanReversionConfig {\n // Bollinger Bands settings\n bbPeriod: number;\n bbStdDev: number;\n\n // RSI settings\n rsiPeriod: number;\n rsiOversold: number;\n rsiOverbought: number;\n\n // Risk management\n positionSizePercent: number;\n stopLossPercent: number;\n takeProfitPercent: number;\n\n // Market condition filters\n minVolatility: number;\n maxVolatility: number;\n minVolumeRatio: number;\n\n // Entry/exit thresholds\n bbEntryThreshold: number; // How far outside BB for entry\n rsiConfirmation: boolean;\n}\n\nexport class MeanReversionStrategy implements TradingStrategy {\n public readonly id = \"mean-reversion-strategy\";\n public readonly name = \"MeanReversionStrategy\";\n public readonly description =\n \"A strategy that trades on mean reversion patterns using Bollinger Bands and RSI\";\n private config: MeanReversionConfig;\n private initialized = false;\n\n constructor(config?: Partial<MeanReversionConfig>) {\n this.config = {\n // Default configuration\n bbPeriod: 20,\n bbStdDev: 2,\n rsiPeriod: 14,\n rsiOversold: 30,\n rsiOverbought: 70,\n positionSizePercent: 0.02,\n stopLossPercent: 0.03,\n takeProfitPercent: 0.02,\n minVolatility: 0.01,\n maxVolatility: 0.05,\n minVolumeRatio: 1.2,\n bbEntryThreshold: 0.95,\n rsiConfirmation: true,\n ...config,\n };\n }\n\n async initialize(runtime: AgentRuntime): Promise<void> {\n this.runtime = runtime;\n this.initialized = true;\n console.log(`[${this.name}] Initialized with config:`, this.config);\n }\n\n isReady(): boolean {\n return this.initialized;\n }\n\n async decide(params: {\n marketData: StrategyContextMarketData;\n agentState: AgentState;\n portfolioSnapshot: PortfolioSnapshot;\n agentRuntime?: AgentRuntime;\n }): Promise<TradeOrder | null> {\n const { marketData, agentState, portfolioSnapshot } = params;\n const { priceData, currentPrice } = marketData;\n\n if (\n !priceData ||\n priceData.length < Math.max(this.config.bbPeriod, this.config.rsiPeriod) + 10\n ) {\n return null;\n }\n\n // Extract price arrays\n const closes = priceData.map((c: OHLCV) => c.close);\n const _highs = priceData.map((c: OHLCV) => c.high);\n const _lows = priceData.map((c: OHLCV) => c.low);\n const volumes = priceData.map((c: OHLCV) => c.volume);\n\n // Calculate indicators\n const bb = this.calculateBollingerBands(closes);\n const rsi = this.calculateRSI(closes);\n const volatility = agentState.volatility;\n const volumeRatio = this.calculateVolumeRatio(volumes);\n\n if (!bb || !rsi || rsi.length === 0) return null;\n\n const currentRSI = rsi[rsi.length - 1];\n const { upper, lower, middle } = bb;\n\n // Market condition checks\n if (volatility < this.config.minVolatility || volatility > this.config.maxVolatility) {\n console.log(\n `[${this.name}] Volatility ${volatility.toFixed(4)} outside range [${this.config.minVolatility}, ${this.config.maxVolatility}]`,\n );\n return null;\n }\n\n if (volumeRatio < this.config.minVolumeRatio) {\n console.log(\n `[${this.name}] Volume ratio ${volumeRatio.toFixed(2)} below minimum ${this.config.minVolumeRatio}`,\n );\n return null;\n }\n\n // Check for mean reversion opportunities\n const distanceFromUpper = (upper - currentPrice) / currentPrice;\n const distanceFromLower = (currentPrice - lower) / currentPrice;\n const distanceFromMiddle = Math.abs(currentPrice - middle) / middle;\n\n // Buy signal: Price near lower band + RSI oversold\n if (currentPrice <= lower * (1 + (1 - this.config.bbEntryThreshold))) {\n const rsiCondition = !this.config.rsiConfirmation || currentRSI < this.config.rsiOversold;\n\n if (rsiCondition) {\n const positionSize = this.calculatePositionSize(portfolioSnapshot.totalValue, currentPrice);\n\n console.log(`[${this.name}] BUY SIGNAL - Price at lower BB, RSI: ${currentRSI.toFixed(2)}`);\n\n return {\n action: TradeType.BUY,\n orderType: OrderType.MARKET,\n pair: \"SOL/USDC\", // This should come from context\n quantity: positionSize,\n reason: `Mean reversion buy: Price ${distanceFromLower.toFixed(2)}% below lower BB, RSI: ${currentRSI.toFixed(2)}`,\n timestamp: Date.now(),\n };\n }\n }\n\n // Sell signal: Price near upper band + RSI overbought\n if (currentPrice >= upper * (1 - (1 - this.config.bbEntryThreshold))) {\n const rsiCondition = !this.config.rsiConfirmation || currentRSI > this.config.rsiOverbought;\n\n if (rsiCondition) {\n const currentHolding = portfolioSnapshot.holdings.SOL || 0;\n\n if (currentHolding > 0) {\n console.log(\n `[${this.name}] SELL SIGNAL - Price at upper BB, RSI: ${currentRSI.toFixed(2)}`,\n );\n\n return {\n action: TradeType.SELL,\n orderType: OrderType.MARKET,\n pair: \"SOL/USDC\",\n quantity: currentHolding,\n reason: `Mean reversion sell: Price ${distanceFromUpper.toFixed(2)}% above upper BB, RSI: ${currentRSI.toFixed(2)}`,\n timestamp: Date.now(),\n };\n }\n }\n }\n\n // Exit position if price returns to mean\n const currentHolding = portfolioSnapshot.holdings.SOL || 0;\n if (currentHolding > 0 && distanceFromMiddle < 0.01) {\n console.log(`[${this.name}] Price returned to mean, exiting position`);\n\n return {\n action: TradeType.SELL,\n orderType: OrderType.MARKET,\n pair: \"SOL/USDC\",\n quantity: currentHolding,\n reason: `Price returned to mean (${distanceFromMiddle.toFixed(2)}% from middle BB)`,\n timestamp: Date.now(),\n };\n }\n\n return null;\n }\n\n private calculateBollingerBands(\n closes: number[],\n ): { upper: number; middle: number; lower: number } | null {\n if (closes.length < this.config.bbPeriod) return null;\n\n const bb = talib.BollingerBands.calculate({\n period: this.config.bbPeriod,\n values: closes,\n stdDev: this.config.bbStdDev,\n });\n\n if (!bb || bb.length === 0) return null;\n\n const lastBB = bb[bb.length - 1];\n return {\n upper: lastBB.upper,\n middle: lastBB.middle,\n lower: lastBB.lower,\n };\n }\n\n private calculateRSI(closes: number[]): number[] {\n const rsi = talib.RSI.calculate({\n period: this.config.rsiPeriod,\n values: closes,\n });\n return rsi;\n }\n\n private calculateVolumeRatio(volumes: number[]): number {\n if (volumes.length < 20) return 0;\n\n const recentVolume = volumes.slice(-5).reduce((a, b) => a + b, 0) / 5;\n const avgVolume = volumes.slice(-20).reduce((a, b) => a + b, 0) / 20;\n\n return avgVolume > 0 ? recentVolume / avgVolume : 0;\n }\n\n private calculatePositionSize(portfolioValue: number, price: number): number {\n const positionValue = portfolioValue * this.config.positionSizePercent;\n return positionValue / price;\n }\n\n updateConfig(config: Partial<MeanReversionConfig>): void {\n this.config = { ...this.config, ...config };\n console.log(`[${this.name}] Config updated:`, this.config);\n }\n\n getConfig(): MeanReversionConfig {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EQ,aAAa,QAA4B;AAC/C,UAAM,MAAY,UAAI,UAAU;AAAA,MAC9B,QAAQ,KAAK,OAAO;AAAA,MACpB,QAAQ;AAAA,IACV,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEQ,qBAAqB,SAA2B;AACtD,QAAI,QAAQ,SAAS,GAAI,QAAO;AAEhC,UAAM,eAAe,QAAQ,MAAM,EAAE,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,IAAI;AACpE,UAAM,YAAY,QAAQ,MAAM,GAAG,EAAE,OAAO,CAAC,GAAG,MAAM,IAAI,GAAG,CAAC,IAAI;AAElE,WAAO,YAAY,IAAI,eAAe,YAAY;AAAA,EACpD;AAAA,EAEQ,sBAAsB,gBAAwB,OAAuB;AAC3E,UAAM,gBAAgB,iBAAiB,KAAK,OAAO;AACnD,WAAO,gBAAgB;AAAA,EACzB;AAAA,EAEA,aAAa,QAA4C;AACvD,SAAK,SAAS,EAAE,GAAG,KAAK,QAAQ,GAAG,OAAO;AAC1C,YAAQ,IAAI,IAAI,KAAK,IAAI,qBAAqB,KAAK,MAAM;AAAA,EAC3D;AAAA,EAEA,YAAiC;AAC/B,WAAO,EAAE,GAAG,KAAK,OAAO;AAAA,EAC1B;AACF;","names":["currentHolding"]}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-Z6SUPK5O.js";
|
|
4
4
|
import {
|
|
5
5
|
MeanReversionStrategy
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-7GI4G3ZN.js";
|
|
7
7
|
import {
|
|
8
8
|
RuleBasedStrategy
|
|
9
9
|
} from "./chunk-GYTZTIWK.js";
|
|
@@ -6623,7 +6623,7 @@ var AutoTradingManager = class _AutoTradingManager extends Service2 {
|
|
|
6623
6623
|
{ RandomStrategy: RandomStrategy2 }
|
|
6624
6624
|
] = await Promise.all([
|
|
6625
6625
|
import("./MomentumBreakoutStrategy-O7I3EMGB.js"),
|
|
6626
|
-
import("./MeanReversionStrategy-
|
|
6626
|
+
import("./MeanReversionStrategy-VQJGG3DE.js"),
|
|
6627
6627
|
import("./RuleBasedStrategy-7O47DGTU.js"),
|
|
6628
6628
|
import("./RandomStrategy-GPGG56MV.js")
|
|
6629
6629
|
]);
|