feat(deribit): get_open_orders (limit resting + trigger non scattati)
Espone private/get_open_orders_by_currency sul router Deribit (pattern gia' presente per Hyperliquid/IBKR). Serve al reconciler resting di PythagorasGoal: TP/DSL attesi dai libri vs ordini realmente in book (caso MR02_BTC 2026-06-12: TP resting fillato di notte + disaster-SL sparito, scoperti solo al close sim). NB: per i trigger untriggered interrogare anche type='trigger_all' e fare merge per order_id. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -171,6 +171,9 @@ sources_used }` (+ `failed_sources` in modalità consenso).
|
|||||||
### Account
|
### Account
|
||||||
- `get_positions`
|
- `get_positions`
|
||||||
- `get_account_summary`
|
- `get_account_summary`
|
||||||
|
- `get_open_orders` — ordini aperti (`currency`, `kind?`, `type` default `all`;
|
||||||
|
per i trigger non scattati interrogare anche `type="trigger_all"` e fare
|
||||||
|
merge per `order_id`)
|
||||||
|
|
||||||
### Options analytics
|
### Options analytics
|
||||||
- `get_dvol`, `get_dvol_history`
|
- `get_dvol`, `get_dvol_history`
|
||||||
|
|||||||
@@ -412,6 +412,37 @@ class DeribitClient:
|
|||||||
"testnet": self.testnet,
|
"testnet": self.testnet,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async def get_open_orders(
|
||||||
|
self, currency: str = "USDC", kind: str | None = None, type: str = "all"
|
||||||
|
) -> list:
|
||||||
|
"""Ordini APERTI sul conto: limit resting e trigger non scattati.
|
||||||
|
NB Deribit: con type='all' gli untriggered possono essere omessi ->
|
||||||
|
chi vuole anche i bracket interroga type='trigger_all' e merge per
|
||||||
|
order_id (e' cio' che fa il reconciler di PythagorasGoal)."""
|
||||||
|
params: dict = {"currency": currency, "type": type}
|
||||||
|
if kind:
|
||||||
|
params["kind"] = kind
|
||||||
|
raw = await self._request("private/get_open_orders_by_currency", params)
|
||||||
|
result = raw.get("result") or []
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
"order_id": o.get("order_id"),
|
||||||
|
"instrument": o.get("instrument_name"),
|
||||||
|
"direction": o.get("direction"),
|
||||||
|
"order_type": o.get("order_type"),
|
||||||
|
"order_state": o.get("order_state"),
|
||||||
|
"amount": o.get("amount"),
|
||||||
|
"filled_amount": o.get("filled_amount"),
|
||||||
|
"price": o.get("price"),
|
||||||
|
"trigger_price": o.get("trigger_price"),
|
||||||
|
"reduce_only": o.get("reduce_only"),
|
||||||
|
"label": o.get("label"),
|
||||||
|
"creation_timestamp": o.get("creation_timestamp"),
|
||||||
|
}
|
||||||
|
for o in result
|
||||||
|
if isinstance(o, dict)
|
||||||
|
]
|
||||||
|
|
||||||
async def get_trade_history(
|
async def get_trade_history(
|
||||||
self, limit: int = 100, instrument_name: str | None = None
|
self, limit: int = 100, instrument_name: str | None = None
|
||||||
) -> list:
|
) -> list:
|
||||||
|
|||||||
@@ -71,6 +71,12 @@ class GetAccountSummaryReq(BaseModel):
|
|||||||
currency: str = "USDC"
|
currency: str = "USDC"
|
||||||
|
|
||||||
|
|
||||||
|
class GetOpenOrdersReq(BaseModel):
|
||||||
|
currency: str = "USDC"
|
||||||
|
kind: str | None = None
|
||||||
|
type: str = "all"
|
||||||
|
|
||||||
|
|
||||||
class GetTradeHistoryReq(BaseModel):
|
class GetTradeHistoryReq(BaseModel):
|
||||||
limit: int = 100
|
limit: int = 100
|
||||||
instrument_name: str | None = None
|
instrument_name: str | None = None
|
||||||
@@ -278,6 +284,10 @@ async def get_account_summary(
|
|||||||
return await client.get_account_summary(params.currency)
|
return await client.get_account_summary(params.currency)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_open_orders(client: DeribitClient, params: GetOpenOrdersReq) -> list:
|
||||||
|
return await client.get_open_orders(params.currency, params.kind, params.type)
|
||||||
|
|
||||||
|
|
||||||
async def get_trade_history(client: DeribitClient, params: GetTradeHistoryReq) -> list:
|
async def get_trade_history(client: DeribitClient, params: GetTradeHistoryReq) -> list:
|
||||||
return await client.get_trade_history(params.limit, params.instrument_name)
|
return await client.get_trade_history(params.limit, params.instrument_name)
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,13 @@ def make_router() -> APIRouter:
|
|||||||
):
|
):
|
||||||
return await t.get_account_summary(client, params)
|
return await t.get_account_summary(client, params)
|
||||||
|
|
||||||
|
@r.post("/tools/get_open_orders")
|
||||||
|
async def _get_open_orders(
|
||||||
|
params: t.GetOpenOrdersReq,
|
||||||
|
client: DeribitClient = Depends(get_deribit_client),
|
||||||
|
):
|
||||||
|
return await t.get_open_orders(client, params)
|
||||||
|
|
||||||
@r.post("/tools/get_trade_history")
|
@r.post("/tools/get_trade_history")
|
||||||
async def _get_trade_history(
|
async def _get_trade_history(
|
||||||
params: t.GetTradeHistoryReq,
|
params: t.GetTradeHistoryReq,
|
||||||
|
|||||||
Reference in New Issue
Block a user