-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus
More file actions
executable file
·54 lines (47 loc) · 1.4 KB
/
status
File metadata and controls
executable file
·54 lines (47 loc) · 1.4 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
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
set -euo pipefail
source .venv/bin/activate
echo "📅 $(date +"%d.%m.%Y, %H:%M %Z")"
echo "💱 Текущие цены:"
python3 - <<'PY'
import ccxt, json, sys
from datetime import datetime
from zoneinfo import ZoneInfo
def fmt_price(p: float) -> str:
if p >= 1: return f"{p:.2f}"
if p >= 0.1: return f"{p:.4f}"
if p >= 0.001: return f"{p:.6f}"
return f"{p:.8f}"
bybit = ccxt.bybit()
binance = ccxt.binance()
with open("pool.json","r",encoding="utf-8") as f:
pool = json.load(f)["pool"]
for sym in pool:
price = None
# 1) пытаемся взять last с Bybit
try:
t = bybit.fetch_ticker(sym)
price = t.get("last")
if price is None:
bid, ask = t.get("bid"), t.get("ask")
if bid and ask:
price = (bid + ask) / 2
except Exception:
pass
# 2) если не получилось — фолбэк на Binance
if price is None:
try:
t = binance.fetch_ticker(sym)
price = t.get("last")
if price is None:
bid, ask = t.get("bid"), t.get("ask")
if bid and ask:
price = (bid + ask) / 2
except Exception:
pass
base = sym.split('/')[0]
if price is None:
print(f"{base:<5}= error")
else:
print(f"{base:<5}= {fmt_price(float(price)):>12} USDT")
PY