This commit is contained in:
Dobromir Popov 2025-03-10 10:42:48 +02:00
parent 9b6d3f94ed
commit 4be322622e
3 changed files with 82 additions and 62 deletions

View File

@ -875,13 +875,16 @@ async def main():
parser.add_argument('--demo', action='store_true', help='Run in demo mode (no real trading)') parser.add_argument('--demo', action='store_true', help='Run in demo mode (no real trading)')
args = parser.parse_args() args = parser.parse_args()
# Initialize exchange # Initialize exchange with async support
exchange = ccxt.mexc({ exchange_id = 'mexc'
exchange_class = getattr(ccxt.async_support, exchange_id)
exchange = exchange_class({
'apiKey': MEXC_API_KEY, 'apiKey': MEXC_API_KEY,
'secret': MEXC_SECRET_KEY, 'secret': MEXC_SECRET_KEY,
'enableRateLimit': True, 'enableRateLimit': True,
}) })
try:
# Create environment # Create environment
env = TradingEnvironment( env = TradingEnvironment(
exchange=exchange, exchange=exchange,
@ -889,7 +892,7 @@ async def main():
timeframe="1m", timeframe="1m",
leverage=MAX_LEVERAGE, leverage=MAX_LEVERAGE,
initial_balance=INITIAL_BALANCE, initial_balance=INITIAL_BALANCE,
is_demo=args.demo or args.mode != 'live' # Only trade for real in live mode is_demo=args.demo or args.mode != 'live'
) )
# Fetch initial data # Fetch initial data
@ -946,6 +949,10 @@ async def main():
logger.info(f"Balance: ${env.balance:.2f} | Trades: {len(env.trades)} | " logger.info(f"Balance: ${env.balance:.2f} | Trades: {len(env.trades)} | "
f"Win Rate: {win_rate:.1f}% | Total PnL: ${total_pnl:.2f}") f"Win Rate: {win_rate:.1f}% | Total PnL: ${total_pnl:.2f}")
finally:
# Clean up exchange connection
await exchange.close()
if __name__ == "__main__": if __name__ == "__main__":
try: try:
asyncio.run(main()) asyncio.run(main())

View File

@ -66,12 +66,21 @@ python main.py --mode eval --episodes 10
### Live Trading Mode ### Live Trading Mode
```bash ```bash
# Demo mode (no real trades) # Demo mode (simulated trading with real market data)
python main.py --mode live --demo python main.py --mode live --demo
# Real trading
# Real trading (actual trades on MEXC)
python main.py --mode live python main.py --mode live
``` ```
Demo mode simulates trading using real-time market data but does not execute actual trades. It still:
- Logs all trading decisions and performance metrics
- Updates the model based on market data (if in training mode)
- Displays real-time analytics and position information
- Calculates theoretical profits/losses
- Saves performance data to TensorBoard
This makes it perfect for testing strategies without financial risk.
## Configuration ## Configuration

View File

@ -0,0 +1,4 @@
2025-03-10 10:31:19,097 - INFO - Fetching initial 60 candles for ETH/USDT...
2025-03-10 10:31:24,545 - ERROR - Error fetching initial data: object list can't be used in 'await' expression
2025-03-10 10:38:32,233 - INFO - Fetching initial 60 candles for ETH/USDT...
2025-03-10 10:38:38,055 - ERROR - Error fetching initial data: object list can't be used in 'await' expression