79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
// --- Simplified Internal Types for Logic Test ---
|
|
enum SignalType {
|
|
BUY = 'BUY',
|
|
SELL = 'SELL',
|
|
NONE = 'NONE'
|
|
}
|
|
|
|
const logger = {
|
|
info: (msg: string) => console.log(`[INFO] ${msg}`),
|
|
error: (msg: string) => console.log(`[ERROR] ${msg}`)
|
|
};
|
|
|
|
// --- Mocking Configuration for Logic Test ---
|
|
const config = {
|
|
SYMBOL: 'BTC/USD',
|
|
LOW_STRESS_MODE: true
|
|
};
|
|
|
|
// --- Mocking Notifier ---
|
|
const notifier = {
|
|
sendAlert: async (msg: string) => {
|
|
console.log('\n--- DISCORD ALERT SENT ---');
|
|
console.log(msg);
|
|
console.log('--------------------------\n');
|
|
}
|
|
};
|
|
|
|
async function runSimulation() {
|
|
console.log('🚀 Starting Low-Stress Mode Simulation Test...\n');
|
|
|
|
let entryPrice: number | null = null;
|
|
let lastKnownPrice = 0;
|
|
|
|
// --- STEP 1: Simulate BUY Signal ---
|
|
console.log('Step 1: Simulating a BUY Signal at $60,000...');
|
|
lastKnownPrice = 60000;
|
|
|
|
// Simulate what happens in index.ts when result.changed is true
|
|
if (config.LOW_STRESS_MODE) {
|
|
entryPrice = lastKnownPrice;
|
|
logger.info(`[Low-Stress] Entry Price set at ${entryPrice}`);
|
|
await notifier.sendAlert(`🚨 *Trend Signal Alert* 🚨\nSignal: BUY\nAsset: ${config.SYMBOL}\nPrice: ${lastKnownPrice}`);
|
|
}
|
|
|
|
// --- STEP 2: Simulate Price Movement (Monitoring) ---
|
|
const simulatePrice = async (currentPrice: number) => {
|
|
lastKnownPrice = currentPrice;
|
|
if (config.LOW_STRESS_MODE && entryPrice) {
|
|
const percentChange = ((lastKnownPrice - entryPrice) / entryPrice) * 100;
|
|
logger.info(`[Low-Stress] Monitoring: ${percentChange.toFixed(2)}% | Price: ${lastKnownPrice}`);
|
|
|
|
if (percentChange >= 1.5) {
|
|
const tpMessage = `💰 *Take Profit Target Reached (+1.5%)* 💰\nAsset: ${config.SYMBOL}\nEntry: ${entryPrice}\nCurrent: ${lastKnownPrice}\nProfit: ${percentChange.toFixed(2)}%\nPlan: $10/Day Low-Stress ✅`;
|
|
await notifier.sendAlert(tpMessage);
|
|
entryPrice = null; // Reset
|
|
} else if (percentChange <= -0.7) {
|
|
const slMessage = `⚠️ *Stop Loss Buffer Hit (-0.7%)* ⚠️\nAsset: ${config.SYMBOL}\nEntry: ${entryPrice}\nCurrent: ${lastKnownPrice}\nLoss: ${percentChange.toFixed(2)}%\nPlan: Risk Managed 🛡️`;
|
|
await notifier.sendAlert(slMessage);
|
|
entryPrice = null; // Reset
|
|
}
|
|
}
|
|
};
|
|
|
|
console.log('\nStep 2: Price moves to $60,500 (+0.83%)...');
|
|
await simulatePrice(60500);
|
|
|
|
console.log('\nStep 3: Price moves to $60,950 (+1.58%)... (TP SHOULD TRIGGER)');
|
|
await simulatePrice(60950);
|
|
|
|
console.log('\nStep 4: Restarting for Stop Loss Test at $60,000...');
|
|
entryPrice = 60000;
|
|
console.log('\nStep 5: Price drops to $59,500 (-0.83%)... (SL SHOULD TRIGGER)');
|
|
await simulatePrice(59500);
|
|
|
|
console.log('\n✅ Simulation Test Complete.');
|
|
}
|
|
|
|
runSimulation();
|