ruff format: update ft_client

This commit is contained in:
Matthias
2024-05-12 16:16:26 +02:00
parent 4f5bf632fc
commit 15f32be176
4 changed files with 189 additions and 186 deletions
+40 -37
View File
@@ -15,41 +15,44 @@ from freqtrade_client.ft_rest_client import FtRestClient
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
logger = logging.getLogger("ft_rest_client")
def add_arguments(args: Any = None):
parser = argparse.ArgumentParser(
prog="freqtrade-client",
description="Client for the freqtrade REST API",
prog="freqtrade-client",
description="Client for the freqtrade REST API",
)
parser.add_argument(
"command", help="Positional argument defining the command to execute.", nargs="?"
)
parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {__version__}")
parser.add_argument(
"--show",
help="Show possible methods with this client",
dest="show",
action="store_true",
default=False,
)
parser.add_argument("command",
help="Positional argument defining the command to execute.",
nargs="?"
)
parser.add_argument('-V', '--version', action='version', version=f'%(prog)s {__version__}')
parser.add_argument('--show',
help='Show possible methods with this client',
dest='show',
action='store_true',
default=False
)
parser.add_argument('-c', '--config',
help='Specify configuration file (default: %(default)s). ',
dest='config',
type=str,
metavar='PATH',
default='config.json'
)
parser.add_argument(
"-c",
"--config",
help="Specify configuration file (default: %(default)s). ",
dest="config",
type=str,
metavar="PATH",
default="config.json",
)
parser.add_argument("command_arguments",
help="Positional arguments for the parameters for [command]",
nargs="*",
default=[]
)
parser.add_argument(
"command_arguments",
help="Positional arguments for the parameters for [command]",
nargs="*",
default=[],
)
pargs = parser.parse_args(args)
return vars(pargs)
@@ -59,8 +62,9 @@ def load_config(configfile):
file = Path(configfile)
if file.is_file():
with file.open("r") as f:
config = rapidjson.load(f, parse_mode=rapidjson.PM_COMMENTS |
rapidjson.PM_TRAILING_COMMAS)
config = rapidjson.load(
f, parse_mode=rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS
)
return config
else:
logger.warning(f"Could not load config file {file}.")
@@ -72,27 +76,26 @@ def print_commands():
client = FtRestClient(None)
print("Possible commands:\n")
for x, _ in inspect.getmembers(client):
if not x.startswith('_'):
doc = re.sub(':return:.*', '', getattr(client, x).__doc__, flags=re.MULTILINE).rstrip()
if not x.startswith("_"):
doc = re.sub(":return:.*", "", getattr(client, x).__doc__, flags=re.MULTILINE).rstrip()
print(f"{x}\n\t{doc}\n")
def main_exec(args: Dict[str, Any]):
if args.get("show"):
print_commands()
sys.exit()
config = load_config(args['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')
password = config.get('api_server', {}).get('password')
config = load_config(args["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")
password = config.get("api_server", {}).get("password")
server_url = f"http://{url}:{port}"
client = FtRestClient(server_url, username, password)
m = [x for x, y in inspect.getmembers(client) if not x.startswith('_')]
m = [x for x, y in inspect.getmembers(client) if not x.startswith("_")]
command = args["command"]
if command not in m:
logger.error(f"Command {command} not defined")