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.
|
|
|
|
"""
|
2024-05-12 15:46:00 +00:00
|
|
|
|
2020-08-14 12:41:46 +00:00
|
|
|
import logging
|
2017-11-17 16:18:31 +00:00
|
|
|
import sys
|
2023-01-21 14:01:56 +00:00
|
|
|
from typing import Any, List, Optional
|
2020-08-14 12:41:46 +00:00
|
|
|
|
2020-09-28 17:39:41 +00:00
|
|
|
|
2019-05-28 20:04:39 +00:00
|
|
|
# check min. python version
|
2024-10-01 04:44:49 +00:00
|
|
|
if sys.version_info < (3, 10): # pragma: no cover
|
|
|
|
sys.exit("Freqtrade requires Python version >= 3.10")
|
2019-05-28 20:04:39 +00:00
|
|
|
|
2022-09-20 14:14:54 +00:00
|
|
|
from freqtrade import __version__
|
2020-01-26 12:41:04 +00:00
|
|
|
from freqtrade.commands import Arguments
|
2024-03-19 06:20:38 +00:00
|
|
|
from freqtrade.constants import DOCS_LINK
|
2024-03-19 05:58:29 +00:00
|
|
|
from freqtrade.exceptions import ConfigurationError, FreqtradeException, OperationalException
|
2020-08-14 12:41:46 +00:00
|
|
|
from freqtrade.loggers import setup_logging_pre
|
2024-10-05 09:30:17 +00:00
|
|
|
from freqtrade.system import asyncio_setup, gc_set_threshold
|
2019-03-25 14:45:03 +00:00
|
|
|
|
2018-03-25 19:37:14 +00:00
|
|
|
|
2024-05-12 15:46:00 +00:00
|
|
|
logger = logging.getLogger("freqtrade")
|
2018-01-15 08:35:11 +00:00
|
|
|
|
2017-09-25 12:42:16 +00:00
|
|
|
|
2023-01-21 14:01:56 +00:00
|
|
|
def main(sysargv: Optional[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
|
|
|
|
2019-05-30 18:00:16 +00:00
|
|
|
return_code: Any = 1
|
2017-11-20 21:15:19 +00:00
|
|
|
try:
|
2020-08-14 12:41:46 +00:00
|
|
|
setup_logging_pre()
|
2024-08-08 18:20:14 +00:00
|
|
|
asyncio_setup()
|
2019-09-04 14:38:33 +00:00
|
|
|
arguments = Arguments(sysargv)
|
2019-09-12 18:16:39 +00:00
|
|
|
args = arguments.get_parsed_arg()
|
2019-05-06 15:27:05 +00:00
|
|
|
|
2019-09-14 09:19:08 +00:00
|
|
|
# Call subcommand.
|
2024-05-12 15:46:00 +00:00
|
|
|
if "func" in args:
|
|
|
|
logger.info(f"freqtrade {__version__}")
|
2022-11-12 14:39:54 +00:00
|
|
|
gc_set_threshold()
|
2024-05-12 15:46:00 +00:00
|
|
|
return_code = args["func"](args)
|
2019-09-16 04:35:37 +00:00
|
|
|
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`."
|
2021-08-06 22:19:36 +00:00
|
|
|
)
|
2017-11-20 21:15:19 +00:00
|
|
|
|
2021-09-05 13:40:21 +00:00
|
|
|
except SystemExit as e: # pragma: no cover
|
2019-05-30 17:38:04 +00:00
|
|
|
return_code = e
|
2017-11-20 21:15:19 +00:00
|
|
|
except KeyboardInterrupt:
|
2024-05-12 15:46:00 +00:00
|
|
|
logger.info("SIGINT received, aborting ...")
|
2018-03-24 19:56:27 +00:00
|
|
|
return_code = 0
|
2024-03-19 05:58:29 +00:00
|
|
|
except ConfigurationError as e:
|
2024-05-12 15:46:00 +00:00
|
|
|
logger.error(
|
|
|
|
f"Configuration error: {e}\n"
|
|
|
|
f"Please make sure to review the documentation at {DOCS_LINK}."
|
|
|
|
)
|
2019-12-30 14:11:07 +00:00
|
|
|
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:
|
2024-05-12 15:46:00 +00:00
|
|
|
logger.exception("Fatal exception!")
|
2017-11-20 21:15:19 +00:00
|
|
|
finally:
|
2018-03-24 19:56:27 +00:00
|
|
|
sys.exit(return_code)
|
2018-02-04 09:21:16 +00:00
|
|
|
|
|
|
|
|
2024-05-12 15:46:00 +00:00
|
|
|
if __name__ == "__main__": # pragma: no cover
|
2019-05-25 13:07:52 +00:00
|
|
|
main()
|