Example #1
0
async def _handle_creation(bot_id, action, data):
    if action == OctoBotChannelTradingActions.EXCHANGE.value:
        try:
            exchange_name = data.get(
                OctoBotChannelTradingDataKeys.EXCHANGE_NAME.value, None)
            config = data[OctoBotChannelTradingDataKeys.EXCHANGE_CONFIG.value]
            exchange_builder = exchanges.create_exchange_builder_instance(config, exchange_name) \
                .has_matrix(data[OctoBotChannelTradingDataKeys.MATRIX_ID.value]) \
                .use_tentacles_setup_config(data[OctoBotChannelTradingDataKeys.TENTACLES_SETUP_CONFIG.value]) \
                .set_bot_id(bot_id)
            _set_exchange_type_details(
                exchange_builder, config,
                data[OctoBotChannelTradingDataKeys.BACKTESTING.value])
            await exchange_builder.build()
            await channel_instances.get_chan_at_id(channels_name.OctoBotChannelsName.OCTOBOT_CHANNEL.value,
                                                   bot_id).get_internal_producer() \
                .send(bot_id=bot_id,
                      subject=enums.OctoBotChannelSubjects.NOTIFICATION.value,
                      action=action,
                      data={OctoBotChannelTradingDataKeys.EXCHANGE_ID.value: exchange_builder.exchange_manager.id})
        except errors.TradingModeIncompatibility as e:
            logging.get_logger(
                OCTOBOT_CHANNEL_TRADING_CONSUMER_LOGGER_TAG
            ).error(
                f"Error when initializing trading mode, {exchange_name} "
                f"exchange connection is closed to increase performances: {e}")
        except Exception as e:
            logging.get_logger(
                OCTOBOT_CHANNEL_TRADING_CONSUMER_LOGGER_TAG
            ).error(
                f"Error when creating a new {exchange_name} exchange connexion: {e.__class__.__name__} {e}"
            )
Example #2
0
async def create_test_exchange_manager(
        config: object,
        exchange_name: str,
        is_spot_only: bool = True,
        is_margin: bool = False,
        is_future: bool = False,
        rest_only: bool = False,
        is_real: bool = True,
        is_sandboxed: bool = False) -> exchanges.ExchangeManager:
    builder = exchanges.create_exchange_builder_instance(config, exchange_name)
    builder.disable_trading_mode()
    builder.use_tentacles_setup_config(
        tentacles_manager_api.get_tentacles_setup_config())
    if is_spot_only:
        builder.is_spot_only()
    if is_margin:
        builder.is_margin()
    if is_future:
        builder.is_future()
    if rest_only:
        builder.is_rest_only()
    if is_sandboxed:
        builder.is_sandboxed(is_sandboxed)
    if is_real:
        builder.is_real()
    else:
        builder.is_simulated()
    await builder.build()
    return builder.exchange_manager
Example #3
0
def app():
    exchange_name = "binance"
    exchange_builder = exchanges.create_exchange_builder_instance(cli.get_config(), exchange_name) \
        .is_simulated() \
        .is_rest_only()

    cli.add_exchange(
        exchange_name, {
            "exchange_builder":
            exchange_builder,
            "exchange_thread":
            threading.Thread(target=cli_tools.start_cli_exchange,
                             args=(exchange_builder, ))
        })

    cli.get_exchange(exchange_name)["exchange_thread"].start()
Example #4
0
async def create_test_exchange_manager(
        config: object,
        exchange_name: str,
        is_spot_only: bool = True,
        is_margin: bool = False,
        is_future: bool = False,
        rest_only: bool = False,
        is_real: bool = True,
        is_sandboxed: bool = False,
        ignore_exchange_config: bool = True) -> exchanges.ExchangeManager:
    if ignore_exchange_config:
        # enable exchange name in config
        config[commons_constants.CONFIG_EXCHANGES][exchange_name] = {
            commons_constants.CONFIG_ENABLED_OPTION: True
        }

    builder = exchanges.create_exchange_builder_instance(config, exchange_name)
    builder.disable_trading_mode()
    builder.use_tentacles_setup_config(
        tentacles_manager_api.get_tentacles_setup_config())
    if is_spot_only:
        builder.is_spot_only()
    if is_margin:
        builder.is_margin()
    if is_future:
        builder.is_future()
    if rest_only:
        builder.is_rest_only()
    if is_sandboxed:
        builder.is_sandboxed(is_sandboxed)
    if is_real:
        builder.is_real()
    else:
        builder.is_simulated()
    await builder.build()
    return builder.exchange_manager
Example #5
0
def create_exchange_builder(config,
                            exchange_name) -> exchanges.ExchangeBuilder:
    return exchanges.create_exchange_builder_instance(config, exchange_name)