79 lines
2.9 KiB
Python
79 lines
2.9 KiB
Python
import pymysql
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# DB Config
|
|
DB_HOST = 'localhost'
|
|
DB_USER = 'root'
|
|
DB_PASSWORD = '12345678'
|
|
DB_NAME = 'auto_trade_sys_new'
|
|
|
|
def connect_db():
|
|
return pymysql.connect(
|
|
host=DB_HOST,
|
|
user=DB_USER,
|
|
password=DB_PASSWORD,
|
|
database=DB_NAME,
|
|
charset='utf8mb4',
|
|
cursorclass=pymysql.cursors.DictCursor
|
|
)
|
|
|
|
def main():
|
|
try:
|
|
conn = connect_db()
|
|
cursor = conn.cursor()
|
|
|
|
print(f"Connected to {DB_NAME}")
|
|
|
|
# Check all databases
|
|
print("\n=== All Databases ===")
|
|
cursor.execute("SHOW DATABASES")
|
|
for db in cursor.fetchall():
|
|
print(db['Database'])
|
|
|
|
# 1. Check Open Positions for Account 2
|
|
print("\n=== Open Positions (Account 2) ===")
|
|
cursor.execute("""
|
|
SELECT id, symbol, side, entry_price, quantity, leverage, stop_loss_price, take_profit_price, created_at
|
|
FROM trades
|
|
WHERE status = 'open' AND account_id = 2
|
|
ORDER BY created_at DESC
|
|
""")
|
|
open_trades = cursor.fetchall()
|
|
|
|
if not open_trades:
|
|
print("No open positions found for Account 2.")
|
|
else:
|
|
for trade in open_trades:
|
|
entry_time = datetime.fromtimestamp(trade['created_at']).strftime('%Y-%m-%d %H:%M:%S')
|
|
print(f"ID: {trade['id']}, Symbol: {trade['symbol']}, Side: {trade['side']}, Entry: {trade['entry_price']}, SL: {trade['stop_loss_price']}, TP: {trade['take_profit_price']}, Time: {entry_time}")
|
|
|
|
# 2. Check Recent Closed Trades for Account 2
|
|
cursor.execute(f"SELECT id, symbol, side, status, pnl, pnl_percent, stop_loss_price, take_profit_price, entry_time, quantity, entry_price FROM trades WHERE account_id = 2 ORDER BY id DESC LIMIT 10")
|
|
trades = cursor.fetchall()
|
|
print(f"Account 2 recent trades:")
|
|
for t in trades:
|
|
# Handle entry_time conversion if it's a timestamp or datetime
|
|
entry_time = t.get('entry_time')
|
|
print(f"ID: {t['id']}, Symbol: {t['symbol']}, Side: {t['side']}, Status: {t['status']}, PnL: {t['pnl']}, PnL%: {t['pnl_percent']}, SL: {t['stop_loss_price']}, TP: {t['take_profit_price']}, Time: {entry_time}, Qty: {t['quantity']}, Price: {t['entry_price']}")
|
|
|
|
# 3. Check for the specific "All take profits" claim
|
|
print("\n=== Checking for Negative PnL with Take Profit Reason ===")
|
|
cursor.execute("""
|
|
SELECT COUNT(*) as count
|
|
FROM trades
|
|
WHERE status != 'open'
|
|
AND exit_reason = 'take_profit'
|
|
AND pnl < 0
|
|
""")
|
|
count = cursor.fetchone()['count']
|
|
print(f"Number of 'take_profit' trades with negative PnL: {count}")
|
|
|
|
conn.close()
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|