Improve rest api client / status response

This commit is contained in:
Matthias 2019-11-17 14:40:59 +01:00
parent 841c379797
commit 3aee8d2b2a
3 changed files with 21 additions and 10 deletions

View File

@ -330,8 +330,11 @@ class ApiServer(RPC):
Returns the current status of the trades in json format Returns the current status of the trades in json format
""" """
results = self._rpc_trade_status() try:
return self.rest_dump(results) results = self._rpc_trade_status()
return self.rest_dump(results)
except RPCException:
return self.rest_dump([])
@require_login @require_login
@rpc_catch_errors @rpc_catch_errors

View File

@ -8,12 +8,14 @@ so it can be used as a standalone script.
""" """
import argparse import argparse
import inspect
import json import json
import logging import logging
import inspect import sys
from urllib.parse import urlencode, urlparse, urlunparse
from pathlib import Path from pathlib import Path
from urllib.parse import urlencode, urlparse, urlunparse
import rapidjson
import requests import requests
from requests.exceptions import ConnectionError from requests.exceptions import ConnectionError
@ -190,7 +192,9 @@ class FtRestClient():
def add_arguments(): def add_arguments():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("command", parser.add_argument("command",
help="Positional argument defining the command to execute.") help="Positional argument defining the command to execute.",
nargs="?"
)
parser.add_argument('--show', parser.add_argument('--show',
help='Show possible methods with this client', help='Show possible methods with this client',
@ -221,9 +225,12 @@ def load_config(configfile):
file = Path(configfile) file = Path(configfile)
if file.is_file(): if file.is_file():
with file.open("r") as f: with file.open("r") as f:
config = json.load(f) config = rapidjson.load(f, parse_mode=rapidjson.PM_COMMENTS |
rapidjson.PM_TRAILING_COMMAS)
return config return config
return {} else:
logger.warning(f"Could not load config file {file}.")
sys.exit(1)
def print_commands(): def print_commands():
@ -237,8 +244,9 @@ def print_commands():
def main(args): def main(args):
if args.get("help"): if args.get("show"):
print_commands() print_commands()
sys.exit()
config = load_config(args["config"]) config = load_config(args["config"])
url = config.get("api_server", {}).get("server_url", "127.0.0.1") url = config.get("api_server", {}).get("server_url", "127.0.0.1")

View File

@ -417,8 +417,8 @@ def test_api_status(botclient, mocker, ticker, fee, markets):
) )
rc = client_get(client, f"{BASE_URI}/status") rc = client_get(client, f"{BASE_URI}/status")
assert_response(rc, 502) assert_response(rc, 200)
assert rc.json == {'error': 'Error querying _status: no active trade'} assert rc.json == []
ftbot.create_trades() ftbot.create_trades()
rc = client_get(client, f"{BASE_URI}/status") rc = client_get(client, f"{BASE_URI}/status")