zt p commited on
Commit
49efd8b
·
1 Parent(s): f03326d

新增 ENABLE_FUTURES 全局开关(默认关),彻底拦截 /fapi 与强平流调用,规避 US 451

Browse files
Files changed (1) hide show
  1. coinpush.py +10 -2
coinpush.py CHANGED
@@ -42,6 +42,12 @@ 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
  # 配置持久化文件
46
  CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
47
  CONFIG_FILE = os.path.join(CURRENT_DIR, "crypto_config.json")
@@ -592,7 +598,7 @@ def calibrate_thresholds(api, coin_cfg, logger=print, sensitivity=1.0):
592
  out["liq_severe_usdt"] = round(out["liq_5m_usdt"] * 4)
593
 
594
  # 7) 资金费率:历史费率分位(仅合约启用时)
595
- if coin_cfg.get("enable_futures"):
596
  fr = api._get(FAPI_BASE, "/fapi/v1/fundingRate",
597
  {"symbol": coin_cfg["futures_symbol"], "limit": 500})
598
  if fr:
@@ -741,7 +747,7 @@ class CoinEvaluator:
741
  self._check_rsi(cfg, sym, head, add)
742
 
743
  # 12) 合约类
744
- if cfg.get("enable_futures"):
745
  self._check_futures(cfg, head, add)
746
 
747
  snapshot = {
@@ -1015,6 +1021,8 @@ class CryptoMonitor:
1015
  self.logs.appendleft(entry)
1016
 
1017
  def _futures_symbols(self):
 
 
1018
  return [c["futures_symbol"] for c in self.config["coins"].values()
1019
  if c.get("enable_futures")]
1020
 
 
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 刷屏。
48
+ # 若自带可访问合约接口的代理,设置环境变量 ENABLE_FUTURES=true 即可整体开启。
49
+ FUTURES_ENABLED = os.getenv("ENABLE_FUTURES", "false").strip().lower() in ("1", "true", "yes", "on")
50
+
51
  # 配置持久化文件
52
  CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
53
  CONFIG_FILE = os.path.join(CURRENT_DIR, "crypto_config.json")
 
598
  out["liq_severe_usdt"] = round(out["liq_5m_usdt"] * 4)
599
 
600
  # 7) 资金费率:历史费率分位(仅合约启用时)
601
+ if FUTURES_ENABLED and coin_cfg.get("enable_futures"):
602
  fr = api._get(FAPI_BASE, "/fapi/v1/fundingRate",
603
  {"symbol": coin_cfg["futures_symbol"], "limit": 500})
604
  if fr:
 
747
  self._check_rsi(cfg, sym, head, add)
748
 
749
  # 12) 合约类
750
+ if FUTURES_ENABLED and cfg.get("enable_futures"):
751
  self._check_futures(cfg, head, add)
752
 
753
  snapshot = {
 
1021
  self.logs.appendleft(entry)
1022
 
1023
  def _futures_symbols(self):
1024
+ if not FUTURES_ENABLED:
1025
+ return []
1026
  return [c["futures_symbol"] for c in self.config["coins"].values()
1027
  if c.get("enable_futures")]
1028