Ejemplo n.º 1
0
def _set_exchange_type_details(exchange_builder, config, backtesting):
    # real, simulator, backtesting
    if util.is_trader_enabled(config):
        exchange_builder.is_real()
    elif util.is_trader_simulator_enabled(config):
        exchange_builder.is_simulated()
    if backtesting is not None:
        exchange_builder.is_backtesting(backtesting)
    # use exchange sandbox
    exchange_builder.is_sandboxed(config[commons_constants.CONFIG_EXCHANGES][
        exchange_builder.exchange_name].get(
            commons_constants.CONFIG_EXCHANGE_SANDBOXED, False))
    # exchange trading type
    if config[commons_constants.CONFIG_EXCHANGES][
            exchange_builder.exchange_name].get(
                commons_constants.CONFIG_EXCHANGE_FUTURE, False):
        exchange_builder.is_future(True)
    elif config[commons_constants.CONFIG_EXCHANGES][
            exchange_builder.exchange_name].get(
                commons_constants.CONFIG_EXCHANGE_MARGIN, False):
        exchange_builder.is_margin(True)
    elif config[commons_constants.CONFIG_EXCHANGES][
            exchange_builder.exchange_name].get(
                commons_constants.CONFIG_EXCHANGE_SPOT, True):
        # Use spot trading as default trading type
        exchange_builder.is_spot_only(True)

    # rest, web socket
    if config[commons_constants.CONFIG_EXCHANGES][
            exchange_builder.exchange_name].get(
                commons_constants.CONFIG_EXCHANGE_REST_ONLY, False):
        exchange_builder.is_rest_only()
Ejemplo n.º 2
0
    async def _build_trader(self):
        try:
            # check traders activation
            if not util.is_trader_enabled(self.config) and not util.is_trader_simulator_enabled(self.config):
                raise ValueError(f"No trader simulator nor real trader activated on "
                                 f"{self.exchange_manager.exchange_name}")

            await self.exchange_manager.trader.initialize()
        except ValueError as e:
            self.logger.error(f"An error occurred when creating trader : {e}")
            raise e
Ejemplo n.º 3
0
    def __init__(self, config, exchange_class_string):
        super().__init__()
        self.id = str(uuid.uuid4())
        self.config = config
        self.tentacles_setup_config = None
        self.exchange_class_string = exchange_class_string
        self.exchange_name = exchange_class_string
        self.logger = logging.get_logger(self.__class__.__name__)

        self.is_ready = False
        self.is_simulated: bool = False
        self.is_backtesting: bool = False
        self.rest_only: bool = False
        self.ignore_config: bool = False
        self.is_collecting: bool = False
        self.is_spot_only: bool = False
        self.is_margin: bool = False
        self.is_future: bool = False
        self.is_sandboxed: bool = False
        self.is_trading: bool = True
        self.without_auth: bool = False

        # exchange_only is True when exchange channels are not required (therefore not created)
        self.exchange_only: bool = False

        self.backtesting = None

        self.is_trader_simulated = util.is_trader_simulator_enabled(self.config)
        self.has_websocket = False

        self.trader = None
        self.exchange = None
        self.exchange_backend = None
        self.is_valid_account = True
        self.community_authenticator = None
        self.trading_modes = []

        self.exchange_web_socket = None

        self.client_symbols = []
        self.client_time_frames = []

        self.exchange_config = exchanges.ExchangeConfig(self)
        self.exchange_personal_data = personal_data.ExchangePersonalData(self)
        self.exchange_symbols_data = exchange_data.ExchangeSymbolsData(self)
    def __init__(self, config, exchange_class_string):
        super().__init__()
        self.id = str(uuid.uuid4())
        self.config = config
        self.exchange_class_string = exchange_class_string
        self.exchange_name = exchange_class_string
        self._logger = get_logger(self.__class__.__name__)

        self.is_ready = False
        self.is_simulated: bool = False
        self.is_backtesting: bool = False
        self.rest_only: bool = False
        self.ignore_config: bool = False
        self.is_collecting: bool = False
        self.is_spot_only: bool = False
        self.is_margin: bool = False
        self.is_future: bool = False
        self.is_sandboxed: bool = False

        # exchange_only is True when exchange channels are not required (therefore not created)
        self.exchange_only: bool = False

        self.backtesting_files: list = None

        self.is_trader_simulated = is_trader_simulator_enabled(self.config)
        self.has_websocket = False

        self.trader = None
        self.exchange = None
        self.trading_modes = []

        self.exchange_web_socket = None
        self.exchange_type = None

        self.client_symbols = []
        self.client_time_frames = []

        self.exchange_config = ExchangeConfig(self)
        self.exchange_personal_data = ExchangePersonalData(self)
        self.exchange_symbols_data = ExchangeSymbolsData(self)
Ejemplo n.º 5
0
    def __init__(self,
                 config,
                 exchange_class_string,
                 is_simulated=False,
                 is_backtesting=False,
                 rest_only=False,
                 ignore_config=False,
                 is_collecting=False,
                 exchange_only=False,
                 backtesting_files=None):
        super().__init__()
        self.id = str(uuid.uuid4())
        self.config = config
        self.exchange_class_string = exchange_class_string
        self.rest_only = rest_only
        self.ignore_config = ignore_config
        self.backtesting_files = backtesting_files
        self._logger = get_logger(self.__class__.__name__)

        self.is_ready = False
        self.is_backtesting = is_backtesting
        self.is_simulated = is_simulated
        self.is_collecting = is_collecting
        self.exchange_only = exchange_only
        self.is_trader_simulated = is_trader_simulator_enabled(self.config)
        self.has_websocket = False

        self.trader = None
        self.exchange = None

        self.exchange_web_socket = None
        self.exchange_type = None

        self.client_symbols = []
        self.client_time_frames = {}

        self.exchange_config = ExchangeConfig(self)
        self.exchange_personal_data = ExchangePersonalData(self)
        self.exchange_symbols_data = ExchangeSymbolsData(self)
    async def create(self, trading_tentacles_path=CONFIG_TRADING_FILE_PATH):
        await self.exchange_manager.initialize()

        # set sandbox mode
        if not self.is_backtesting:
            self.exchange_manager.exchange.client.setSandboxMode(
                self.is_sandboxed)

        if not self.is_simulated:
            self.trader = Trader(self.config, self.exchange_manager)
        else:
            self.trader = TraderSimulator(self.config, self.exchange_manager)

        try:
            # check traders activation
            if not is_trader_enabled(
                    self.config) and not is_trader_simulator_enabled(
                        self.config):
                raise ValueError(
                    f"No trader simulator nor real trader activated on {self.exchange_manager.exchange.name}"
                )

            # initialize trader
            await self.trader.initialize()
            self.exchange_manager.trader = self.trader

            init_trading_mode_config(self.config, trading_tentacles_path)
            await create_trading_mode(self.config, self.exchange_manager)

            # add to global exchanges
            Exchanges.instance().add_exchange(self.exchange_manager)
        except Exception as e:
            self.logger.error(
                f"An error occurred when creating trader or initializing trading mode : "
            )
            raise e
 def get_enabled_trader(profile):
     if is_real_trading(profile):
         return "Real trading"
     if trading_util.is_trader_simulator_enabled(profile.config):
         return "Simulated trading"
     return ""
Ejemplo n.º 8
0
def is_trader_simulator_enabled_in_config(config) -> bool:
    return util.is_trader_simulator_enabled(config)
Ejemplo n.º 9
0
 def enabled(config):
     return is_trader_simulator_enabled(config)