Fix Bybit linear open orders query
This commit is contained in:
@@ -74,7 +74,10 @@ class BybitGateway:
|
||||
categories = [category] if category else list(self.scanner.categories)
|
||||
result: list[dict[str, Any]] = []
|
||||
for item_category in categories:
|
||||
response = await self._call(self._http.get_open_orders, category=item_category, limit=50)
|
||||
parameters: dict[str, Any] = {"category": item_category, "limit": 50}
|
||||
if item_category == "linear":
|
||||
parameters["settleCoin"] = self.config.settle_coin
|
||||
response = await self._call(self._http.get_open_orders, **parameters)
|
||||
for order in _result(response).get("list", []):
|
||||
order = dict(order)
|
||||
order.setdefault("category", item_category)
|
||||
|
||||
28
tests/test_bybit_gateway.py
Normal file
28
tests/test_bybit_gateway.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from llm_trade_bot.bybit_gateway import BybitGateway
|
||||
from llm_trade_bot.config import BybitConfig, ScannerConfig
|
||||
|
||||
|
||||
class FakeBybitHTTP:
|
||||
def __init__(self) -> None:
|
||||
self.open_order_requests: list[dict[str, Any]] = []
|
||||
|
||||
def get_open_orders(self, **parameters: Any) -> dict[str, Any]:
|
||||
self.open_order_requests.append(parameters)
|
||||
return {"retCode": 0, "result": {"list": []}}
|
||||
|
||||
|
||||
async def test_open_orders_scopes_linear_requests_by_settle_coin() -> None:
|
||||
gateway = BybitGateway(BybitConfig("key", "secret", "USDC"), ScannerConfig())
|
||||
http = FakeBybitHTTP()
|
||||
gateway._http = http # type: ignore[assignment]
|
||||
|
||||
await gateway.open_orders()
|
||||
|
||||
assert http.open_order_requests == [
|
||||
{"category": "spot", "limit": 50},
|
||||
{"category": "linear", "limit": 50, "settleCoin": "USDC"},
|
||||
]
|
||||
Reference in New Issue
Block a user