Keep bot operational when forecast model is unavailable
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import requests
|
||||
|
||||
from crypto_spot_bot.bybit import BybitClient, websocket_subscribe_message, _looks_like_leveraged_token, _looks_like_stablecoin
|
||||
|
||||
|
||||
@@ -86,6 +88,38 @@ def test_private_get_signs_the_same_query_it_sends(make_settings, tmp_path) -> N
|
||||
assert captured["headers"]["X-BAPI-SIGN"]
|
||||
|
||||
|
||||
def test_public_get_recreates_failed_tls_session_before_retry(make_settings, tmp_path, monkeypatch) -> None:
|
||||
client = BybitClient(make_settings(tmp_path))
|
||||
|
||||
class FailedSession:
|
||||
def get(self, *_args, **_kwargs):
|
||||
raise requests.exceptions.SSLError("invalid session id")
|
||||
|
||||
class Response:
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return {"retCode": 0, "result": {"ok": True}}
|
||||
|
||||
class WorkingSession:
|
||||
def get(self, *_args, **_kwargs):
|
||||
return Response()
|
||||
|
||||
resets = []
|
||||
client.session = FailedSession()
|
||||
|
||||
def reset_session() -> None:
|
||||
resets.append(True)
|
||||
client.session = WorkingSession()
|
||||
|
||||
monkeypatch.setattr(client, "_reset_session", reset_session)
|
||||
monkeypatch.setattr("crypto_spot_bot.bybit.time.sleep", lambda _seconds: None)
|
||||
|
||||
assert client.public_get("/v5/market/kline", {"symbol": "BTCUSDT"}) == {"ok": True}
|
||||
assert resets == [True]
|
||||
|
||||
|
||||
def test_websocket_subscribe_uses_configured_kline_interval() -> None:
|
||||
payload = websocket_subscribe_message(["BTCUSDT"], interval="60")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user