From 75d5ff69ef78c30f63c061d0012f1ae9c822703c Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 11 Nov 2019 20:09:58 +0100 Subject: [PATCH] Add ping endpoing --- docs/rest-api.md | 9 ++++++++- freqtrade/rpc/api_server.py | 9 +++++++++ tests/rpc/test_rpc_apiserver.py | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/rest-api.md b/docs/rest-api.md index 4d5bc5730..85435e0db 100644 --- a/docs/rest-api.md +++ b/docs/rest-api.md @@ -22,7 +22,14 @@ Sample configuration: !!! Danger "Password selection" Please make sure to select a very strong, unique password to protect your bot from unauthorized access. -You can then access the API by going to `http://127.0.0.1:8080/api/v1/version` to check if the API is running correctly. +You can then access the API by going to `http://127.0.0.1:8080/api/v1/ping` to check if the API is running correctly. +This should return the response: + +``` output +{"status":"pong"} +``` + +All other endpoints will require authentication, so are not available through a webrowser. To generate a secure password, either use a password manager, or use the below code snipped. diff --git a/freqtrade/rpc/api_server.py b/freqtrade/rpc/api_server.py index 67bbfdc78..5167823fd 100644 --- a/freqtrade/rpc/api_server.py +++ b/freqtrade/rpc/api_server.py @@ -169,6 +169,8 @@ class ApiServer(RPC): view_func=self._status, methods=['GET']) self.app.add_url_rule(f'{BASE_URI}/version', 'version', view_func=self._version, methods=['GET']) + self.app.add_url_rule(f'{BASE_URI}/ping', 'ping', + view_func=self._ping, methods=['GET']) # Combined actions and infos self.app.add_url_rule(f'{BASE_URI}/blacklist', 'blacklist', view_func=self._blacklist, @@ -224,6 +226,13 @@ class ApiServer(RPC): msg = self._rpc_stopbuy() return self.rest_dump(msg) + @rpc_catch_errors + def _ping(self): + """ + simple poing version + """ + return self.rest_dump({"status": "pong"}) + @require_login @rpc_catch_errors def _version(self): diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index b572a0514..6e65cf934 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -64,6 +64,10 @@ def test_api_not_found(botclient): def test_api_unauthorized(botclient): ftbot, client = botclient + rc = client.get(f"{BASE_URI}/ping") + assert_response(rc) + assert rc.json == {'status': 'pong'} + # Don't send user/pass information rc = client.get(f"{BASE_URI}/version") assert_response(rc, 401)