Octo Bot
Octo Bot
Octo Bot
import argparse
import asyncio
import logging
import os
import sys
import traceback
import webbrowser
import socket
from logging.config import fileConfig
from threading import Thread
from time import sleep
config[CONFIG_CATEGORY_NOTIFICATION][CONFIG_ENABLED_OPTION] = False
config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True
if starting_args.simulate:
config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True
def _check_public_announcements(logger):
try:
announcement =
get_external_resource(EXTERNAL_RESOURCE_PUBLIC_ANNOUNCEMENTS)
if announcement:
logger.info(announcement)
except Exception as e:
logger.warning("Impossible to check announcements: {0}".format(e))
webbrowser.open("http://{0}:
{1}".format(socket.gethostbyname(socket.gethostname()),
config[CONFIG_CATEGORY_SERVICES]
[CONFIG_WEB][CONFIG_WEB_PORT])
)
except webbrowser.Error as e:
logging.error("{0}, impossible to open automatically web
interface".format(e))
def start_octobot(starting_args):
try:
fileConfig(LOGGING_CONFIG_FILE)
except KeyError:
print("Error when loading logging config file, it might be missing or is
corrupted. File is: " +
LOGGING_CONFIG_FILE + " please make sure that this script is called
from its location directory.")
os._exit(-1)
# Force new log file creation not to log at the previous one's end.
try:
logger.parent.handlers[1].doRollover()
except IndexError:
print("Logfile rotation disabled: error when handling logging config.")
sys.excepthook = _log_uncaught_exceptions
try:
if starting_args.version:
print(LONG_VERSION)
else:
# Version
logger.info("Version : {0}".format(LONG_VERSION))
_check_public_announcements(logger)
# configuration loading
config = load_config(error=False, fill_missing_fields=True)
if config is None:
raise ConfigError
elif starting_args.creator:
Commands.tentacle_creator(config, starting_args.creator)
elif starting_args.encrypter:
Commands.exchange_keys_encrypter()
else:
if not tentacles_arch_exists():
logger.info("No tentacles found. Installing default
tentacles ...")
Commands.package_manager(config, ["install", "all"],
force=True)
ConfigManager.reload_tentacle_config(config)
if starting_args.data_collector:
Commands.data_collector(config)
elif starting_args.strategy_optimizer:
Commands.start_strategy_optimizer(config,
starting_args.strategy_optimizer)
else:
update_config_with_args(starting_args, config)
reset_trading_history = starting_args.reset_trading_history
bot = OctoBot(config,
reset_trading_history=reset_trading_history)
_log_terms_if_unaccepted(config, logger)
import interfaces
interfaces.__init__(bot, config)
except ModuleNotFoundError as e:
if 'tentacles' in str(e):
logger.error("Impossible to start OctoBot, tentacles are missing.\nTo
install tentacles, "
"please use the following command:\nstart.py -p install
all")
else:
logger.exception(e)
os._exit(-1)
except ConfigEvaluatorError:
logger.error("OctoBot can't start without a valid " +
CONFIG_EVALUATOR_FILE_PATH
+ " configuration file.\nThis file is generated on tentacle "
"installation using the following command:\nstart.py -p
install all")
os._exit(-1)
except ConfigTradingError:
logger.error("OctoBot can't start without a valid " +
CONFIG_TRADING_FILE_PATH
+ " configuration file.\nThis file is generated on tentacle "
"installation using the following command:\nstart.py -p
install all")
os._exit(-1)
def main(args=None):
if not args:
args = sys.argv[1:]
parser = argparse.ArgumentParser(description='OctoBot')
parser.add_argument('-v', '--version', help='Show OctoBot current version.',
action='store_true')
parser.add_argument('-s', '--simulate', help='Force OctoBot to start with the
trader simulator only.',
action='store_true')
parser.add_argument('-rts', '--reset-trading-history', help='Force the traders
to reset their history. They will '
'now take the next
portfolio as a reference for '
'profitability and
trading simulators will use a '
'fresh new
portfolio.',
action='store_true')
parser.add_argument('-d', '--data_collector',
help='Start the data collector process to store data for
backtesting.',
action='store_true')
parser.add_argument('-b', '--backtesting', help='Start OctoBot in backesting
mode using the backtesting '
'config stored in
config.json.',
action='store_true')
parser.add_argument('-ba', '--backtesting_analysis',
help='Additional argument in order not stop the bot at the
end of the backtesting '
'(useful to analyse results using interfaces like the
web interface).',
action='store_true')
parser.add_argument('-r', '--risk', type=float, help='Force a specific risk
configuration (between 0 and 1).')
parser.add_argument('-nw', '--no_web', help="Don't start OctoBot web
interface.",
action='store_true')
parser.add_argument('-no', '--no_open_web', help="Don't automatically open web
interface.",
action='store_true')
parser.add_argument('-nt', '--no-telegram', help='Start OctoBot without
telegram interface, even if telegram '
'credentials are in config.
Telegram interface is required to '
'listen to telegram signals
and discuss with OctoBot on telegram.',
action='store_true')
parser.add_argument('--encrypter', help="Start the exchange api keys encrypter.
This tool is useful to manually add"
" exchanges configuration in your
config.json without using any interface "
"(ie the web interface that handle
encryption automatically)",
action='store_true')
parser.add_argument('-p', '--packager', help='Start OctoBot Tentacles Manager.
examples: -p install all '
'to install all tentacles packages
and -p install [tentacle] to '
'install specific tentacle.
Tentacles Manager allows to install, '
'update, uninstall and reset
tentacles. You can specify github '
'branches using branch= parameter.
'
'You can also skip installation
confirm inputs by adding the force '
'parameter. Use: -p help to get
the '
'Tentacle Manager help.',
nargs='+')
args = parser.parse_args(args)
start_octobot(args)
if __name__ == '__main__':
main()