95 lines
3.4 KiB
Python
95 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify enhanced fee tracking with maker/taker fees
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
import logging
|
|
from datetime import datetime, timezone
|
|
from web.dashboard import TradingDashboard
|
|
from core.data_provider import DataProvider
|
|
|
|
# Setup logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def test_enhanced_fee_tracking():
|
|
"""Test enhanced fee tracking with maker/taker fees"""
|
|
|
|
logger.info("Testing enhanced fee tracking...")
|
|
|
|
# Create dashboard instance
|
|
data_provider = DataProvider()
|
|
dashboard = TradingDashboard(data_provider=data_provider)
|
|
|
|
# Create test trading decisions with different fee types
|
|
test_decisions = [
|
|
{
|
|
'action': 'BUY',
|
|
'symbol': 'ETH/USDT',
|
|
'price': 3500.0,
|
|
'confidence': 0.8,
|
|
'timestamp': datetime.now(timezone.utc),
|
|
'order_type': 'market', # Should use taker fee
|
|
'filled_as_maker': False
|
|
},
|
|
{
|
|
'action': 'SELL',
|
|
'symbol': 'ETH/USDT',
|
|
'price': 3520.0,
|
|
'confidence': 0.9,
|
|
'timestamp': datetime.now(timezone.utc),
|
|
'order_type': 'limit', # Should use maker fee if filled as maker
|
|
'filled_as_maker': True
|
|
}
|
|
]
|
|
|
|
# Process the trading decisions
|
|
for i, decision in enumerate(test_decisions):
|
|
logger.info(f"Processing decision {i+1}: {decision['action']} @ ${decision['price']}")
|
|
dashboard._process_trading_decision(decision)
|
|
|
|
# Check session trades
|
|
if dashboard.session_trades:
|
|
latest_trade = dashboard.session_trades[-1]
|
|
fee_type = latest_trade.get('fee_type', 'unknown')
|
|
fee_rate = latest_trade.get('fee_rate', 0)
|
|
fees = latest_trade.get('fees', 0)
|
|
|
|
logger.info(f" Trade recorded: {latest_trade.get('position_action', 'unknown')}")
|
|
logger.info(f" Fee Type: {fee_type}")
|
|
logger.info(f" Fee Rate: {fee_rate*100:.3f}%")
|
|
logger.info(f" Fee Amount: ${fees:.4f}")
|
|
|
|
# Check closed trades
|
|
if dashboard.closed_trades:
|
|
logger.info(f"\nClosed trades: {len(dashboard.closed_trades)}")
|
|
for trade in dashboard.closed_trades:
|
|
logger.info(f" Trade #{trade['trade_id']}: {trade['side']}")
|
|
logger.info(f" Fee Type: {trade.get('fee_type', 'unknown')}")
|
|
logger.info(f" Fee Rate: {trade.get('fee_rate', 0)*100:.3f}%")
|
|
logger.info(f" Total Fees: ${trade.get('fees', 0):.4f}")
|
|
logger.info(f" Net P&L: ${trade.get('net_pnl', 0):.2f}")
|
|
|
|
# Test session performance with fee breakdown
|
|
logger.info("\nTesting session performance display...")
|
|
performance = dashboard._create_session_performance()
|
|
logger.info(f"Session performance components: {len(performance)}")
|
|
|
|
# Test closed trades table
|
|
logger.info("\nTesting enhanced trades table...")
|
|
table_components = dashboard._create_closed_trades_table()
|
|
logger.info(f"Table components: {len(table_components)}")
|
|
|
|
logger.info("Enhanced fee tracking test completed!")
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
test_enhanced_fee_tracking() |