chore: implement pagination for _rpc_list_custom_data

This commit is contained in:
Axel-CH
2025-03-10 22:17:34 -04:00
parent 76aefccd03
commit 673447794e

View File

@@ -1116,15 +1116,18 @@ class RPC:
} }
def _rpc_list_custom_data( def _rpc_list_custom_data(
self, trade_id: int | None = None, key: str | None = None self, trade_id: int | None = None, key: str | None = None, limit: int = 100, offset: int = 0
) -> list[dict[str, Any]]: ) -> list[dict[str, Any]]:
""" """
Fetch custom data for a specific trade, or all open trades if `trade_id` is not provided. Fetch custom data for a specific trade, or all open trades if `trade_id` is not provided.
Pagination is applied via `limit` and `offset`.
""" """
trades: Sequence[Trade] trades: Sequence[Trade]
if trade_id is None: if trade_id is None:
# get all open trades # Get all open trades
trades = Trade.get_open_trades() trades = Trade.session.scalars(
Trade.get_trades_query([Trade.is_open.is_(True)]).limit(limit).offset(offset)
).all()
else: else:
trades = Trade.get_trades(trade_filter=[Trade.id == trade_id]).all() trades = Trade.get_trades(trade_filter=[Trade.id == trade_id]).all()
@@ -1142,7 +1145,7 @@ class RPC:
custom_data.extend(trade.get_all_custom_data()) custom_data.extend(trade.get_all_custom_data())
# Format the results # Format the results
return [ formatted_results = [
{ {
"id": data_entry.id, "id": data_entry.id,
"ft_trade_id": data_entry.ft_trade_id, "ft_trade_id": data_entry.ft_trade_id,
@@ -1155,6 +1158,8 @@ class RPC:
for data_entry in custom_data for data_entry in custom_data
] ]
return formatted_results
def _rpc_performance(self) -> list[dict[str, Any]]: def _rpc_performance(self) -> list[dict[str, Any]]:
""" """
Handler for performance. Handler for performance.