refactor argparse handling
This commit is contained in:
parent
5be7be6189
commit
b682262486
@ -2,6 +2,7 @@
|
|||||||
import copy
|
import copy
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@ -14,8 +15,9 @@ from jsonschema import validate
|
|||||||
|
|
||||||
from freqtrade import __version__, exchange, persistence
|
from freqtrade import __version__, exchange, persistence
|
||||||
from freqtrade.analyze import get_signal, SignalType
|
from freqtrade.analyze import get_signal, SignalType
|
||||||
|
from freqtrade.misc import CONF_SCHEMA, State, get_state, update_state, parse_args, throttle
|
||||||
from freqtrade.misc import (
|
from freqtrade.misc import (
|
||||||
CONF_SCHEMA, State, get_state, update_state, build_arg_parser, throttle, FreqtradeException
|
FreqtradeException
|
||||||
)
|
)
|
||||||
from freqtrade.persistence import Trade
|
from freqtrade.persistence import Trade
|
||||||
from freqtrade.rpc import telegram
|
from freqtrade.rpc import telegram
|
||||||
@ -316,11 +318,8 @@ def main():
|
|||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
global _CONF
|
global _CONF
|
||||||
args = build_arg_parser().parse_args()
|
args = parse_args(sys.argv[1:])
|
||||||
|
if not args:
|
||||||
# Check if subcommand has been selected
|
|
||||||
if hasattr(args, 'func'):
|
|
||||||
args.func(args)
|
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
# Initialize logger
|
# Initialize logger
|
||||||
|
@ -3,7 +3,7 @@ import enum
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable, List
|
||||||
|
|
||||||
from wrapt import synchronized
|
from wrapt import synchronized
|
||||||
|
|
||||||
@ -62,8 +62,11 @@ def throttle(func: Callable[..., Any], min_secs: float, *args, **kwargs) -> Any:
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def build_arg_parser() -> argparse.ArgumentParser:
|
def parse_args(args: List[str]):
|
||||||
""" Builds and returns an ArgumentParser instance """
|
"""
|
||||||
|
Parses given arguments and returns an argparse Namespace instance.
|
||||||
|
Returns None if a sub command has been selected and executed.
|
||||||
|
"""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Simple High Frequency Trading Bot for crypto currencies'
|
description='Simple High Frequency Trading Bot for crypto currencies'
|
||||||
)
|
)
|
||||||
@ -94,7 +97,14 @@ def build_arg_parser() -> argparse.ArgumentParser:
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
)
|
)
|
||||||
build_subcommands(parser)
|
build_subcommands(parser)
|
||||||
return parser
|
parsed_args = parser.parse_args(args)
|
||||||
|
|
||||||
|
# No subcommand as been selected
|
||||||
|
if not hasattr(parsed_args, 'func'):
|
||||||
|
return parsed_args
|
||||||
|
|
||||||
|
parsed_args.func(parsed_args)
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def build_subcommands(parser: argparse.ArgumentParser) -> None:
|
def build_subcommands(parser: argparse.ArgumentParser) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user