From 3da18c3443b74478c86221e2309ee9732ea98ba8 Mon Sep 17 00:00:00 2001 From: Robert Davey Date: Wed, 29 May 2024 14:45:49 +0100 Subject: [PATCH] Add force_enter optional args and tests --- ft_client/freqtrade_client/ft_rest_client.py | 23 +++++++++++++++++++- ft_client/test_client/test_rest_client.py | 4 ++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/ft_client/freqtrade_client/ft_rest_client.py b/ft_client/freqtrade_client/ft_rest_client.py index 6e5f7e6c5..af2d370e0 100755 --- a/ft_client/freqtrade_client/ft_rest_client.py +++ b/ft_client/freqtrade_client/ft_rest_client.py @@ -312,20 +312,41 @@ class FtRestClient: data = {"pair": pair, "price": price} return self._post("forcebuy", data=data) - def forceenter(self, pair, side, price=None): + def forceenter(self, pair, side, + price=None, order_type=None, + stake_amount=None, leverage=None, + enter_tag=None): """Force entering a trade :param pair: Pair to buy (ETH/BTC) :param side: 'long' or 'short' :param price: Optional - price to buy + :param order_type: Optional - 'limit' or 'market' + :param stake_amount: Optional - stake amount (as a float) + :param leverage: Optional - leverage (as a float) + :param enter_tag: Optional - entry tag (as a string, default: 'force_enter') :return: json object of the trade """ data = { "pair": pair, "side": side, } + if price: data["price"] = price + + if order_type: + data["ordertype"] = order_type + + if stake_amount: + data["stakeamount"] = stake_amount + + if leverage: + data["leverage"] = leverage + + if enter_tag: + data["entry_tag"] = enter_tag + return self._post("forceenter", data=data) def forceexit(self, tradeid, ordertype=None, amount=None): diff --git a/ft_client/test_client/test_rest_client.py b/ft_client/test_client/test_rest_client.py index 08ccee765..05af92ad6 100644 --- a/ft_client/test_client/test_rest_client.py +++ b/ft_client/test_client/test_rest_client.py @@ -96,6 +96,10 @@ def test_FtRestClient_call_invalid(caplog): ("forcebuy", ["XRP/USDT", 1.5]), ("forceenter", ["XRP/USDT", "short"]), ("forceenter", ["XRP/USDT", "short", 1.5]), + ("forceenter", ["XRP/USDT", "short", 1.5, "market"]), + ("forceenter", ["XRP/USDT", "short", 1.5, "market", 100]), + ("forceenter", ["XRP/USDT", "short", 1.5, "market", 100, 10.0]), + ("forceenter", ["XRP/USDT", "short", 1.5, "market", 100, 10.0, "test_force_enter"]), ("forceexit", [1]), ("forceexit", [1, "limit"]), ("forceexit", [1, "limit", 100]),