63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
|
|
import { AutoTrader } from '../src/services/AutoTrader.js';
|
|
import { TradeExecutor } from '../src/services/TradeExecutor.js';
|
|
import { SignalDirection } from '../src/strategies/rules/types.js';
|
|
import logger from '../src/utils/logger.js';
|
|
|
|
// Mock Executor
|
|
const mockExecutor = {
|
|
getActivePosition: () => null,
|
|
getActiveSymbols: () => [],
|
|
checkCooldown: () => false,
|
|
openPosition: async (symbol, side, qty) => {
|
|
console.log(`✅ EXECUTION TRIGGERED: Open ${side} on ${symbol} for ${qty}`);
|
|
return { success: true };
|
|
},
|
|
syncPositions: async () => { },
|
|
currentProfileId: 'test-profile'
|
|
} as unknown as TradeExecutor;
|
|
|
|
// Mock Exchange
|
|
const mockExchange = {
|
|
getPosition: async () => null
|
|
} as any;
|
|
|
|
async function testThinking() {
|
|
console.log('--- 🧪 TESTING AUTO-TRADER FUZZY MATCH LOGIC ---');
|
|
|
|
// Scenario: User allows "BTC/USD" (Alpaca style)
|
|
// Signal comes in as "BTC/USDT" (Data style)
|
|
const allowedSymbols = ['BTC/USD', 'ETH/USD'];
|
|
|
|
const trader = new AutoTrader(
|
|
mockExecutor,
|
|
mockExchange,
|
|
1000, // Capital
|
|
1, // Risk %
|
|
allowedSymbols
|
|
);
|
|
|
|
const incomingSymbol = 'BTC/USDT';
|
|
|
|
console.log(`User Allowed Symbols: ${JSON.stringify(allowedSymbols)}`);
|
|
console.log(`Incoming Signal Symbol: ${incomingSymbol}`);
|
|
|
|
const mockSignal = {
|
|
ruleName: 'TestRule',
|
|
passed: true,
|
|
signal: SignalDirection.BUY,
|
|
reason: 'Test Buy Signal'
|
|
};
|
|
|
|
const mockContext = {
|
|
currentPrice: 90000,
|
|
candles1h: Array(50).fill({ high: 90100, low: 89900, close: 90000 }), // Mock for ATR
|
|
} as any;
|
|
|
|
console.log('\nInvoking handleSignal...');
|
|
await trader.handleSignal(incomingSymbol, mockSignal, mockContext);
|
|
console.log('--- Test Complete (Check above for EXECUTION TRIGGERED) ---');
|
|
}
|
|
|
|
testThinking();
|