Fix Binance linear market context

This commit is contained in:
Azimkin
2026-09-19 17:41:42 +02:00
parent 93cafe8160
commit 0df55d295c
4 changed files with 69 additions and 26 deletions

View File

@@ -5,7 +5,7 @@ from typing import Any
import pytest
from llm_trade_bot.binance_gateway import BinanceError, BinanceGateway
from llm_trade_bot.binance_gateway import BinanceError, BinanceGateway, _active_ideas
from llm_trade_bot.config import BinanceAccountConfig, BinanceConfig, ScannerConfig
from llm_trade_bot.models import (
Category,
@@ -160,3 +160,36 @@ async def test_trailing_rate_outside_binance_range_rejects_before_opening():
)
assert not usdm.requests
assert not usdm.mutations
async def test_linear_market_context_uses_a_valid_binance_depth_limit():
class MarketClient(FakeBinanceClient):
async def request(self, method: str, path: str, parameters=None, **kwargs):
self.requests.append((method, path, parameters, kwargs))
if path.endswith("/ticker/24hr"):
return {"lastPrice": "100"}
if path.endswith("/depth"):
return {"bids": [], "asks": []}
if path.endswith("/klines"):
return [[0, "1", "101", "99", "100", "10"] for _ in range(20)]
return await super().request(method, path, parameters, **kwargs)
spot = MarketClient("/api/v3/exchangeInfo", [])
usdm = MarketClient("/fapi/v1/exchangeInfo", [])
context = await gateway(spot, usdm).market_context("linear", "BTCUSDT")
depth = next(parameters for _, path, parameters, _ in usdm.requests if path == "/fapi/v1/depth")
assert context["ticker"]["lastPrice"] == "100"
assert depth == {"symbol": "BTCUSDT", "limit": 20}
def test_seeded_spot_assets_are_exposure_but_not_active_ideas():
state = {
"wallets": {"spot": {"balances": [{"asset": "SOL", "free": "4", "locked": "0"}]}},
"positions": [],
"open_orders": [],
}
assert _active_ideas(state) == set()
state["open_orders"] = [
{"category": "spot", "symbol": "SOLUSDT", "protective": True, "client_id": "ltb-1-tp"}
]
assert _active_ideas(state) == {"spot:SOLUSDT"}