Fix Binance linear market context
This commit is contained in:
@@ -5,7 +5,7 @@ from zoneinfo import ZoneInfo
|
||||
|
||||
import pytest
|
||||
|
||||
from llm_trade_bot.agent import AgentTools
|
||||
from llm_trade_bot.agent import AgentTools, _has_existing_idea
|
||||
from llm_trade_bot.config import (
|
||||
AppConfig,
|
||||
BraveConfig,
|
||||
@@ -102,3 +102,22 @@ async def test_pause_blocks_entry_from_running_session(tmp_path):
|
||||
)
|
||||
finally:
|
||||
await database.close()
|
||||
|
||||
|
||||
def test_seeded_spot_balance_does_not_block_new_agent_entry():
|
||||
state = {
|
||||
"wallets": {"spot": {"balances": [{"asset": "SOL", "free": "4", "locked": "0"}]}},
|
||||
"positions": [],
|
||||
"open_orders": [],
|
||||
}
|
||||
assert _has_existing_idea(state, "spot", "SOLUSDT") is False
|
||||
|
||||
state["open_orders"] = [
|
||||
{
|
||||
"category": "spot",
|
||||
"symbol": "SOLUSDT",
|
||||
"protective": True,
|
||||
"client_id": "ltb-12-abcd-tp",
|
||||
}
|
||||
]
|
||||
assert _has_existing_idea(state, "spot", "SOLUSDT") is True
|
||||
|
||||
@@ -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"}
|
||||
|
||||
Reference in New Issue
Block a user