diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index 0081871f0..6d7dc8bb5 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -200,9 +200,10 @@ def status(rpc: RPC = Depends(get_rpc)): def trades( limit: int = Query(500, ge=1, description="Maximum number of different trades to return data"), offset: int = Query(0, ge=0, description="Number of trades to skip for pagination"), + order_by_id: bool = Query(True, description="Sort trades by id (default: True). If False, sorts by latest timestamp"), rpc: RPC = Depends(get_rpc), ): - return rpc._rpc_trade_history(limit, offset=offset, order_by_id=True) + return rpc._rpc_trade_history(limit, offset=offset, order_by_id=order_by_id) @router.get("/trade/{tradeid}", response_model=OpenTradeSchema, tags=["info", "trading"]) diff --git a/ft_client/freqtrade_client/ft_rest_client.py b/ft_client/freqtrade_client/ft_rest_client.py index 5e15bc185..c3be342f5 100755 --- a/ft_client/freqtrade_client/ft_rest_client.py +++ b/ft_client/freqtrade_client/ft_rest_client.py @@ -255,11 +255,12 @@ class FtRestClient: """ return self._get("logs", params={"limit": limit} if limit else {}) - def trades(self, limit=None, offset=None): - """Return trades history, sorted by id + def trades(self, limit=None, offset=None, order_by_id=True): + """Return trades history, sorted by id (or by latest timestamp if order_by_id=False) :param limit: Limits trades to the X last trades. Max 500 trades. :param offset: Offset by this amount of trades. + :param order_by_id: Sort trades by id (default: True). If False, sorts by latest timestamp. :return: json object """ params = {} @@ -267,6 +268,8 @@ class FtRestClient: params["limit"] = limit if offset: params["offset"] = offset + if order_by_id: + params["order_by_id"] = True return self._get("trades", params) def list_open_trades_custom_data(self, key=None, limit=100, offset=0):