diff --git a/docs/rest-api.md b/docs/rest-api.md index fc628ac71..73a7b9c89 100644 --- a/docs/rest-api.md +++ b/docs/rest-api.md @@ -145,6 +145,12 @@ python3 scripts/rest_client.py help ``` output Possible commands: +available_pairs + Return available pair (backtest data) based on timeframe / stake_currency selection + + :param timeframe: Only pairs with this timeframe available. + :param stake_currency: Only pairs that include this timeframe + balance Get the account balance. @@ -184,9 +190,27 @@ logs :param limit: Limits log messages to the last logs. No limit to get all the trades. +pair_candles + Return live dataframe for . + + :param pair: Pair to get data for + :param timeframe: Only pairs with this timeframe available. + :param limit: Limit result to the last n candles. + +pair_history + Return historic, analyzed dataframe + + :param pair: Pair to get data for + :param timeframe: Only pairs with this timeframe available. + :param strategy: Strategy to analyze and get values for + :param timerange: Timerange to get data for (same format than --timerange endpoints) + performance Return the performance of the different coins. +plot_config + Return plot configuration if the strategy defines one. + profit Return the profit summary. @@ -209,6 +233,9 @@ stop stopbuy Stop buying (but handle sells gracefully). Use `reload_config` to reset. +strategies + Lists available strategies + trades Return trades history. @@ -220,7 +247,6 @@ version whitelist Show the current whitelist. - ``` ## Advanced API usage using JWT tokens diff --git a/freqtrade/rpc/api_server.py b/freqtrade/rpc/api_server.py index 4d1c5731c..0b80283d9 100644 --- a/freqtrade/rpc/api_server.py +++ b/freqtrade/rpc/api_server.py @@ -166,8 +166,8 @@ class ApiServer(RPC): """ Helper function to jsonify object for a webserver """ return jsonify(return_value) - def rest_error(self, error_msg): - return jsonify({"error": error_msg}), 502 + def rest_error(self, error_msg, error_code=502): + return jsonify({"error": error_msg}), error_code def register_rest_rpc_urls(self): """ @@ -531,6 +531,8 @@ class ApiServer(RPC): pair = request.args.get("pair") timeframe = request.args.get("timeframe") limit = request.args.get("limit", type=int) + if not pair or not timeframe: + return self.rest_error("Mandatory parameter missing.", 400) results = self._analysed_dataframe(pair, timeframe, limit) return self.rest_dump(results) @@ -556,7 +558,7 @@ class ApiServer(RPC): strategy = request.args.get("strategy") if not pair or not timeframe or not timerange or not strategy: - return self.rest_error("Mandatory parameter missing.") + return self.rest_error("Mandatory parameter missing.", 400) config = deepcopy(self._config) config.update({ diff --git a/scripts/rest_client.py b/scripts/rest_client.py index 8512777df..8889b82c1 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -224,6 +224,62 @@ class FtRestClient(): return self._post("forcesell", data={"tradeid": tradeid}) + def strategies(self): + """Lists available strategies + + :return: json object + """ + return self._get("strategies") + + def plot_config(self): + """Return plot configuration if the strategy defines one. + + :return: json object + """ + return self._get("plot_config") + + def available_pairs(self, timeframe=None, stake_currency=None): + """Return available pair (backtest data) based on timeframe / stake_currency selection + + :param timeframe: Only pairs with this timeframe available. + :param stake_currency: Only pairs that include this timeframe + :return: json object + """ + return self._get("available_pairs", params={ + "stake_currency": stake_currency if timeframe else '', + "timeframe": timeframe if timeframe else '', + }) + + def pair_candles(self, pair, timeframe, limit=None): + """Return live dataframe for . + + :param pair: Pair to get data for + :param timeframe: Only pairs with this timeframe available. + :param limit: Limit result to the last n candles. + :return: json object + """ + return self._get("available_pairs", params={ + "pair": pair, + "timeframe": timeframe, + "limit": limit, + }) + + def pair_history(self, pair, timeframe, strategy, timerange=None): + """Return historic, analyzed dataframe + + :param pair: Pair to get data for + :param timeframe: Only pairs with this timeframe available. + :param strategy: Strategy to analyze and get values for + :param timerange: Timerange to get data for (same format than --timerange endpoints) + :return: json object + """ + return self._get("pair_history", params={ + "pair": pair, + "timeframe": timeframe, + "strategy": strategy, + "timerange": timerange if timerange else '', + }) + def add_arguments(): parser = argparse.ArgumentParser() diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index b98483061..47afc61a1 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -818,6 +818,16 @@ def test_api_pair_candles(botclient, ohlcv_history): timeframe = '5m' amount = 2 + # No pair + rc = client_get(client, + f"{BASE_URI}/pair_candles?limit={amount}&timeframe={timeframe}") + assert_response(rc, 400) + + # No timeframe + rc = client_get(client, + f"{BASE_URI}/pair_candles?pair=XRP%2FBTC") + assert_response(rc, 400) + rc = client_get(client, f"{BASE_URI}/pair_candles?limit={amount}&pair=XRP%2FBTC&timeframe={timeframe}") assert_response(rc)