File size: 1,484 Bytes
da0ce7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from aureon_baton_link import link_system as _baton_link; _baton_link(__name__)
import os
from binance_client import BinanceClient
from dotenv import load_dotenv

load_dotenv()

client = get_binance_client()

def check_balances():
    account = client.account()
    print("Balances:")
    for b in account['balances']:
        if float(b['free']) > 0:
            symbol = b['asset']
            qty = float(b['free'])
            try:
                if symbol == 'USDT':
                    price = 1.0
                elif symbol == 'LDUSDC':
                    price = 1.0
                else:
                    ticker = client.session.get(f"{client.base}/api/v3/ticker/price", params={'symbol': f"{symbol}USDT"}).json()
                    if 'price' in ticker:
                        price = float(ticker['price'])
                    else:
                        price = 0.0
                val = qty * price
                if val > 1.0: # Only show > $1
                    print(f"{symbol}: {qty} (~${val:.2f})")
            except:
                print(f"{symbol}: {qty} (Price unknown)")

def test_price(symbol):
    try:
        ticker = client.session.get(f"{client.base}/api/v3/ticker/price", params={'symbol': f"{symbol}USDT"}).json()
        print(f"Price of {symbol}USDT: {ticker}")
    except Exception as e:
        print(f"Error fetching {symbol}USDT: {e}")

check_balances()
test_price('DOGE')
test_price('XRP')