position history with fees
This commit is contained in:
@ -67,10 +67,28 @@ class TradingExecutor:
|
||||
api_key = os.getenv('MEXC_API_KEY', self.mexc_config.get('api_key', ''))
|
||||
api_secret = os.getenv('MEXC_SECRET_KEY', self.mexc_config.get('api_secret', ''))
|
||||
|
||||
# Determine trading mode from unified config
|
||||
trading_mode = self.mexc_config.get('trading_mode', 'simulation')
|
||||
|
||||
# Map trading mode to exchange test_mode and execution mode
|
||||
if trading_mode == 'simulation':
|
||||
exchange_test_mode = True
|
||||
self.simulation_mode = True
|
||||
elif trading_mode == 'testnet':
|
||||
exchange_test_mode = True
|
||||
self.simulation_mode = False
|
||||
elif trading_mode == 'live':
|
||||
exchange_test_mode = False
|
||||
self.simulation_mode = False
|
||||
else:
|
||||
logger.warning(f"Unknown trading_mode '{trading_mode}', defaulting to simulation")
|
||||
exchange_test_mode = True
|
||||
self.simulation_mode = True
|
||||
|
||||
self.exchange = MEXCInterface(
|
||||
api_key=api_key,
|
||||
api_secret=api_secret,
|
||||
test_mode=self.mexc_config.get('test_mode', True)
|
||||
test_mode=exchange_test_mode
|
||||
)
|
||||
|
||||
# Trading state
|
||||
@ -80,7 +98,10 @@ class TradingExecutor:
|
||||
self.daily_loss = 0.0
|
||||
self.last_trade_time = {}
|
||||
self.trading_enabled = self.mexc_config.get('enabled', False)
|
||||
self.dry_run = self.mexc_config.get('dry_run_mode', True)
|
||||
self.trading_mode = trading_mode
|
||||
|
||||
# Legacy compatibility (deprecated)
|
||||
self.dry_run = self.simulation_mode
|
||||
|
||||
# Thread safety
|
||||
self.lock = Lock()
|
||||
@ -98,7 +119,8 @@ class TradingExecutor:
|
||||
return True
|
||||
else:
|
||||
logger.error("Failed to connect to MEXC exchange")
|
||||
self.trading_enabled = False
|
||||
if not self.dry_run:
|
||||
self.trading_enabled = False
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Error connecting to MEXC exchange: {e}")
|
||||
@ -204,8 +226,8 @@ class TradingExecutor:
|
||||
logger.info(f"Executing BUY: {quantity:.6f} {symbol} at ${current_price:.2f} "
|
||||
f"(value: ${position_value:.2f}, confidence: {confidence:.2f})")
|
||||
|
||||
if self.dry_run:
|
||||
logger.info("DRY RUN MODE - Trade logged but not executed")
|
||||
if self.simulation_mode:
|
||||
logger.info(f"SIMULATION MODE ({self.trading_mode.upper()}) - Trade logged but not executed")
|
||||
# Create mock position for tracking
|
||||
self.positions[symbol] = Position(
|
||||
symbol=symbol,
|
||||
@ -213,7 +235,7 @@ class TradingExecutor:
|
||||
quantity=quantity,
|
||||
entry_price=current_price,
|
||||
entry_time=datetime.now(),
|
||||
order_id=f"dry_run_{int(time.time())}"
|
||||
order_id=f"sim_{int(time.time())}"
|
||||
)
|
||||
self.last_trade_time[symbol] = datetime.now()
|
||||
self.daily_trades += 1
|
||||
@ -264,8 +286,8 @@ class TradingExecutor:
|
||||
logger.info(f"Executing SELL: {position.quantity:.6f} {symbol} at ${current_price:.2f} "
|
||||
f"(confidence: {confidence:.2f})")
|
||||
|
||||
if self.dry_run:
|
||||
logger.info("DRY RUN MODE - Trade logged but not executed")
|
||||
if self.simulation_mode:
|
||||
logger.info(f"SIMULATION MODE ({self.trading_mode.upper()}) - Trade logged but not executed")
|
||||
# Calculate P&L
|
||||
pnl = position.calculate_pnl(current_price)
|
||||
|
||||
@ -444,4 +466,4 @@ class TradingExecutor:
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting account balance: {e}")
|
||||
return {}
|
||||
return {}
|
||||
|
Reference in New Issue
Block a user