stable/freqtrade/main.py

64 lines
1.7 KiB
Python
Raw Normal View History

2017-11-07 16:54:44 +00:00
#!/usr/bin/env python3
"""
Main Freqtrade bot script.
Read the documentation to know what cli arguments you need.
"""
2019-05-28 20:04:39 +00:00
from freqtrade.exceptions import FreqtradeException, OperationalException
2017-11-17 16:18:31 +00:00
import sys
2019-05-28 20:04:39 +00:00
# check min. python version
if sys.version_info < (3, 6):
sys.exit("Freqtrade requires Python version >= 3.6")
# flake8: noqa E402
import logging
2019-05-30 18:00:16 +00:00
from typing import Any, List
2018-03-17 21:44:47 +00:00
from freqtrade.commands import Arguments
2019-03-25 14:45:03 +00:00
2018-03-25 19:37:14 +00:00
logger = logging.getLogger('freqtrade')
2018-01-15 08:35:11 +00:00
def main(sysargv: List[str] = None) -> None:
2017-05-12 17:11:56 +00:00
"""
This function will initiate the bot and start the trading loop.
:return: None
"""
2019-05-29 17:46:46 +00:00
2019-05-30 18:00:16 +00:00
return_code: Any = 1
try:
2019-09-04 14:38:33 +00:00
arguments = Arguments(sysargv)
args = arguments.get_parsed_arg()
2019-05-06 15:27:05 +00:00
# Call subcommand.
if 'func' in args:
return_code = args['func'](args)
else:
# No subcommand was issued.
raise OperationalException(
2019-11-13 09:03:59 +00:00
"Usage of Freqtrade requires a subcommand to be specified.\n"
2020-02-14 00:05:07 +00:00
"To have the bot executing trades in live/dry-run modes, "
"depending on the value of the `dry_run` setting in the config, run Freqtrade "
2019-11-13 09:03:59 +00:00
"as `freqtrade trade [options...]`.\n"
"To see the full list of options available, please use "
"`freqtrade --help` or `freqtrade <command> --help`."
)
2019-05-30 17:38:04 +00:00
except SystemExit as e:
return_code = e
except KeyboardInterrupt:
2018-02-24 16:33:08 +00:00
logger.info('SIGINT received, aborting ...')
return_code = 0
except FreqtradeException as e:
2018-06-07 19:35:57 +00:00
logger.error(str(e))
return_code = 2
2019-05-30 17:38:04 +00:00
except Exception:
2019-05-24 01:04:07 +00:00
logger.exception('Fatal exception!')
finally:
sys.exit(return_code)
2017-09-28 21:47:51 +00:00
if __name__ == '__main__':
main()