• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

freqtrade / freqtrade / 9394559170

26 Apr 2024 06:36AM UTC coverage: 94.656% (-0.02%) from 94.674%
9394559170

push

github

xmatthias
Loader should be passed as kwarg for clarity

20280 of 21425 relevant lines covered (94.66%)

0.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.55
/ft_client/freqtrade_client/ft_client.py
1
import argparse
1✔
2
import inspect
1✔
3
import json
1✔
4
import logging
1✔
5
import re
1✔
6
import sys
1✔
7
from pathlib import Path
1✔
8
from typing import Any, Dict
1✔
9

10
import rapidjson
1✔
11
from freqtrade_client import __version__
1✔
12
from freqtrade_client.ft_rest_client import FtRestClient
1✔
13

14

15
logging.basicConfig(
1✔
16
    level=logging.INFO,
17
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
18
)
19
logger = logging.getLogger("ft_rest_client")
1✔
20

21

22
def add_arguments(args: Any = None):
1✔
23
    parser = argparse.ArgumentParser()
1✔
24
    parser.add_argument("command",
1✔
25
                        help="Positional argument defining the command to execute.",
26
                        nargs="?"
27
                        )
28
    parser.add_argument('-V', '--version', action='version', version=f'%(prog)s {__version__}')
1✔
29
    parser.add_argument('--show',
1✔
30
                        help='Show possible methods with this client',
31
                        dest='show',
32
                        action='store_true',
33
                        default=False
34
                        )
35

36
    parser.add_argument('-c', '--config',
1✔
37
                        help='Specify configuration file (default: %(default)s). ',
38
                        dest='config',
39
                        type=str,
40
                        metavar='PATH',
41
                        default='config.json'
42
                        )
43

44
    parser.add_argument("command_arguments",
1✔
45
                        help="Positional arguments for the parameters for [command]",
46
                        nargs="*",
47
                        default=[]
48
                        )
49

50
    pargs = parser.parse_args(args)
1✔
51
    return vars(pargs)
1✔
52

53

54
def load_config(configfile):
1✔
55
    file = Path(configfile)
1✔
56
    if file.is_file():
1✔
57
        with file.open("r") as f:
1✔
58
            config = rapidjson.load(f, parse_mode=rapidjson.PM_COMMENTS |
1✔
59
                                    rapidjson.PM_TRAILING_COMMAS)
60
        return config
1✔
61
    else:
62
        logger.warning(f"Could not load config file {file}.")
1✔
63
        sys.exit(1)
1✔
64

65

66
def print_commands():
1✔
67
    # Print dynamic help for the different commands using the commands doc-strings
68
    client = FtRestClient(None)
1✔
69
    print("Possible commands:\n")
1✔
70
    for x, _ in inspect.getmembers(client):
1✔
71
        if not x.startswith('_'):
1✔
72
            doc = re.sub(':return:.*', '', getattr(client, x).__doc__, flags=re.MULTILINE).rstrip()
1✔
73
            print(f"{x}\n\t{doc}\n")
1✔
74

75

76
def main_exec(args: Dict[str, Any]):
1✔
77

78
    if args.get("show"):
1✔
79
        print_commands()
1✔
80
        sys.exit()
1✔
81

82
    config = load_config(args['config'])
1✔
83
    url = config.get('api_server', {}).get('listen_ip_address', '127.0.0.1')
1✔
84
    port = config.get('api_server', {}).get('listen_port', '8080')
1✔
85
    username = config.get('api_server', {}).get('username')
1✔
86
    password = config.get('api_server', {}).get('password')
1✔
87

88
    server_url = f"http://{url}:{port}"
1✔
89
    client = FtRestClient(server_url, username, password)
1✔
90

91
    m = [x for x, y in inspect.getmembers(client) if not x.startswith('_')]
1✔
92
    command = args["command"]
1✔
93
    if command not in m:
1✔
94
        logger.error(f"Command {command} not defined")
1✔
95
        print_commands()
1✔
96
        return
1✔
97

98
    print(json.dumps(getattr(client, command)(*args["command_arguments"])))
1✔
99

100

101
def main():
1✔
102
    """
103
    Main entry point for the client
104
    """
105
    args = add_arguments()
×
106
    main_exec(args)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc