Spaces:
Paused
Paused
zt p commited on
Commit ·
0f0aa8f
1
Parent(s): 6ffa41d
新增 Bitget/OKX 交易所: 跨所差价提醒(TON/GRAM,BTC)、Bitget STRC 股票异动(休市跳过)、OKX GRAM 合约资金费率/持仓量监控; 凭证经环境变量读取
Browse files- README.md +11 -0
- coinpush.py +495 -0
README.md
CHANGED
|
@@ -27,3 +27,14 @@ pinned: false
|
|
| 27 |
- `WEWORK_BOT_WEBHOOK`(必填):企业微信机器人 Webhook
|
| 28 |
- `BINANCE_API_KEY` / `BINANCE_API_SECRET`(可选,公开行情无需)
|
| 29 |
- `BINANCE_SPOT_BASE` / `BINANCE_FAPI_BASE` / `BINANCE_FSTREAM_BASE`(可选,换镜像用)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
- `WEWORK_BOT_WEBHOOK`(必填):企业微信机器人 Webhook
|
| 28 |
- `BINANCE_API_KEY` / `BINANCE_API_SECRET`(可选,公开行情无需)
|
| 29 |
- `BINANCE_SPOT_BASE` / `BINANCE_FAPI_BASE` / `BINANCE_FSTREAM_BASE`(可选,换镜像用)
|
| 30 |
+
- `ENABLE_FUTURES`(可选,默认 false):币安合约/强平监控总开关(US 区域受限)
|
| 31 |
+
- `BITGET_API_KEY` / `BITGET_API_SECRET` / `BITGET_API_PASSPHRASE`(Bitget 行情/STRC 股票)
|
| 32 |
+
- `OKX_API_KEY` / `OKX_API_SECRET` / `OKX_API_PASSPHRASE`(OKX 行情/GRAM 合约)
|
| 33 |
+
- `BITGET_BASE` / `OKX_BASE`(可选,受限区域可指向可用代理)
|
| 34 |
+
|
| 35 |
+
## 多交易所扩展
|
| 36 |
+
- 跨所差价提醒:BTC、TON/GRAM 在 Binance / Bitget / OKX 之间的价差(Binance 仍叫 TON,Bitget/OKX 已改名 GRAM)。
|
| 37 |
+
- Bitget STRC 股票代币(rToken `RSTRCUSDT`)价格异动;休市价格不变时自动跳过。
|
| 38 |
+
- OKX GRAM 永续合约关键信息:合约价异动、资金费率、持仓量变化。
|
| 39 |
+
- 以上均可在页面「多交易所设置」开关与调参。Bitget/OKX 对部分地区有访问限制,
|
| 40 |
+
若 Space 处于受限区域,需通过 `BITGET_BASE` / `OKX_BASE` 指向可用代理。
|
coinpush.py
CHANGED
|
@@ -7,6 +7,7 @@ import copy
|
|
| 7 |
import threading
|
| 8 |
import hmac
|
| 9 |
import hashlib
|
|
|
|
| 10 |
import urllib3
|
| 11 |
from datetime import datetime, timedelta, timezone, time as dt_time
|
| 12 |
from collections import deque, defaultdict
|
|
@@ -42,6 +43,17 @@ SPOT_BASE = os.getenv("BINANCE_SPOT_BASE", "https://api.binance.com")
|
|
| 42 |
FAPI_BASE = os.getenv("BINANCE_FAPI_BASE", "https://fapi.binance.com")
|
| 43 |
FSTREAM_BASE = os.getenv("BINANCE_FSTREAM_BASE", "wss://fstream.binance.com/ws")
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
# 合约功能全局开关(默认关闭)。币安合约接口/强平流对 US 区域返回 451,
|
| 46 |
# 而 HuggingFace Space 运行在 US。此开关优先级高于每个币种的 enable_futures:
|
| 47 |
# 关闭时一律不调用 /fapi 与强平 websocket,避免 451 刷屏。
|
|
@@ -159,6 +171,39 @@ DEFAULT_CONFIG = {
|
|
| 159 |
"auto_calibrate_hours": 24,
|
| 160 |
"last_calibrate_ts": 0,
|
| 161 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
# 各类告警冷却时间(分钟),避免重复刷屏
|
|
@@ -169,6 +214,8 @@ COOLDOWN_MIN = {
|
|
| 169 |
"big_trade": 15, "cum_trade": 20, "spread": 30, "imbalance": 30,
|
| 170 |
"wall": 90, "wall_vanish": 30, "ma_deviation": 30,
|
| 171 |
"consecutive": 60, "rsi": 60, "funding": 120, "oi": 30, "liquidation": 10,
|
|
|
|
|
|
|
| 172 |
}
|
| 173 |
|
| 174 |
|
|
@@ -201,6 +248,8 @@ def load_config():
|
|
| 201 |
merged_coins[name] = _deep_merge(template, coin_cfg)
|
| 202 |
if merged_coins:
|
| 203 |
cfg["coins"] = merged_coins
|
|
|
|
|
|
|
| 204 |
except Exception as e:
|
| 205 |
print(f"⚠️ 配置读取失败,使用默认值: {e}")
|
| 206 |
return cfg
|
|
@@ -365,6 +414,161 @@ class BinanceAPI:
|
|
| 365 |
return self._get(FAPI_BASE, "/fapi/v1/openInterest", {"symbol": symbol})
|
| 366 |
|
| 367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
# --- 7. 实时强平监控(websocket,可选)---
|
| 369 |
class LiquidationTracker:
|
| 370 |
"""
|
|
@@ -1033,6 +1237,202 @@ class CoinEvaluator:
|
|
| 1033 |
return None
|
| 1034 |
|
| 1035 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1036 |
# --- 10. 监控主逻辑 ---
|
| 1037 |
class CryptoMonitor:
|
| 1038 |
def __init__(self):
|
|
@@ -1049,10 +1449,17 @@ class CryptoMonitor:
|
|
| 1049 |
self._auto_calibrate_needed = not os.path.exists(CONFIG_FILE)
|
| 1050 |
|
| 1051 |
self.api = BinanceAPI(self.log)
|
|
|
|
|
|
|
| 1052 |
self.pusher = WeWorkBotPusher(WEWORK_BOT_WEBHOOK)
|
| 1053 |
self.alert_mgr = AlertManager(self.pusher, self.log, self.stats)
|
| 1054 |
self.liq = LiquidationTracker(self._futures_symbols(), self.log)
|
| 1055 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1056 |
self.evaluators = {}
|
| 1057 |
self._rebuild_evaluators()
|
| 1058 |
|
|
@@ -1200,6 +1607,18 @@ class CryptoMonitor:
|
|
| 1200 |
except Exception as e:
|
| 1201 |
self.log(f"❌ {name} 评估异常: {e}")
|
| 1202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1203 |
if total_alerts:
|
| 1204 |
self.alert_mgr.emit(total_alerts)
|
| 1205 |
|
|
@@ -1313,6 +1732,82 @@ def render_config_editor(monitor):
|
|
| 1313 |
else:
|
| 1314 |
st.caption("自定义模式:阈值以下方各币种设置为准,不会被自动覆盖。")
|
| 1315 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1316 |
coin_names = list(cfg["coins"].keys())
|
| 1317 |
tabs = st.tabs(coin_names + ["➕ 新增币种"])
|
| 1318 |
|
|
|
|
| 7 |
import threading
|
| 8 |
import hmac
|
| 9 |
import hashlib
|
| 10 |
+
import base64
|
| 11 |
import urllib3
|
| 12 |
from datetime import datetime, timedelta, timezone, time as dt_time
|
| 13 |
from collections import deque, defaultdict
|
|
|
|
| 43 |
FAPI_BASE = os.getenv("BINANCE_FAPI_BASE", "https://fapi.binance.com")
|
| 44 |
FSTREAM_BASE = os.getenv("BINANCE_FSTREAM_BASE", "wss://fstream.binance.com/ws")
|
| 45 |
|
| 46 |
+
# --- Bitget / OKX 凭证与基址(全部从环境变量读取,切勿硬编码)---
|
| 47 |
+
BITGET_API_KEY = os.getenv("BITGET_API_KEY")
|
| 48 |
+
BITGET_API_SECRET = os.getenv("BITGET_API_SECRET")
|
| 49 |
+
BITGET_API_PASSPHRASE = os.getenv("BITGET_API_PASSPHRASE")
|
| 50 |
+
BITGET_BASE = os.getenv("BITGET_BASE", "https://api.bitget.com")
|
| 51 |
+
|
| 52 |
+
OKX_API_KEY = os.getenv("OKX_API_KEY")
|
| 53 |
+
OKX_API_SECRET = os.getenv("OKX_API_SECRET")
|
| 54 |
+
OKX_API_PASSPHRASE = os.getenv("OKX_API_PASSPHRASE")
|
| 55 |
+
OKX_BASE = os.getenv("OKX_BASE", "https://www.okx.com")
|
| 56 |
+
|
| 57 |
# 合约功能全局开关(默认关闭)。币安合约接口/强平流对 US 区域返回 451,
|
| 58 |
# 而 HuggingFace Space 运行在 US。此开关优先级高于每个币种的 enable_futures:
|
| 59 |
# 关闭时一律不调用 /fapi 与强平 websocket,避免 451 刷屏。
|
|
|
|
| 171 |
"auto_calibrate_hours": 24,
|
| 172 |
"last_calibrate_ts": 0,
|
| 173 |
},
|
| 174 |
+
# 多交易所扩展:跨所差价、Bitget STRC 股票、OKX GRAM 合约
|
| 175 |
+
"exchanges": {
|
| 176 |
+
"enable_bitget": True,
|
| 177 |
+
"enable_okx": True,
|
| 178 |
+
# 跨交易所差价提醒(同一资产在不同所的价差)
|
| 179 |
+
"spread": {
|
| 180 |
+
"enable": True,
|
| 181 |
+
"threshold_pct": 0.5, # 任意两所价差超过该百分比即提醒
|
| 182 |
+
"pairs": [
|
| 183 |
+
# Binance 仍叫 TON,Bitget/OKX 已改名 GRAM
|
| 184 |
+
{"name": "BTC", "binance": "BTCUSDT", "bitget": "BTCUSDT", "okx": "BTC-USDT"},
|
| 185 |
+
{"name": "TON/GRAM", "binance": "TONUSDT", "bitget": "GRAMUSDT", "okx": "GRAM-USDT"},
|
| 186 |
+
],
|
| 187 |
+
},
|
| 188 |
+
# Bitget STRC 股票代币(rToken),休市价格不变时不提醒
|
| 189 |
+
"strc": {
|
| 190 |
+
"enable": True,
|
| 191 |
+
"symbol": "RSTRCUSDT",
|
| 192 |
+
"change_pct": 1.0, # 短时异动阈值 %
|
| 193 |
+
"amp_24h_pct": 3.0, # 24h 振幅提醒 %
|
| 194 |
+
"skip_when_static": True, # 价格长时间不变(休市)则跳过
|
| 195 |
+
"static_secs": 600, # 多久不变判定为休市
|
| 196 |
+
},
|
| 197 |
+
# OKX GRAM 永续合约关键信息
|
| 198 |
+
"okx_gram_swap": {
|
| 199 |
+
"enable": True,
|
| 200 |
+
"inst_id": "GRAM-USDT-SWAP",
|
| 201 |
+
"funding_high": 0.05, # 资金费率绝对值高位 %
|
| 202 |
+
"funding_neg": -0.05,
|
| 203 |
+
"oi_change_pct": 5.0, # 持仓量较上次变动 %
|
| 204 |
+
"price_change_pct": 2.0, # 合约价短时异动 %
|
| 205 |
+
},
|
| 206 |
+
},
|
| 207 |
}
|
| 208 |
|
| 209 |
# 各类告警冷却时间(分钟),避免重复刷屏
|
|
|
|
| 214 |
"big_trade": 15, "cum_trade": 20, "spread": 30, "imbalance": 30,
|
| 215 |
"wall": 90, "wall_vanish": 30, "ma_deviation": 30,
|
| 216 |
"consecutive": 60, "rsi": 60, "funding": 120, "oi": 30, "liquidation": 10,
|
| 217 |
+
# 跨交易所差价 / STRC 股票异动 / OKX GRAM 合约
|
| 218 |
+
"spread_ex": 20, "strc": 15, "okx_funding": 120, "okx_oi": 30, "okx_price": 10,
|
| 219 |
}
|
| 220 |
|
| 221 |
|
|
|
|
| 248 |
merged_coins[name] = _deep_merge(template, coin_cfg)
|
| 249 |
if merged_coins:
|
| 250 |
cfg["coins"] = merged_coins
|
| 251 |
+
# exchanges:跨所/STRC/OKX 合约配置,缺失字段以默认补全
|
| 252 |
+
cfg["exchanges"] = _deep_merge(cfg["exchanges"], saved.get("exchanges", {}))
|
| 253 |
except Exception as e:
|
| 254 |
print(f"⚠️ 配置读取失败,使用默认值: {e}")
|
| 255 |
return cfg
|
|
|
|
| 414 |
return self._get(FAPI_BASE, "/fapi/v1/openInterest", {"symbol": symbol})
|
| 415 |
|
| 416 |
|
| 417 |
+
# --- 6b. Bitget 行情接口(现货 + STRC 股票代币)---
|
| 418 |
+
class BitgetAPI:
|
| 419 |
+
"""Bitget 公共行情接口。市场数据无需密钥;密钥用于私有接口与提高限频。"""
|
| 420 |
+
|
| 421 |
+
def __init__(self, logger):
|
| 422 |
+
self.logger = logger
|
| 423 |
+
self.session = requests.Session()
|
| 424 |
+
self.session.headers.update(REQ_HEADERS)
|
| 425 |
+
|
| 426 |
+
def _sign(self, ts, method, path, body=""):
|
| 427 |
+
msg = f"{ts}{method.upper()}{path}{body}"
|
| 428 |
+
mac = hmac.new(BITGET_API_SECRET.encode(), msg.encode(), hashlib.sha256)
|
| 429 |
+
return base64.b64encode(mac.digest()).decode()
|
| 430 |
+
|
| 431 |
+
def _get(self, path, params=None, signed=False, timeout=10):
|
| 432 |
+
url = BITGET_BASE + path
|
| 433 |
+
headers = {}
|
| 434 |
+
# 公共行情默认不签名;若提供密钥则附带以提升限频
|
| 435 |
+
if signed and BITGET_API_KEY and BITGET_API_SECRET and BITGET_API_PASSPHRASE:
|
| 436 |
+
ts = str(int(time.time() * 1000))
|
| 437 |
+
query = ""
|
| 438 |
+
if params:
|
| 439 |
+
query = "?" + "&".join(f"{k}={v}" for k, v in params.items())
|
| 440 |
+
headers = {
|
| 441 |
+
"ACCESS-KEY": BITGET_API_KEY,
|
| 442 |
+
"ACCESS-SIGN": self._sign(ts, "GET", path + query),
|
| 443 |
+
"ACCESS-TIMESTAMP": ts,
|
| 444 |
+
"ACCESS-PASSPHRASE": BITGET_API_PASSPHRASE,
|
| 445 |
+
"Content-Type": "application/json",
|
| 446 |
+
}
|
| 447 |
+
try:
|
| 448 |
+
r = self.session.get(url, params=params, headers=headers, timeout=timeout)
|
| 449 |
+
if r.status_code != 200:
|
| 450 |
+
self.logger(f"⚠️ Bitget {path} 状态码 {r.status_code}")
|
| 451 |
+
return None
|
| 452 |
+
data = r.json()
|
| 453 |
+
if str(data.get("code")) != "00000":
|
| 454 |
+
self.logger(f"⚠️ Bitget {path} 返回 {data.get('code')}: {data.get('msg')}")
|
| 455 |
+
return None
|
| 456 |
+
return data.get("data")
|
| 457 |
+
except Exception as e:
|
| 458 |
+
self.logger(f"⚠️ Bitget {path} 异常: {e}")
|
| 459 |
+
return None
|
| 460 |
+
|
| 461 |
+
def spot_ticker(self, symbol):
|
| 462 |
+
"""返回标准化字典:price/high24/low24/open/bid/ask/qvol/ts/change_pct"""
|
| 463 |
+
data = self._get("/api/v2/spot/market/tickers", {"symbol": symbol})
|
| 464 |
+
if not data:
|
| 465 |
+
return None
|
| 466 |
+
d = data[0] if isinstance(data, list) else data
|
| 467 |
+
try:
|
| 468 |
+
return {
|
| 469 |
+
"price": float(d["lastPr"]),
|
| 470 |
+
"high24": float(d.get("high24h") or 0),
|
| 471 |
+
"low24": float(d.get("low24h") or 0),
|
| 472 |
+
"open": float(d.get("open") or 0),
|
| 473 |
+
"bid": float(d.get("bidPr") or 0),
|
| 474 |
+
"ask": float(d.get("askPr") or 0),
|
| 475 |
+
"qvol": float(d.get("usdtVolume") or 0),
|
| 476 |
+
"ts": int(d.get("ts") or 0),
|
| 477 |
+
"change_pct": float(d.get("change24h") or 0) * 100,
|
| 478 |
+
}
|
| 479 |
+
except (KeyError, ValueError, TypeError):
|
| 480 |
+
return None
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
# --- 6c. OKX 行情接口(现货 + GRAM 永续合约)---
|
| 484 |
+
class OKXAPI:
|
| 485 |
+
"""OKX 公共行情接口(v5)。市场数据无需密钥。"""
|
| 486 |
+
|
| 487 |
+
def __init__(self, logger):
|
| 488 |
+
self.logger = logger
|
| 489 |
+
self.session = requests.Session()
|
| 490 |
+
self.session.headers.update(REQ_HEADERS)
|
| 491 |
+
|
| 492 |
+
def _sign(self, ts, method, path, body=""):
|
| 493 |
+
msg = f"{ts}{method.upper()}{path}{body}"
|
| 494 |
+
mac = hmac.new(OKX_API_SECRET.encode(), msg.encode(), hashlib.sha256)
|
| 495 |
+
return base64.b64encode(mac.digest()).decode()
|
| 496 |
+
|
| 497 |
+
def _get(self, path, params=None, signed=False, timeout=10):
|
| 498 |
+
url = OKX_BASE + path
|
| 499 |
+
headers = {}
|
| 500 |
+
query = ""
|
| 501 |
+
if params:
|
| 502 |
+
query = "?" + "&".join(f"{k}={v}" for k, v in params.items())
|
| 503 |
+
if signed and OKX_API_KEY and OKX_API_SECRET and OKX_API_PASSPHRASE:
|
| 504 |
+
ts = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
|
| 505 |
+
headers = {
|
| 506 |
+
"OK-ACCESS-KEY": OKX_API_KEY,
|
| 507 |
+
"OK-ACCESS-SIGN": self._sign(ts, "GET", path + query),
|
| 508 |
+
"OK-ACCESS-TIMESTAMP": ts,
|
| 509 |
+
"OK-ACCESS-PASSPHRASE": OKX_API_PASSPHRASE,
|
| 510 |
+
"Content-Type": "application/json",
|
| 511 |
+
}
|
| 512 |
+
try:
|
| 513 |
+
r = self.session.get(url, params=params, headers=headers, timeout=timeout)
|
| 514 |
+
if r.status_code != 200:
|
| 515 |
+
self.logger(f"⚠️ OKX {path} 状态码 {r.status_code}")
|
| 516 |
+
return None
|
| 517 |
+
data = r.json()
|
| 518 |
+
if str(data.get("code")) != "0":
|
| 519 |
+
self.logger(f"⚠️ OKX {path} 返回 {data.get('code')}: {data.get('msg')}")
|
| 520 |
+
return None
|
| 521 |
+
return data.get("data")
|
| 522 |
+
except Exception as e:
|
| 523 |
+
self.logger(f"⚠️ OKX {path} 异常: {e}")
|
| 524 |
+
return None
|
| 525 |
+
|
| 526 |
+
def ticker(self, inst_id):
|
| 527 |
+
data = self._get("/api/v5/market/ticker", {"instId": inst_id})
|
| 528 |
+
if not data:
|
| 529 |
+
return None
|
| 530 |
+
d = data[0]
|
| 531 |
+
try:
|
| 532 |
+
return {
|
| 533 |
+
"price": float(d["last"]),
|
| 534 |
+
"high24": float(d.get("high24h") or 0),
|
| 535 |
+
"low24": float(d.get("low24h") or 0),
|
| 536 |
+
"open": float(d.get("open24h") or 0),
|
| 537 |
+
"bid": float(d.get("bidPx") or 0),
|
| 538 |
+
"ask": float(d.get("askPx") or 0),
|
| 539 |
+
"qvol": float(d.get("volCcy24h") or 0),
|
| 540 |
+
"ts": int(d.get("ts") or 0),
|
| 541 |
+
}
|
| 542 |
+
except (KeyError, ValueError, TypeError):
|
| 543 |
+
return None
|
| 544 |
+
|
| 545 |
+
def funding_rate(self, inst_id):
|
| 546 |
+
data = self._get("/api/v5/public/funding-rate", {"instId": inst_id})
|
| 547 |
+
if not data:
|
| 548 |
+
return None
|
| 549 |
+
d = data[0]
|
| 550 |
+
try:
|
| 551 |
+
return {
|
| 552 |
+
"rate_pct": float(d["fundingRate"]) * 100,
|
| 553 |
+
"next_time": int(d.get("nextFundingTime") or 0),
|
| 554 |
+
}
|
| 555 |
+
except (KeyError, ValueError, TypeError):
|
| 556 |
+
return None
|
| 557 |
+
|
| 558 |
+
def open_interest(self, inst_id):
|
| 559 |
+
data = self._get("/api/v5/public/open-interest", {"instId": inst_id})
|
| 560 |
+
if not data:
|
| 561 |
+
return None
|
| 562 |
+
d = data[0]
|
| 563 |
+
try:
|
| 564 |
+
return {
|
| 565 |
+
"oi": float(d.get("oi") or 0),
|
| 566 |
+
"oi_usd": float(d.get("oiUsd") or 0),
|
| 567 |
+
}
|
| 568 |
+
except (KeyError, ValueError, TypeError):
|
| 569 |
+
return None
|
| 570 |
+
|
| 571 |
+
|
| 572 |
# --- 7. 实时强平监控(websocket,可选)---
|
| 573 |
class LiquidationTracker:
|
| 574 |
"""
|
|
|
|
| 1237 |
return None
|
| 1238 |
|
| 1239 |
|
| 1240 |
+
# --- 9b. 多交易所监控(跨所差价 / Bitget STRC 股票 / OKX GRAM 合约)---
|
| 1241 |
+
def make_alert(name, category, key, direction, headline, body):
|
| 1242 |
+
"""构造与 AlertManager 兼容的告警字典"""
|
| 1243 |
+
emoji = SIGNAL_EMOJI[direction]
|
| 1244 |
+
text = f"{emoji} {name} {headline}\n{body}"
|
| 1245 |
+
return {"category": category, "key": key, "direction": direction,
|
| 1246 |
+
"sev_emoji": emoji, "title": headline, "text": text}
|
| 1247 |
+
|
| 1248 |
+
|
| 1249 |
+
class CrossExchangeMonitor:
|
| 1250 |
+
"""同一资产在 Binance / Bitget / OKX 间的价差提醒(TON 在 Binance,GRAM 在 Bitget/OKX)"""
|
| 1251 |
+
|
| 1252 |
+
def __init__(self, binance_api, bitget_api, okx_api, logger):
|
| 1253 |
+
self.binance = binance_api
|
| 1254 |
+
self.bitget = bitget_api
|
| 1255 |
+
self.okx = okx_api
|
| 1256 |
+
self.logger = logger
|
| 1257 |
+
|
| 1258 |
+
def _binance_price(self, symbol):
|
| 1259 |
+
t = self.binance.ticker_24h(symbol)
|
| 1260 |
+
if t and t.get("lastPrice"):
|
| 1261 |
+
try:
|
| 1262 |
+
return float(t["lastPrice"])
|
| 1263 |
+
except (ValueError, TypeError):
|
| 1264 |
+
return None
|
| 1265 |
+
return None
|
| 1266 |
+
|
| 1267 |
+
def evaluate(self, ex_cfg):
|
| 1268 |
+
alerts = []
|
| 1269 |
+
spread_cfg = ex_cfg.get("spread", {})
|
| 1270 |
+
if not spread_cfg.get("enable", True):
|
| 1271 |
+
return alerts
|
| 1272 |
+
thr = float(spread_cfg.get("threshold_pct", 0.5))
|
| 1273 |
+
use_bitget = ex_cfg.get("enable_bitget", True)
|
| 1274 |
+
use_okx = ex_cfg.get("enable_okx", True)
|
| 1275 |
+
|
| 1276 |
+
for pair in spread_cfg.get("pairs", []):
|
| 1277 |
+
name = pair.get("name", "?")
|
| 1278 |
+
prices = {}
|
| 1279 |
+
if pair.get("binance"):
|
| 1280 |
+
p = self._binance_price(pair["binance"])
|
| 1281 |
+
if p:
|
| 1282 |
+
prices["Binance"] = p
|
| 1283 |
+
if use_bitget and pair.get("bitget"):
|
| 1284 |
+
t = self.bitget.spot_ticker(pair["bitget"])
|
| 1285 |
+
if t:
|
| 1286 |
+
prices["Bitget"] = t["price"]
|
| 1287 |
+
if use_okx and pair.get("okx"):
|
| 1288 |
+
t = self.okx.ticker(pair["okx"])
|
| 1289 |
+
if t:
|
| 1290 |
+
prices["OKX"] = t["price"]
|
| 1291 |
+
|
| 1292 |
+
if len(prices) < 2:
|
| 1293 |
+
continue
|
| 1294 |
+
lo_ex = min(prices, key=prices.get)
|
| 1295 |
+
hi_ex = max(prices, key=prices.get)
|
| 1296 |
+
lo, hi = prices[lo_ex], prices[hi_ex]
|
| 1297 |
+
if lo <= 0:
|
| 1298 |
+
continue
|
| 1299 |
+
spread_pct = (hi - lo) / lo * 100
|
| 1300 |
+
if spread_pct >= thr:
|
| 1301 |
+
detail = " ".join(f"{ex} {fmt_price(prices[ex])}" for ex in prices)
|
| 1302 |
+
alerts.append(make_alert(
|
| 1303 |
+
name, "spread_ex", f"spread_{name}", "关注",
|
| 1304 |
+
f"跨所价差 {spread_pct:.2f}%",
|
| 1305 |
+
f"{detail}\n{hi_ex} 高于 {lo_ex} {spread_pct:.2f}%"
|
| 1306 |
+
f"(阈值 {thr}%),可关注搬砖/价差回归"))
|
| 1307 |
+
return alerts
|
| 1308 |
+
|
| 1309 |
+
|
| 1310 |
+
class STRCMonitor:
|
| 1311 |
+
"""Bitget STRC 股票代币(rToken)价格异动;休市(价格长时间不变)时不提醒"""
|
| 1312 |
+
|
| 1313 |
+
def __init__(self, bitget_api, logger):
|
| 1314 |
+
self.bitget = bitget_api
|
| 1315 |
+
self.logger = logger
|
| 1316 |
+
self.last_price = None
|
| 1317 |
+
self.last_change_ts = 0.0
|
| 1318 |
+
|
| 1319 |
+
def evaluate(self, strc_cfg):
|
| 1320 |
+
alerts = []
|
| 1321 |
+
if not strc_cfg.get("enable", True):
|
| 1322 |
+
return alerts
|
| 1323 |
+
symbol = strc_cfg.get("symbol", "RSTRCUSDT")
|
| 1324 |
+
t = self.bitget.spot_ticker(symbol)
|
| 1325 |
+
if not t:
|
| 1326 |
+
return alerts
|
| 1327 |
+
price = t["price"]
|
| 1328 |
+
now = time.time()
|
| 1329 |
+
name = f"STRC({symbol})"
|
| 1330 |
+
|
| 1331 |
+
if self.last_price is None:
|
| 1332 |
+
self.last_price = price
|
| 1333 |
+
self.last_change_ts = now
|
| 1334 |
+
return alerts
|
| 1335 |
+
|
| 1336 |
+
static_secs = float(strc_cfg.get("static_secs", 600))
|
| 1337 |
+
skip_static = strc_cfg.get("skip_when_static", True)
|
| 1338 |
+
is_static = (now - self.last_change_ts) >= static_secs
|
| 1339 |
+
|
| 1340 |
+
if price != self.last_price:
|
| 1341 |
+
pct = (price - self.last_price) / self.last_price * 100
|
| 1342 |
+
paused = (now - self.last_change_ts) >= static_secs
|
| 1343 |
+
self.last_price = price
|
| 1344 |
+
self.last_change_ts = now
|
| 1345 |
+
if abs(pct) >= float(strc_cfg.get("change_pct", 1.0)):
|
| 1346 |
+
direction = "涨" if pct > 0 else "跌"
|
| 1347 |
+
arrow = "📈" if pct > 0 else "📉"
|
| 1348 |
+
prefix = "复市后" if paused else ""
|
| 1349 |
+
alerts.append(make_alert(
|
| 1350 |
+
name, "strc", "strc_change", direction,
|
| 1351 |
+
f"{prefix}股价异动 {arrow} {pct:+.2f}%",
|
| 1352 |
+
f"现价 {fmt_price(price)} USDT(较上次 {pct:+.2f}%)"))
|
| 1353 |
+
return alerts
|
| 1354 |
+
|
| 1355 |
+
# 价格未变:休市判定
|
| 1356 |
+
if skip_static and is_static:
|
| 1357 |
+
return alerts
|
| 1358 |
+
|
| 1359 |
+
# 交易中但价格暂稳:检查 24h 振幅
|
| 1360 |
+
if t["low24"] > 0:
|
| 1361 |
+
amp = (t["high24"] - t["low24"]) / t["low24"] * 100
|
| 1362 |
+
if amp >= float(strc_cfg.get("amp_24h_pct", 3.0)):
|
| 1363 |
+
alerts.append(make_alert(
|
| 1364 |
+
name, "strc", "strc_amp", "关注",
|
| 1365 |
+
f"24h 振幅 {amp:.2f}%",
|
| 1366 |
+
f"24h 区间 {fmt_price(t['low24'])} ~ {fmt_price(t['high24'])}"
|
| 1367 |
+
f",现价 {fmt_price(price)}"))
|
| 1368 |
+
return alerts
|
| 1369 |
+
|
| 1370 |
+
|
| 1371 |
+
class OKXGramSwapMonitor:
|
| 1372 |
+
"""OKX GRAM 永续合约关键信息:价格异动 / 资金费率 / 持仓量变化"""
|
| 1373 |
+
|
| 1374 |
+
def __init__(self, okx_api, logger):
|
| 1375 |
+
self.okx = okx_api
|
| 1376 |
+
self.logger = logger
|
| 1377 |
+
self.last_price = None
|
| 1378 |
+
self.last_oi = None
|
| 1379 |
+
|
| 1380 |
+
def evaluate(self, swap_cfg):
|
| 1381 |
+
alerts = []
|
| 1382 |
+
if not swap_cfg.get("enable", True):
|
| 1383 |
+
return alerts
|
| 1384 |
+
inst = swap_cfg.get("inst_id", "GRAM-USDT-SWAP")
|
| 1385 |
+
name = f"OKX {inst}"
|
| 1386 |
+
|
| 1387 |
+
# 1) 合约价异动
|
| 1388 |
+
t = self.okx.ticker(inst)
|
| 1389 |
+
if t:
|
| 1390 |
+
price = t["price"]
|
| 1391 |
+
if self.last_price and self.last_price > 0:
|
| 1392 |
+
pct = (price - self.last_price) / self.last_price * 100
|
| 1393 |
+
if abs(pct) >= float(swap_cfg.get("price_change_pct", 2.0)):
|
| 1394 |
+
direction = "涨" if pct > 0 else "跌"
|
| 1395 |
+
arrow = "📈" if pct > 0 else "📉"
|
| 1396 |
+
alerts.append(make_alert(
|
| 1397 |
+
name, "okx_price", "okx_gram_price", direction,
|
| 1398 |
+
f"合约价异动 {arrow} {pct:+.2f}%",
|
| 1399 |
+
f"现价 {fmt_price(price)} USDT(较上次 {pct:+.2f}%)"))
|
| 1400 |
+
self.last_price = price
|
| 1401 |
+
|
| 1402 |
+
# 2) 资金费率
|
| 1403 |
+
fr = self.okx.funding_rate(inst)
|
| 1404 |
+
if fr:
|
| 1405 |
+
rate = fr["rate_pct"]
|
| 1406 |
+
high = float(swap_cfg.get("funding_high", 0.05))
|
| 1407 |
+
neg = float(swap_cfg.get("funding_neg", -0.05))
|
| 1408 |
+
if rate >= high:
|
| 1409 |
+
alerts.append(make_alert(
|
| 1410 |
+
name, "okx_funding", "okx_gram_funding_high", "关注",
|
| 1411 |
+
f"资金费率偏高 {rate:+.4f}%",
|
| 1412 |
+
f"多头需付费,资金费率 {rate:+.4f}%(阈值 {high}%),警惕多头拥挤"))
|
| 1413 |
+
elif rate <= neg:
|
| 1414 |
+
alerts.append(make_alert(
|
| 1415 |
+
name, "okx_funding", "okx_gram_funding_neg", "关注",
|
| 1416 |
+
f"资金费率为负 {rate:+.4f}%",
|
| 1417 |
+
f"空头需付费,资金费率 {rate:+.4f}%(阈值 {neg}%),警惕空头拥挤"))
|
| 1418 |
+
|
| 1419 |
+
# 3) 持仓量变化
|
| 1420 |
+
oi = self.okx.open_interest(inst)
|
| 1421 |
+
if oi:
|
| 1422 |
+
cur = oi["oi"]
|
| 1423 |
+
if self.last_oi and self.last_oi > 0:
|
| 1424 |
+
pct = (cur - self.last_oi) / self.last_oi * 100
|
| 1425 |
+
if abs(pct) >= float(swap_cfg.get("oi_change_pct", 5.0)):
|
| 1426 |
+
direction = "涨" if pct > 0 else "跌"
|
| 1427 |
+
word = "增仓" if pct > 0 else "减仓"
|
| 1428 |
+
alerts.append(make_alert(
|
| 1429 |
+
name, "okx_oi", "okx_gram_oi", direction,
|
| 1430 |
+
f"持仓量{word} {pct:+.2f}%",
|
| 1431 |
+
f"持仓量 {fmt_usdt(oi['oi_usd'])}(较上次 {pct:+.2f}%)"))
|
| 1432 |
+
self.last_oi = cur
|
| 1433 |
+
return alerts
|
| 1434 |
+
|
| 1435 |
+
|
| 1436 |
# --- 10. 监控主逻辑 ---
|
| 1437 |
class CryptoMonitor:
|
| 1438 |
def __init__(self):
|
|
|
|
| 1449 |
self._auto_calibrate_needed = not os.path.exists(CONFIG_FILE)
|
| 1450 |
|
| 1451 |
self.api = BinanceAPI(self.log)
|
| 1452 |
+
self.bitget = BitgetAPI(self.log)
|
| 1453 |
+
self.okx = OKXAPI(self.log)
|
| 1454 |
self.pusher = WeWorkBotPusher(WEWORK_BOT_WEBHOOK)
|
| 1455 |
self.alert_mgr = AlertManager(self.pusher, self.log, self.stats)
|
| 1456 |
self.liq = LiquidationTracker(self._futures_symbols(), self.log)
|
| 1457 |
|
| 1458 |
+
# 多交易所监控器
|
| 1459 |
+
self.cross_ex = CrossExchangeMonitor(self.api, self.bitget, self.okx, self.log)
|
| 1460 |
+
self.strc_mon = STRCMonitor(self.bitget, self.log)
|
| 1461 |
+
self.okx_gram = OKXGramSwapMonitor(self.okx, self.log)
|
| 1462 |
+
|
| 1463 |
self.evaluators = {}
|
| 1464 |
self._rebuild_evaluators()
|
| 1465 |
|
|
|
|
| 1607 |
except Exception as e:
|
| 1608 |
self.log(f"❌ {name} 评估异常: {e}")
|
| 1609 |
|
| 1610 |
+
# 多交易所监控(跨所差价 / STRC 股票 / OKX GRAM 合约)
|
| 1611 |
+
ex_cfg = cfg.get("exchanges", {})
|
| 1612 |
+
for label, mon, sub in (
|
| 1613 |
+
("跨所差价", self.cross_ex, ex_cfg),
|
| 1614 |
+
("STRC", self.strc_mon, ex_cfg.get("strc", {})),
|
| 1615 |
+
("OKX GRAM 合约", self.okx_gram, ex_cfg.get("okx_gram_swap", {})),
|
| 1616 |
+
):
|
| 1617 |
+
try:
|
| 1618 |
+
total_alerts.extend(mon.evaluate(sub))
|
| 1619 |
+
except Exception as e:
|
| 1620 |
+
self.log(f"❌ {label} 评估异常: {e}")
|
| 1621 |
+
|
| 1622 |
if total_alerts:
|
| 1623 |
self.alert_mgr.emit(total_alerts)
|
| 1624 |
|
|
|
|
| 1732 |
else:
|
| 1733 |
st.caption("自定义模式:阈值以下方各币种设置为准,不会被自动覆盖。")
|
| 1734 |
|
| 1735 |
+
with st.expander("多交易所设置(Bitget / OKX / 跨所差价 / STRC)", expanded=False):
|
| 1736 |
+
ex = cfg.setdefault("exchanges", {})
|
| 1737 |
+
ec1, ec2 = st.columns(2)
|
| 1738 |
+
with ec1:
|
| 1739 |
+
ex["enable_bitget"] = st.checkbox(
|
| 1740 |
+
"启用 Bitget", value=ex.get("enable_bitget", True),
|
| 1741 |
+
help="跨所差价的 GRAM/BTC 价格、STRC 股票均来自 Bitget")
|
| 1742 |
+
with ec2:
|
| 1743 |
+
ex["enable_okx"] = st.checkbox(
|
| 1744 |
+
"启用 OKX", value=ex.get("enable_okx", True),
|
| 1745 |
+
help="跨所差价的 GRAM/BTC 价格、GRAM 合约信息均来自 OKX")
|
| 1746 |
+
st.caption("⚠️ 密钥从环境变量读取(BITGET_*/OKX_*)。Bitget/OKX 对部分地区有访问限制,"
|
| 1747 |
+
"若 Space 在受限区域可设置 BITGET_BASE / OKX_BASE 指向可用代理。")
|
| 1748 |
+
|
| 1749 |
+
st.markdown("**跨交易所差价提醒**")
|
| 1750 |
+
sp = ex.setdefault("spread", {})
|
| 1751 |
+
sp["enable"] = st.checkbox("启用跨所差价提醒", value=sp.get("enable", True))
|
| 1752 |
+
sp["threshold_pct"] = st.number_input(
|
| 1753 |
+
"差价阈值 %(任意两所价差超过即提醒)", min_value=0.05, max_value=20.0,
|
| 1754 |
+
value=float(sp.get("threshold_pct", 0.5)), step=0.05, format="%.2f")
|
| 1755 |
+
pairs_txt = "\n".join(
|
| 1756 |
+
f"{p.get('name','')},{p.get('binance','')},{p.get('bitget','')},{p.get('okx','')}"
|
| 1757 |
+
for p in sp.get("pairs", []))
|
| 1758 |
+
new_pairs_txt = st.text_area(
|
| 1759 |
+
"对照表(每行:名称,Binance,Bitget,OKX;留空表示该所不参与)",
|
| 1760 |
+
value=pairs_txt, height=80,
|
| 1761 |
+
help="例:TON/GRAM,TONUSDT,GRAMUSDT,GRAM-USDT")
|
| 1762 |
+
parsed = []
|
| 1763 |
+
for line in new_pairs_txt.splitlines():
|
| 1764 |
+
cols = [c.strip() for c in line.split(",")]
|
| 1765 |
+
if cols and cols[0]:
|
| 1766 |
+
cols += [""] * (4 - len(cols))
|
| 1767 |
+
parsed.append({"name": cols[0], "binance": cols[1],
|
| 1768 |
+
"bitget": cols[2], "okx": cols[3]})
|
| 1769 |
+
if parsed:
|
| 1770 |
+
sp["pairs"] = parsed
|
| 1771 |
+
|
| 1772 |
+
st.markdown("**Bitget STRC 股票(rToken,休市价格不变时不提醒)**")
|
| 1773 |
+
strc = ex.setdefault("strc", {})
|
| 1774 |
+
sc1, sc2 = st.columns(2)
|
| 1775 |
+
with sc1:
|
| 1776 |
+
strc["enable"] = st.checkbox("启用 STRC 监控", value=strc.get("enable", True))
|
| 1777 |
+
strc["symbol"] = st.text_input("STRC 交易对", value=strc.get("symbol", "RSTRCUSDT"))
|
| 1778 |
+
strc["change_pct"] = st.number_input(
|
| 1779 |
+
"短时异动阈值 %", min_value=0.1, max_value=20.0,
|
| 1780 |
+
value=float(strc.get("change_pct", 1.0)), step=0.1, format="%.1f")
|
| 1781 |
+
with sc2:
|
| 1782 |
+
strc["amp_24h_pct"] = st.number_input(
|
| 1783 |
+
"24h 振幅阈值 %", min_value=0.5, max_value=50.0,
|
| 1784 |
+
value=float(strc.get("amp_24h_pct", 3.0)), step=0.5, format="%.1f")
|
| 1785 |
+
strc["skip_when_static"] = st.checkbox(
|
| 1786 |
+
"休市(价格不变)时不提醒", value=strc.get("skip_when_static", True))
|
| 1787 |
+
strc["static_secs"] = st.number_input(
|
| 1788 |
+
"判定休市的静止秒数", min_value=60, max_value=7200,
|
| 1789 |
+
value=int(strc.get("static_secs", 600)), step=60)
|
| 1790 |
+
|
| 1791 |
+
st.markdown("**OKX GRAM 永续合约**")
|
| 1792 |
+
sw = ex.setdefault("okx_gram_swap", {})
|
| 1793 |
+
sw["enable"] = st.checkbox("启用 GRAM 合约监控", value=sw.get("enable", True))
|
| 1794 |
+
wc1, wc2 = st.columns(2)
|
| 1795 |
+
with wc1:
|
| 1796 |
+
sw["inst_id"] = st.text_input("合约 instId", value=sw.get("inst_id", "GRAM-USDT-SWAP"))
|
| 1797 |
+
sw["price_change_pct"] = st.number_input(
|
| 1798 |
+
"合约价短时异动 %", min_value=0.1, max_value=20.0,
|
| 1799 |
+
value=float(sw.get("price_change_pct", 2.0)), step=0.1, format="%.1f")
|
| 1800 |
+
sw["oi_change_pct"] = st.number_input(
|
| 1801 |
+
"持仓量变动 %", min_value=0.5, max_value=50.0,
|
| 1802 |
+
value=float(sw.get("oi_change_pct", 5.0)), step=0.5, format="%.1f")
|
| 1803 |
+
with wc2:
|
| 1804 |
+
sw["funding_high"] = st.number_input(
|
| 1805 |
+
"资金费率高位 %", min_value=0.001, max_value=1.0,
|
| 1806 |
+
value=float(sw.get("funding_high", 0.05)), step=0.001, format="%.3f")
|
| 1807 |
+
sw["funding_neg"] = st.number_input(
|
| 1808 |
+
"资金费率负位 %", min_value=-1.0, max_value=-0.001,
|
| 1809 |
+
value=float(sw.get("funding_neg", -0.05)), step=0.001, format="%.3f")
|
| 1810 |
+
|
| 1811 |
coin_names = list(cfg["coins"].keys())
|
| 1812 |
tabs = st.tabs(coin_names + ["➕ 新增币种"])
|
| 1813 |
|