import { config } from '../src/config/index.js';
import { AlpacaConnector } from '../src/connectors/alpaca.js';
import { TradeExecutor } from '../src/services/TradeExecutor.js';
import logger from '../src/utils/logger.js';

async function testLogging() {
    logger.info('--- Starting Order Logging Verification ---');

    const exchange = new AlpacaConnector(config.ALPACA_API_KEY, config.ALPACA_API_SECRET);
    const executor = new TradeExecutor(exchange, undefined, 'test-user');

    const symbol = 'BTC/USDT';

    // 1. Test Open
    logger.info('[Test] Opening Position...');
    const openRes = await executor.openPosition(symbol, 'BUY' as any, 0.001, 'market');

    if (openRes.success) {
        logger.info('✅ Open logged.');

        // 2. Test Close
        logger.info('[Test] Closing Position...');
        const closeRes = await executor.closePosition(symbol, 'Verification Test');

        if (closeRes.success) {
            logger.info('✅ Close logged.');
            logger.info('--- Verification Complete ---');
            logger.info('Please check the logs to see if two "Logged order to DB" messages appeared.');
        } else {
            logger.error('❌ Close failed:', closeRes.error);
        }
    } else {
        logger.error('❌ Open failed:', openRes.error);
    }
}

testLogging().catch(console.error);
