[go: up one dir, main page]

Menu

[d23127]: / start.py  Maximize  Restore  History

Download this file

117 lines (85 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import argparse
import logging
import sys
import traceback
from logging.config import fileConfig
from config.config import load_config
from config.cst import *
from tools.commands import Commands
from interfaces.telegram.bot import TelegramApp
from services import WebService
def _log_uncaught_exceptions(ex_cls, ex, tb):
logging.exception(''.join(traceback.format_tb(tb)))
logging.exception('{0}: {1}'.format(ex_cls, ex))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='OctoBot')
parser.add_argument('start', help='start the OctoBot',
action='store_true')
parser.add_argument('-s', '--simulate', help='start the OctoBot with the trader simulator',
action='store_true')
parser.add_argument('-d', '--data_collector',
help='start the data collector process to create data for backtesting',
action='store_true')
parser.add_argument('-u', '--update', help='update OctoBot with the latest version available',
action='store_true')
parser.add_argument('-b', '--backtesting', help='enable the backtesting option and use the backtesting config',
action='store_true')
parser.add_argument('-r', '--risk', type=float, help='risk representation (between 0 and 1)')
parser.add_argument('-w', '--web', help='Start web server',
action='store_true')
parser.add_argument('-t', '--telegram', help='Start telegram command handler',
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. Use: -p help to get the '
'Tentacle Manager help.',
nargs='+')
parser.add_argument('-c', '--creator', help='Start OctoBot Tentacles Creator. examples: -c strategy test '
'to create a new strategy tentacles. Use: -c help to get the '
'Tentacle Creator help.',
nargs='+')
args = parser.parse_args()
fileConfig('config/logging_config.ini')
logger = logging.getLogger("OctoBot Launcher")
# Force new log file creation not to log at the previous one's end.
logger.parent.handlers[1].doRollover()
sys.excepthook = _log_uncaught_exceptions
# Version
logger.info("Version : {0}".format(LONG_VERSION))
logger.info("Loading config files...")
config = load_config()
# Handle utility methods before bot initializing if possible
if args.packager:
Commands.package_manager(config, args.packager)
elif args.creator:
Commands.tentacle_creator(config, args.creator)
elif args.update:
Commands.update(logger)
else:
# In those cases load OctoBot
from octobot import OctoBot
config[CONFIG_EVALUATOR] = load_config(CONFIG_EVALUATOR_FILE_PATH, False)
TelegramApp.enable(config, args.telegram)
WebService.enable(config, args.web)
bot = OctoBot(config)
import interfaces
interfaces.__init__(bot, config)
if args.data_collector:
Commands.data_collector(config)
# start crypto bot options
else:
if args.backtesting:
import backtesting
backtesting.__init__(bot)
config[CONFIG_BACKTESTING][CONFIG_ENABLED_OPTION] = True
config[CONFIG_CATEGORY_NOTIFICATION][CONFIG_ENABLED_OPTION] = False
config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True
if args.simulate:
config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True
if args.risk is not None and 0 < args.risk <= 1:
config[CONFIG_TRADER][CONFIG_TRADER_RISK] = args.risk
if args.start:
Commands.start_bot(bot, logger)