优化前改动
This commit is contained in:
@@ -81,7 +81,7 @@ python3 "/Users/ddrwode/code/lm_code/bitmart/保守模式参数优化/四分之
|
||||
|
||||
默认 WebSocket 订阅:
|
||||
- `wss://openapi-ws-v2.bitmart.com/api?protocol=1.1`
|
||||
- topic: `futures/ticker:ETHUSDT`
|
||||
- topic: `futures/bookticker:ETHUSDT`(实时推送,默认更快)
|
||||
|
||||
如果你本机没有 WebSocket 依赖,会自动回退 API。安装方式:
|
||||
|
||||
|
||||
@@ -81,7 +81,8 @@ class BitmartFuturesTransactionConservative:
|
||||
# WebSocket 实时价格(优先使用,失败自动回退 API)
|
||||
self.ws_enabled = os.getenv("BITMART_WS_ENABLED", "1").strip().lower() not in {"0", "false", "off", "no"}
|
||||
self.ws_url = os.getenv("BITMART_WS_URL", "wss://openapi-ws-v2.bitmart.com/api?protocol=1.1")
|
||||
self.ws_topic = os.getenv("BITMART_WS_TOPIC", f"futures/ticker:{self.contract_symbol}")
|
||||
# 使用 bookticker 实时推送(比 ticker 的 1s 推送更及时)
|
||||
self.ws_topic = os.getenv("BITMART_WS_TOPIC", f"futures/bookticker:{self.contract_symbol}")
|
||||
self.ws_price_ttl_seconds = float(os.getenv("BITMART_WS_PRICE_TTL", "2.0"))
|
||||
self.ws_reconnect_seconds = float(os.getenv("BITMART_WS_RECONNECT_SECONDS", "2.0"))
|
||||
self.ws_last_price = None
|
||||
@@ -212,6 +213,12 @@ class BitmartFuturesTransactionConservative:
|
||||
return
|
||||
|
||||
payload = json.loads(message)
|
||||
if isinstance(payload, dict) and payload.get("success") is False:
|
||||
logger.warning(
|
||||
f"WebSocket 订阅失败: group={payload.get('group')} error={payload.get('error')}"
|
||||
)
|
||||
return
|
||||
|
||||
price = self._extract_price_from_ws_payload(payload)
|
||||
if price is not None:
|
||||
with self.ws_lock:
|
||||
|
||||
Reference in New Issue
Block a user