Add force_enter optional args and tests

This commit is contained in:
Robert Davey 2024-05-29 14:45:49 +01:00 committed by GitHub
parent 7f210ab3b5
commit 3da18c3443
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -312,20 +312,41 @@ class FtRestClient:
data = {"pair": pair, "price": price} data = {"pair": pair, "price": price}
return self._post("forcebuy", data=data) 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 """Force entering a trade
:param pair: Pair to buy (ETH/BTC) :param pair: Pair to buy (ETH/BTC)
:param side: 'long' or 'short' :param side: 'long' or 'short'
:param price: Optional - price to buy :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 :return: json object of the trade
""" """
data = { data = {
"pair": pair, "pair": pair,
"side": side, "side": side,
} }
if price: if price:
data["price"] = 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) return self._post("forceenter", data=data)
def forceexit(self, tradeid, ordertype=None, amount=None): def forceexit(self, tradeid, ordertype=None, amount=None):

View File

@ -96,6 +96,10 @@ def test_FtRestClient_call_invalid(caplog):
("forcebuy", ["XRP/USDT", 1.5]), ("forcebuy", ["XRP/USDT", 1.5]),
("forceenter", ["XRP/USDT", "short"]), ("forceenter", ["XRP/USDT", "short"]),
("forceenter", ["XRP/USDT", "short", 1.5]), ("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]),
("forceexit", [1, "limit"]), ("forceexit", [1, "limit"]),
("forceexit", [1, "limit", 100]), ("forceexit", [1, "limit", 100]),