lint: ruff clean services/ (autofix + manual + ignore E741)
ci / ruff lint (push) Successful in 15s
ci / validate compose + Caddyfile (push) Successful in 2m6s
ci / mypy mcp_common (push) Successful in 30s
ci / pytest (push) Successful in 34s
ci / build & push to registry (push) Failing after 47s

- 24 autofix safe (SIM105 contextlib.suppress, F401 unused imports,
  I001 import order, B007 unused loop var, F811 redef, F841 unused).
- 15 unsafe-fix (UP038 X|Y in isinstance, SIM108 ternary, ecc.).
- Manual fix: SIM102 nested if in deribit term_structure, E402 imports
  in test_cot.py + sentiment server.py.
- Ignore E741 (variabili 'l' in list comprehensions deribit/client.py
  — stilistico, non bug).

Tests: 478/478 verdi.
This commit is contained in:
AdrianoDev
2026-04-29 08:44:12 +02:00
parent 910f80c99b
commit 9da2e12473
15 changed files with 29 additions and 41 deletions
@@ -1,10 +1,10 @@
from __future__ import annotations
import contextlib
import time
from dataclasses import dataclass, field
from typing import Any
import httpx
from mcp_common import indicators as ind
from mcp_common import microstructure as micro
from mcp_common import options as opt
@@ -196,10 +196,8 @@ class DeribitClient:
name = s.get("instrument_name")
oi = s.get("open_interest")
if name and oi is not None:
try:
with contextlib.suppress(TypeError, ValueError):
oi_by_name[name] = float(oi)
except (TypeError, ValueError):
pass
all_items = raw.get("result") or []
filtered: list[dict] = []
@@ -882,10 +880,9 @@ class DeribitClient:
shape = "backwardation"
short_term = next((x for x in ts if 8 <= x["dte"] <= 14), None)
mid_term = next((x for x in ts if 35 <= x["dte"] <= 45), None)
if short_term and mid_term:
if mid_term["atm_iv"] - short_term["atm_iv"] > 5:
contango_steep = True
calendar_opp = True
if short_term and mid_term and mid_term["atm_iv"] - short_term["atm_iv"] > 5:
contango_steep = True
calendar_opp = True
return {
"currency": currency,
@@ -1131,7 +1128,7 @@ class DeribitClient:
structure = self._guess_structure(enriched)
notional = sum(l["quantity"] * spot for l in enriched) if spot else 0.0
sum(l["quantity"] * spot for l in enriched) if spot else 0.0
fee_per_leg = min(0.0003 * (spot or 1) * sum(l["quantity"] for l in enriched),
0.125 * abs(net_premium)) if spot else 0.0
fees_open = round(fee_per_leg, 4)
@@ -1,5 +1,6 @@
from __future__ import annotations
import contextlib
import os
from fastapi import Depends, FastAPI, HTTPException
@@ -272,10 +273,8 @@ def create_app(
@asynccontextmanager
async def _lifespan(_app: FastAPI):
for inst in ("BTC-PERPETUAL", "ETH-PERPETUAL"):
try:
with contextlib.suppress(Exception):
await client.set_leverage(inst, cap_default)
except Exception:
pass
yield
app = build_app(
@@ -551,10 +550,8 @@ def create_app(
_check(principal, core=True)
lev = _enforce_leverage(body.leverage, creds=creds, exchange="deribit")
if lev != cap_default:
try:
with contextlib.suppress(Exception):
await client.set_leverage(body.instrument_name, lev)
except Exception:
pass
result = await client.place_order(
instrument_name=body.instrument_name,
side=body.side,
@@ -582,10 +579,8 @@ def create_app(
lev = _enforce_leverage(body.leverage, creds=creds, exchange="deribit")
if lev != cap_default:
for leg in body.legs:
try:
with contextlib.suppress(Exception):
await client.set_leverage(leg.instrument_name, lev)
except Exception:
pass
result = await client.place_combo_order(
legs=[leg.model_dump() for leg in body.legs],
side=body.side,