2017-11-07 16:54:44 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-02-04 09:21:16 +00:00
|
|
|
"""
|
|
|
|
Main Freqtrade bot script.
|
|
|
|
Read the documentation to know what cli arguments you need.
|
|
|
|
"""
|
2019-05-28 20:04:39 +00:00
|
|
|
|
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
|
2018-06-09 02:29:48 +00:00
|
|
|
from argparse import Namespace
|
2019-03-25 14:45:03 +00:00
|
|
|
from typing import List
|
2018-03-17 21:44:47 +00:00
|
|
|
|
2019-03-25 14:45:03 +00:00
|
|
|
from freqtrade import OperationalException
|
2018-02-04 09:21:16 +00:00
|
|
|
from freqtrade.arguments import Arguments
|
2019-03-25 14:45:03 +00:00
|
|
|
from freqtrade.configuration import set_loggers
|
|
|
|
from freqtrade.worker import Worker
|
|
|
|
|
2018-03-25 19:37:14 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger('freqtrade')
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2017-09-25 12:42:16 +00:00
|
|
|
|
2019-05-25 13:07:52 +00:00
|
|
|
def main(sysargv: List[str] = None) -> None:
|
2017-05-12 17:11:56 +00:00
|
|
|
"""
|
2018-02-04 09:21:16 +00:00
|
|
|
This function will initiate the bot and start the trading loop.
|
2017-09-08 13:51:00 +00:00
|
|
|
:return: None
|
|
|
|
"""
|
2019-05-29 17:46:46 +00:00
|
|
|
|
2017-11-20 21:15:19 +00:00
|
|
|
try:
|
2019-05-25 12:51:50 +00:00
|
|
|
set_loggers()
|
|
|
|
|
2019-05-06 15:27:05 +00:00
|
|
|
worker = None
|
|
|
|
return_code = 1
|
|
|
|
|
|
|
|
arguments = Arguments(
|
|
|
|
sysargv,
|
|
|
|
'Free, open source crypto trading bot'
|
|
|
|
)
|
|
|
|
args: Namespace = arguments.get_parsed_arg()
|
|
|
|
|
|
|
|
# A subcommand has been issued.
|
|
|
|
# Means if Backtesting or Hyperopt have been called we exit the bot
|
|
|
|
if hasattr(args, 'func'):
|
|
|
|
args.func(args)
|
|
|
|
# TODO: fetch return_code as returned by the command function here
|
|
|
|
return_code = 0
|
2019-05-28 20:25:19 +00:00
|
|
|
else:
|
|
|
|
# Load and run worker
|
|
|
|
worker = Worker(args)
|
|
|
|
worker.run()
|
2017-11-20 21:15:19 +00:00
|
|
|
|
2019-05-30 17:38:04 +00:00
|
|
|
except SystemExit as e:
|
|
|
|
return_code = e
|
2017-11-20 21:15:19 +00:00
|
|
|
except KeyboardInterrupt:
|
2018-02-24 16:33:08 +00:00
|
|
|
logger.info('SIGINT received, aborting ...')
|
2018-03-24 19:56:27 +00:00
|
|
|
return_code = 0
|
2018-06-07 19:35:57 +00:00
|
|
|
except OperationalException as e:
|
|
|
|
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!')
|
2017-11-20 21:15:19 +00:00
|
|
|
finally:
|
2019-03-22 20:41:48 +00:00
|
|
|
if worker:
|
2019-03-22 17:16:54 +00:00
|
|
|
worker.exit()
|
2018-03-24 19:56:27 +00:00
|
|
|
sys.exit(return_code)
|
2018-02-04 09:21:16 +00:00
|
|
|
|
|
|
|
|
2017-09-28 21:47:51 +00:00
|
|
|
if __name__ == '__main__':
|
2019-05-25 13:07:52 +00:00
|
|
|
main()
|