Spaces:
Running
Running
Deploy Aureon OS (deploy/selfhost stack: nginx edge + fusion API x2 + console + HNC organ + redis + postgres; paper mode) (part 19)
da0ce7b verified Download scripts/diagnostics/debug_crypto_history.py from GaryLeckey/aureon-os: direct link, hf CLI and curl.
- Browser
- Download file 6.27 kB
-
https://huggingface.co/spaces/GaryLeckey/aureon-os/resolve/main/scripts/diagnostics/debug_crypto_history.py
- Command line
-
hf download hf://spaces/GaryLeckey/aureon-os/scripts/diagnostics/debug_crypto_history.py
-
curl -L -o debug_crypto_history.py https://huggingface.co/spaces/GaryLeckey/aureon-os/resolve/main/scripts/diagnostics/debug_crypto_history.py
6.27 kB
| import os | |
| import sys | |
| import json | |
| import time | |
| from dotenv import load_dotenv | |
| # Load environment variables | |
| load_dotenv() | |
| # Add current directory to path | |
| sys.path.append(os.getcwd()) | |
| from binance_client import BinanceClient | |
| from kraken_client import KrakenClient | |
| def debug_binance(): | |
| print("\n" + "="*50) | |
| print("π DIAGNOSTIC: BINANCE") | |
| print("="*50) | |
| api_key = os.getenv("BINANCE_API_KEY") | |
| api_secret = os.getenv("BINANCE_SECRET_KEY") | |
| if not api_key: | |
| print("β Missing BINANCE_API_KEY") | |
| return | |
| # FIXED: No args for init (loads from env) | |
| client = get_binance_client() | |
| # Check Connectivity | |
| try: | |
| status = client.get_system_status() | |
| print(f"β System Status: {status.get('msg', 'OK')}") | |
| except Exception as e: | |
| print(f"β Connection Failed: {e}") | |
| return | |
| # Check Balances | |
| try: | |
| account = client.account() | |
| balances = [b for b in account.get("balances", []) if float(b.get("free", 0)) > 0 or float(b.get("locked", 0)) > 0] | |
| if not balances: | |
| print("β οΈ No non-zero balances found.") | |
| else: | |
| print(f"π° Found {len(balances)} assets with balance:") | |
| for b in balances: | |
| asset = b['asset'] | |
| amount = float(b['free']) + float(b['locked']) | |
| print(f" - {asset}: {amount}") | |
| # Try to find trades for this asset | |
| quotes = ['USDT', 'USDC', 'GBP', 'EUR', 'BTC', 'ETH', 'FDUSD'] | |
| found_trades = False | |
| for quote in quotes: | |
| if asset == quote: continue | |
| symbol = f"{asset}{quote}" | |
| try: | |
| trades = client.get_my_trades(symbol, limit=5) | |
| orders = client.get_all_orders(symbol, limit=5, silent=True) | |
| if trades: | |
| print(f" β Found {len(trades)} trades for {symbol}") | |
| print(f" Sample Trade: {trades[0]}") | |
| found_trades = True | |
| if orders: | |
| print(f" β Found {len(orders)} orders for {symbol}") | |
| filled_orders = [o for o in orders if o['status'] == 'FILLED'] | |
| print(f" Filled: {len(filled_orders)}") | |
| if filled_orders: | |
| print(f" Sample Order: {filled_orders[0]}") | |
| found_trades = True | |
| # Calculate cost basis from Orders if possible | |
| if filled_orders: | |
| total_qty = 0.0 | |
| total_cost = 0.0 | |
| for o in filled_orders: | |
| if o['side'] == 'BUY': | |
| qty = float(o['executedQty']) | |
| cost = float(o['cummulativeQuoteQty']) | |
| total_qty += qty | |
| total_cost += cost | |
| if total_qty > 0: | |
| print(f" Derived Avg Buy Price: {total_cost/total_qty}") | |
| if not trades and not orders: | |
| # print(f" . No trades for {symbol}") | |
| pass | |
| except Exception as e: | |
| print(f" x Error checking {symbol}: {str(e)}") | |
| pass | |
| if not found_trades: | |
| print(f" β οΈ No trades found for {asset} with standard pairs.") | |
| except Exception as e: | |
| print(f"β Account/Trade fetch failed: {e}") | |
| def debug_kraken(): | |
| print("\n" + "="*50) | |
| print("π DIAGNOSTIC: KRAKEN") | |
| print("="*50) | |
| api_key = os.getenv("KRAKEN_API_KEY") | |
| api_secret = os.getenv("KRAKEN_PRIVATE_KEY") | |
| if not api_key: | |
| print("β Missing KRAKEN_API_KEY") | |
| return | |
| client = KrakenClient(api_key, api_secret) | |
| # Check Balances | |
| try: | |
| balance = client.get_account_balance() | |
| if not balance: | |
| print("β οΈ No balances returned.") | |
| else: | |
| print(f"π° Balances: {balance}") | |
| print("\n--- Checking History Sources ---") | |
| # 1. Check Trades History | |
| print("1οΈβ£ Checking 'TradesHistory' endpoint...") | |
| trades = client.get_trades_history() | |
| if trades: | |
| count = len(trades) | |
| print(f" β Found {count} historical trades.") | |
| first_key = list(trades.keys())[0] | |
| print(f" Sample Key: {first_key}") | |
| print(f" Sample Data: {trades[first_key]}") | |
| # Check Pairs in history | |
| pairs = set(t.get('pair') for t in trades.values()) | |
| print(f" Pairs found in history: {pairs}") | |
| else: | |
| print(" β οΈ TradesHistory returned empty/None.") | |
| # 2. Check Ledgers (User suggestion) | |
| print("\n2οΈβ£ Checking 'Ledgers' endpoint...") | |
| ledgers = client.get_ledgers() | |
| if ledgers: | |
| count = len(ledgers) | |
| print(f" β Found {count} ledger entries.") | |
| first_key = list(ledgers.keys())[0] | |
| print(f" Sample Key: {first_key}") | |
| print(f" Sample Data: {ledgers[first_key]}") | |
| # types in ledger | |
| types = set(l.get('type') for l in ledgers.values()) | |
| print(f" Ledger Types found: {types}") | |
| else: | |
| print(" β οΈ Ledgers returned empty/None.") | |
| except Exception as e: | |
| print(f"β Kraken Diagnostics failed: {e}") | |
| if __name__ == "__main__": | |
| debug_binance() | |
| debug_kraken() | |