-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_balance.sh
More file actions
executable file
·42 lines (39 loc) · 1.3 KB
/
get_balance.sh
File metadata and controls
executable file
·42 lines (39 loc) · 1.3 KB
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
#!/bin/bash
# Extract balance from the latest log line
BALANCE_FILE="/tmp/youtube_stream/balance.txt"
LOG_FILE="$HOME/.openclaw/workspace/kraken_bot/bot.log"
# Get latest balance from log
LATEST_LINE=$(tail -1 "$LOG_FILE" 2>/dev/null)
EUR_BALANCE=$(echo "$LATEST_LINE" | grep -oP 'Bal:\s*\K[0-9.]+(?=EUR)' || echo "0.00")
# Try to get token balances from kraken bot
cd "$HOME/.openclaw/workspace/kraken_bot" 2>/dev/null
if [ -f "kraken_interface.py" ]; then
# Get balances using Python
BALANCES=$(python3 << 'EOF' 2>/dev/null
import sys
sys.path.insert(0, '.')
try:
from kraken_interface import KrakenAPI
api = KrakenAPI()
balance = api.get_account_balance()
if balance:
print(f"EUR: {float(balance.get('ZEUR', 0)):.2f}")
print(f"BTC: {float(balance.get('XXBT', 0)):.6f}")
print(f"ETH: {float(balance.get('XETH', 0)):.4f}")
print(f"SOL: {float(balance.get('SOL', 0)):.2f}")
print(f"ADA: {float(balance.get('ADA', 0)):.1f}")
print(f"DOT: {float(balance.get('DOT', 0)):.2f}")
except:
pass
EOF
)
if [ ! -z "$BALANCES" ]; then
echo "$BALANCES" > "$BALANCE_FILE"
else
# Fallback to log balance
echo "EUR: $EUR_BALANCE" > "$BALANCE_FILE"
fi
else
# Fallback to log balance
echo "EUR: $EUR_BALANCE" > "$BALANCE_FILE"
fi