88 lines
3.4 KiB
Python
88 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script for manual trading buttons functionality
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
import time
|
|
from datetime import datetime
|
|
|
|
def test_manual_trading():
|
|
"""Test the manual trading buttons functionality"""
|
|
print("Testing manual trading buttons...")
|
|
|
|
# Check if dashboard is running
|
|
try:
|
|
response = requests.get("http://127.0.0.1:8050", timeout=5)
|
|
if response.status_code == 200:
|
|
print("✅ Dashboard is running on port 8050")
|
|
else:
|
|
print(f"❌ Dashboard returned status code: {response.status_code}")
|
|
return
|
|
except Exception as e:
|
|
print(f"❌ Dashboard not accessible: {e}")
|
|
return
|
|
|
|
# Check if trades file exists
|
|
try:
|
|
with open('closed_trades_history.json', 'r') as f:
|
|
trades = json.load(f)
|
|
print(f"📊 Current trades in history: {len(trades)}")
|
|
if trades:
|
|
latest_trade = trades[-1]
|
|
print(f" Latest trade: {latest_trade.get('side')} at ${latest_trade.get('exit_price', latest_trade.get('entry_price'))}")
|
|
except FileNotFoundError:
|
|
print("📊 No trades history file found (this is normal for fresh start)")
|
|
except Exception as e:
|
|
print(f"❌ Error reading trades file: {e}")
|
|
|
|
print("\n🎯 Manual Trading Test Instructions:")
|
|
print("1. Open dashboard at http://127.0.0.1:8050")
|
|
print("2. Look for the 'MANUAL BUY' and 'MANUAL SELL' buttons")
|
|
print("3. Click 'MANUAL BUY' to create a test long position")
|
|
print("4. Wait a few seconds, then click 'MANUAL SELL' to close and create short")
|
|
print("5. Check the chart for green triangles showing trade entry/exit points")
|
|
print("6. Check the 'Closed Trades' table for trade records")
|
|
|
|
print("\n📈 Expected Results:")
|
|
print("- Green triangles should appear on the price chart at trade execution times")
|
|
print("- Dashed lines should connect entry and exit points")
|
|
print("- Trade records should appear in the closed trades table")
|
|
print("- Session P&L should update with trade profits/losses")
|
|
|
|
print("\n🔍 Monitoring trades file...")
|
|
initial_count = 0
|
|
try:
|
|
with open('closed_trades_history.json', 'r') as f:
|
|
initial_count = len(json.load(f))
|
|
except:
|
|
pass
|
|
|
|
print(f"Initial trade count: {initial_count}")
|
|
print("Watching for new trades... (Press Ctrl+C to stop)")
|
|
|
|
try:
|
|
while True:
|
|
time.sleep(2)
|
|
try:
|
|
with open('closed_trades_history.json', 'r') as f:
|
|
current_trades = json.load(f)
|
|
current_count = len(current_trades)
|
|
|
|
if current_count > initial_count:
|
|
new_trades = current_trades[initial_count:]
|
|
for trade in new_trades:
|
|
print(f"🆕 NEW TRADE: {trade.get('side')} | Entry: ${trade.get('entry_price'):.2f} | Exit: ${trade.get('exit_price'):.2f} | P&L: ${trade.get('net_pnl'):.2f}")
|
|
initial_count = current_count
|
|
|
|
except FileNotFoundError:
|
|
pass
|
|
except Exception as e:
|
|
print(f"Error monitoring trades: {e}")
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n✅ Test monitoring stopped")
|
|
|
|
if __name__ == "__main__":
|
|
test_manual_trading() |