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

async function verifySync() {
    logger.info('--- Starting Sync Verification ---');

    // 1. Setup Connector
    const exchange = new AlpacaConnector(config.ALPACA_API_KEY, config.ALPACA_API_SECRET);

    // 2. Test Symbol
    const inputSymbol = 'BTC/USDT';
    const tradeSymbol = SymbolMapper.toTradeSymbol(inputSymbol, 'alpaca');
    logger.info(`Mapped ${inputSymbol} -> ${tradeSymbol}`);

    // 3. Fetch Position (Test 1: Mapped)
    try {
        const position = await exchange.getPosition(tradeSymbol);
        if (position) {
            logger.info(`✅ Position Found for ${tradeSymbol}:`, position);
        } else {
            logger.warn(`⚠️ No Position Found for ${tradeSymbol}`);
        }
    } catch (error) {
        logger.error(`❌ API Error for ${tradeSymbol}:`, error);
    }

    // 4. Fetch Position (Test 2: Raw/No Slash)
    const rawSymbol = 'BTCUSD';
    try {
        const position = await exchange.getPosition(rawSymbol);
        if (position) {
            logger.info(`✅ Position Found for ${rawSymbol}:`, position);
        } else {
            logger.warn(`⚠️ No Position Found for ${rawSymbol}`);
        }
    } catch (error) {
        logger.error(`❌ API Error for ${rawSymbol}:`, error);
    }
}

verifySync().catch(console.error);
