@echo off
chcp 65001 >nul
title Gold AutoTrade
cd /d "%~dp0"

set "GAT_VERSION=unknown"
if exist "VERSION" (
    for /f "usebackq delims=" %%v in ("VERSION") do set "GAT_VERSION=%%v"
)

echo.
echo   Gold AutoTrade %GAT_VERSION%

REM Prevent duplicate launch — check if engine is already running
tasklist /FI "IMAGENAME eq GoldAutoTradeEngine.exe" 2>NUL | find /I "GoldAutoTradeEngine.exe" >NUL
if %ERRORLEVEL% == 0 (
    echo   Gold AutoTrade is already running.
    echo   If the dashboard doesn't appear, open http://127.0.0.1:18790
    pause
    exit /b 0
)

echo   Starting engine...
echo.

if exist "GoldAutoTradeEngine.exe" (
    start "" "GoldAutoTradeEngine.exe"
    echo   Engine started. Dashboard will open in your browser.
) else (
    echo   [ERROR] GoldAutoTradeEngine.exe not found.
    echo   Please reinstall the application.
    pause
)
