[go: up one dir, main page]

Menu

[cc83e9]: / core / octobot.py  Maximize  Restore  History

Download this file

138 lines (104 with data), 4.6 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Drakkar-Software OctoBot
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import copy
import time
import aiohttp
from config import BOT_TOOLS_RECORDER, BOT_TOOLS_STRATEGY_OPTIMIZER, BOT_TOOLS_BACKTESTING
from core.evaluator_factory import EvaluatorFactory
from core.exchange_factory import ExchangeFactory
from core.initializer import Initializer
from core.task_manager import TaskManager
from tools.logging.logging_util import get_logger
"""Main OctoBot class:
- Create all indicators and thread for each cryptocurrencies in config """
class OctoBot:
"""
Constructor :
- Load configs
"""
def __init__(self, config, ignore_config=False, reset_trading_history=False):
self.start_time = time.time()
self.config = config
self.reset_trading_history = reset_trading_history
self.startup_config = copy.deepcopy(config)
self.edited_config = copy.deepcopy(config)
# tools: used for alternative operations on a bot on the fly (ex: backtesting started from web interface)
self.tools = {
BOT_TOOLS_BACKTESTING: None,
BOT_TOOLS_STRATEGY_OPTIMIZER: None,
BOT_TOOLS_RECORDER: None,
}
# unique aiohttp session: to be initialized from getter in a task
self._aiohttp_session = None
# metrics if enabled
self.metrics_handler = None
# Logger
self.logger = get_logger(self.__class__.__name__)
self.initializer = Initializer(self)
self.task_manager = TaskManager(self)
self.exchange_factory = ExchangeFactory(self, ignore_config=ignore_config)
self.evaluator_factory = EvaluatorFactory(self)
async def initialize(self):
await self.initializer.create()
self.task_manager.init_async_loop()
await self.exchange_factory.create()
self.evaluator_factory.create()
async def start(self, run_in_new_thread=False):
await self.task_manager.start_tasks(run_in_new_thread=run_in_new_thread)
def stop(self):
self.task_manager.stop_threads()
def run_in_main_asyncio_loop(self, coroutine):
return self.task_manager.run_in_main_asyncio_loop(coroutine)
def set_watcher(self, watcher):
self.task_manager.watcher = watcher
def get_symbols_tasks_manager(self):
return self.evaluator_factory.symbol_tasks_manager
def get_exchange_traders(self):
return self.exchange_factory.exchange_traders
def get_exchange_trader_simulators(self):
return self.exchange_factory.exchange_trader_simulators
def get_exchange_trading_modes(self):
return self.exchange_factory.exchange_trading_modes
def get_exchanges_list(self):
return self.exchange_factory.exchanges_list
def get_symbol_evaluator_list(self):
return self.evaluator_factory.symbol_evaluator_list
def get_symbols_list(self):
return self.evaluator_factory.symbol_evaluator_list.keys()
def get_crypto_currency_evaluator_list(self):
return self.evaluator_factory.crypto_currency_evaluator_list
def get_dispatchers_list(self):
return self.evaluator_factory.dispatchers_list
def get_global_updaters_by_exchange(self):
return self.exchange_factory.global_updaters_by_exchange
def get_trading_mode(self):
return self.exchange_factory.trading_mode
def is_ready(self):
return self.task_manager.ready
def get_config(self):
return self.config
def get_tools(self):
return self.tools
def get_time_frames(self):
return self.initializer.time_frames
def get_relevant_evaluators(self):
return self.initializer.relevant_evaluators
def get_async_loop(self):
return self.task_manager.async_loop
def get_aiohttp_session(self):
if self._aiohttp_session is None:
self._aiohttp_session = aiohttp.ClientSession()
return self._aiohttp_session