mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-26 00:40:23 +00:00
Merge pull request #11627 from arenstar/ftclient_trades_order_fix
Ftclient trades order fix
This commit is contained in:
@@ -200,9 +200,12 @@ def status(rpc: RPC = Depends(get_rpc)):
|
|||||||
def trades(
|
def trades(
|
||||||
limit: int = Query(500, ge=1, description="Maximum number of different trades to return data"),
|
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"),
|
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),
|
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"])
|
@router.get("/trade/{tradeid}", response_model=OpenTradeSchema, tags=["info", "trading"])
|
||||||
|
|||||||
@@ -255,11 +255,12 @@ class FtRestClient:
|
|||||||
"""
|
"""
|
||||||
return self._get("logs", params={"limit": limit} if limit else {})
|
return self._get("logs", params={"limit": limit} if limit else {})
|
||||||
|
|
||||||
def trades(self, limit=None, offset=None):
|
def trades(self, limit=None, offset=None, order_by_id=True):
|
||||||
"""Return trades history, sorted by id
|
"""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 limit: Limits trades to the X last trades. Max 500 trades.
|
||||||
:param offset: Offset by this amount of 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
|
:return: json object
|
||||||
"""
|
"""
|
||||||
params = {}
|
params = {}
|
||||||
@@ -267,6 +268,8 @@ class FtRestClient:
|
|||||||
params["limit"] = limit
|
params["limit"] = limit
|
||||||
if offset:
|
if offset:
|
||||||
params["offset"] = offset
|
params["offset"] = offset
|
||||||
|
if order_by_id:
|
||||||
|
params["order_by_id"] = True
|
||||||
return self._get("trades", params)
|
return self._get("trades", params)
|
||||||
|
|
||||||
def list_open_trades_custom_data(self, key=None, limit=100, offset=0):
|
def list_open_trades_custom_data(self, key=None, limit=100, offset=0):
|
||||||
|
|||||||
@@ -85,6 +85,8 @@ def test_FtRestClient_call_invalid(caplog):
|
|||||||
("trades", [], {}),
|
("trades", [], {}),
|
||||||
("trades", [5], {}),
|
("trades", [5], {}),
|
||||||
("trades", [5, 5], {}), # With offset
|
("trades", [5, 5], {}), # With offset
|
||||||
|
("trades", [5, 5, True], {}), # Explicit order_by_id=True
|
||||||
|
("trades", [5, 5, False], {}), # order_by_id=False
|
||||||
("trade", [1], {}),
|
("trade", [1], {}),
|
||||||
("delete_trade", [1], {}),
|
("delete_trade", [1], {}),
|
||||||
("cancel_open_order", [1], {}),
|
("cancel_open_order", [1], {}),
|
||||||
@@ -127,6 +129,10 @@ def test_FtRestClient_call_invalid(caplog):
|
|||||||
("pair_candles", ["XRP/USDT", "5m", 500], {"columns": ["close_time,close"]}),
|
("pair_candles", ["XRP/USDT", "5m", 500], {"columns": ["close_time,close"]}),
|
||||||
("pair_history", ["XRP/USDT", "5m", "SampleStrategy"], {}),
|
("pair_history", ["XRP/USDT", "5m", "SampleStrategy"], {}),
|
||||||
("pair_history", ["XRP/USDT", "5m"], {"strategy": "SampleStrategy"}),
|
("pair_history", ["XRP/USDT", "5m"], {"strategy": "SampleStrategy"}),
|
||||||
|
("trades", [], {"order_by_id": True}),
|
||||||
|
("trades", [], {"order_by_id": False}),
|
||||||
|
("trades", [5], {"order_by_id": False}),
|
||||||
|
("trades", [5, 5], {"order_by_id": True}),
|
||||||
("sysinfo", [], {}),
|
("sysinfo", [], {}),
|
||||||
("health", [], {}),
|
("health", [], {}),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -776,12 +776,28 @@ def test_api_trades(botclient, mocker, fee, markets, is_short):
|
|||||||
assert rc.json()["trades_count"] == 2
|
assert rc.json()["trades_count"] == 2
|
||||||
assert rc.json()["total_trades"] == 2
|
assert rc.json()["total_trades"] == 2
|
||||||
assert rc.json()["trades"][0]["is_short"] == is_short
|
assert rc.json()["trades"][0]["is_short"] == is_short
|
||||||
|
# Ensure the trades are sorted by trade_id (the default, see below)
|
||||||
|
assert rc.json()["trades"][0]["trade_id"] == 2
|
||||||
|
assert rc.json()["trades"][1]["trade_id"] == 3
|
||||||
|
|
||||||
rc = client_get(client, f"{BASE_URI}/trades?limit=1")
|
rc = client_get(client, f"{BASE_URI}/trades?limit=1")
|
||||||
assert_response(rc)
|
assert_response(rc)
|
||||||
assert len(rc.json()["trades"]) == 1
|
assert len(rc.json()["trades"]) == 1
|
||||||
assert rc.json()["trades_count"] == 1
|
assert rc.json()["trades_count"] == 1
|
||||||
assert rc.json()["total_trades"] == 2
|
assert rc.json()["total_trades"] == 2
|
||||||
|
|
||||||
|
# Test ascending order (default)
|
||||||
|
rc = client_get(client, f"{BASE_URI}/trades?order_by_id=true")
|
||||||
|
assert_response(rc)
|
||||||
|
assert rc.json()["trades"][0]["trade_id"] == 2
|
||||||
|
assert rc.json()["trades"][1]["trade_id"] == 3
|
||||||
|
|
||||||
|
# Test descending order
|
||||||
|
rc = client_get(client, f"{BASE_URI}/trades?order_by_id=false")
|
||||||
|
assert_response(rc)
|
||||||
|
assert rc.json()["trades"][0]["trade_id"] == 3
|
||||||
|
assert rc.json()["trades"][1]["trade_id"] == 2
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("is_short", [True, False])
|
@pytest.mark.parametrize("is_short", [True, False])
|
||||||
def test_api_trade_single(botclient, mocker, fee, ticker, markets, is_short):
|
def test_api_trade_single(botclient, mocker, fee, ticker, markets, is_short):
|
||||||
|
|||||||
Reference in New Issue
Block a user