94 lines
3.4 KiB
Python
94 lines
3.4 KiB
Python
import asyncio
|
|
import sys
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# Add path
|
|
sys.path.insert(0, '/Users/vivian/work/python/auto_trade_sys')
|
|
sys.path.insert(0, '/Users/vivian/work/python/auto_trade_sys/backend')
|
|
|
|
from trading_system.binance_client import BinanceClient
|
|
from config_manager import ConfigManager
|
|
|
|
async def check_account(account_id):
|
|
print(f"\n{'='*20} Checking Account {account_id} {'='*20}")
|
|
try:
|
|
# Initialize ConfigManager for this account
|
|
config_manager = ConfigManager(account_id=account_id)
|
|
api_key = config_manager.get('BINANCE_API_KEY')
|
|
api_secret = config_manager.get('BINANCE_API_SECRET')
|
|
|
|
if not api_key or not api_secret:
|
|
print(f"Skipping Account {account_id}: Missing API keys")
|
|
return
|
|
|
|
# Initialize client with specific keys
|
|
client = BinanceClient(api_key=api_key, api_secret=api_secret)
|
|
# Connect
|
|
await client.connect()
|
|
|
|
# Get account information
|
|
# Access the underlying AsyncClient
|
|
if not client.client:
|
|
print(f"Failed to connect to Binance for Account {account_id}")
|
|
return
|
|
|
|
# Check positions
|
|
print("=== Current Positions ===")
|
|
positions = await client.client.futures_position_information()
|
|
|
|
has_positions = False
|
|
for pos in positions:
|
|
symbol = pos['symbol']
|
|
amt = float(pos['positionAmt'])
|
|
if amt != 0:
|
|
has_positions = True
|
|
entry_price = float(pos['entryPrice'])
|
|
mark_price = float(pos['markPrice'])
|
|
unrealized_profit = float(pos['unRealizedProfit'])
|
|
|
|
# Calculate percentage
|
|
if entry_price > 0:
|
|
if amt > 0:
|
|
pnl_pct = (mark_price - entry_price) / entry_price * 100
|
|
else:
|
|
pnl_pct = (entry_price - mark_price) / entry_price * 100
|
|
else:
|
|
pnl_pct = 0
|
|
|
|
print(f"Symbol: {symbol}")
|
|
print(f" Amount: {amt}")
|
|
print(f" Entry Price: {entry_price}")
|
|
print(f" Mark Price: {mark_price}")
|
|
print(f" Unrealized PnL: {unrealized_profit:.2f} USDT ({pnl_pct:.2f}%)")
|
|
print("-" * 30)
|
|
|
|
if not has_positions:
|
|
print("No open positions.")
|
|
|
|
# Check open orders
|
|
print("\n=== Open Orders (for active positions) ===")
|
|
if has_positions:
|
|
for pos in positions:
|
|
if float(pos['positionAmt']) != 0:
|
|
symbol = pos['symbol']
|
|
orders = await client.get_open_orders(symbol)
|
|
if orders:
|
|
print(f"Orders for {symbol}:")
|
|
for order in orders:
|
|
print(f" Type: {order['type']}, Side: {order['side']}, Price: {order['price']}, StopPrice: {order.get('stopPrice', 'N/A')}")
|
|
else:
|
|
print(f"No open orders for {symbol}")
|
|
|
|
await client.close()
|
|
|
|
except Exception as e:
|
|
print(f"Error checking Account {account_id}: {e}")
|
|
|
|
async def main():
|
|
for account_id in [1, 2, 3, 4]:
|
|
await check_account(account_id)
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|