Merge pull request #10269 from freqtrade/frog-rest-client-1
Add force_enter optional args and tests
This commit is contained in:
@@ -81,12 +81,12 @@ def print_commands():
|
||||
print(f"{x}\n\t{doc}\n")
|
||||
|
||||
|
||||
def main_exec(args: Dict[str, Any]):
|
||||
if args.get("show"):
|
||||
def main_exec(parsed: Dict[str, Any]):
|
||||
if parsed.get("show"):
|
||||
print_commands()
|
||||
sys.exit()
|
||||
|
||||
config = load_config(args["config"])
|
||||
config = load_config(parsed["config"])
|
||||
url = config.get("api_server", {}).get("listen_ip_address", "127.0.0.1")
|
||||
port = config.get("api_server", {}).get("listen_port", "8080")
|
||||
username = config.get("api_server", {}).get("username")
|
||||
@@ -96,13 +96,24 @@ def main_exec(args: Dict[str, Any]):
|
||||
client = FtRestClient(server_url, username, password)
|
||||
|
||||
m = [x for x, y in inspect.getmembers(client) if not x.startswith("_")]
|
||||
command = args["command"]
|
||||
command = parsed["command"]
|
||||
if command not in m:
|
||||
logger.error(f"Command {command} not defined")
|
||||
print_commands()
|
||||
return
|
||||
|
||||
print(json.dumps(getattr(client, command)(*args["command_arguments"])))
|
||||
# Split arguments with = into key/value pairs
|
||||
kwargs = {x.split("=")[0]: x.split("=")[1] for x in parsed["command_arguments"] if "=" in x}
|
||||
args = [x for x in parsed["command_arguments"] if "=" not in x]
|
||||
try:
|
||||
res = getattr(client, command)(*args, **kwargs)
|
||||
print(json.dumps(res))
|
||||
except TypeError as e:
|
||||
logger.error(f"Error executing command {command}: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
logger.error(f"Fatal Error executing command {command}: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -54,7 +54,7 @@ class FtRestClient:
|
||||
# return resp.text
|
||||
return resp.json()
|
||||
except ConnectionError:
|
||||
logger.warning("Connection error")
|
||||
logger.warning(f"Connection error - could not connect to {netloc}.")
|
||||
|
||||
def _get(self, apipath, params: ParamsT = None):
|
||||
return self._call("GET", apipath, params=params)
|
||||
@@ -312,20 +312,48 @@ 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 keyword argument - 'limit' or 'market'
|
||||
:param stake_amount: Optional keyword argument - stake amount (as float)
|
||||
:param leverage: Optional keyword argument - leverage (as float)
|
||||
:param enter_tag: Optional keyword argument - entry tag (as 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):
|
||||
|
||||
Reference in New Issue
Block a user