Ejemplo n.º 1
0
async def _handle_creation(bot_id, action, data):
    if action == OctoBotChannelTradingActions.EXCHANGE.value:
        try:
            config = data[OctoBotChannelTradingDataKeys.EXCHANGE_CONFIG.value]
            exchange_builder = create_exchange_builder(config,
                                                       data[OctoBotChannelTradingDataKeys.EXCHANGE_NAME.value]) \
                .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 get_chan_at_id(OctoBotChannelsName.OCTOBOT_CHANNEL.value, bot_id).get_internal_producer() \
                .send(bot_id=bot_id,
                      subject=OctoBotChannelSubjects.NOTIFICATION.value,
                      action=action,
                      data={OctoBotChannelTradingDataKeys.EXCHANGE_ID.value: exchange_builder.exchange_manager.id})
        except TradingModeIncompatibility as e:
            get_logger(OCTOBOT_CHANNEL_TRADING_CONSUMER_LOGGER_TAG).error(
                f"Error when initializing trading mode, {data[OctoBotChannelTradingDataKeys.EXCHANGE_NAME.value]} "
                f"exchange connection is closed to increase performances: {e}")
        except Exception as e:
            get_logger(OCTOBOT_CHANNEL_TRADING_CONSUMER_LOGGER_TAG).error(
                f"Error when creating new exchange: {e}")
Ejemplo n.º 2
0
async def _handle_creation(bot_id, action, data):
    if action == OctoBotChannelTradingActions.EXCHANGE.value:
        try:
            config = data[OctoBotChannelTradingDataKeys.EXCHANGE_CONFIG.value]
            exchange_builder = create_exchange_builder(config,
                                                       data[OctoBotChannelTradingDataKeys.EXCHANGE_NAME.value]) \
                .has_matrix(data[OctoBotChannelTradingDataKeys.MATRIX_ID.value]) \
                .use_tentacles_setup_config(data[OctoBotChannelTradingDataKeys.TENTACLES_SETUP_CONFIG.value]) \
                .set_bot_id(bot_id) \
                .is_rest_only()
            if is_trader_enabled_in_config(config):
                exchange_builder.is_real()
            elif is_trader_simulator_enabled_in_config(config):
                exchange_builder.is_simulated()
            backtesting = data[OctoBotChannelTradingDataKeys.BACKTESTING.value]
            if backtesting is not None:
                exchange_builder.is_backtesting(backtesting)
            await exchange_builder.build()
            await get_chan_at_id(OctoBotChannelsName.OCTOBOT_CHANNEL.value, bot_id).get_internal_producer() \
                .send(bot_id=bot_id,
                      subject=OctoBotChannelSubjects.NOTIFICATION.value,
                      action=action,
                      data={OctoBotChannelTradingDataKeys.EXCHANGE_ID.value: exchange_builder.exchange_manager.id})
        except Exception as e:
            get_logger(OCTOBOT_CHANNEL_TRADING_CONSUMER_LOGGER_TAG).error(f"Error when creating new exchange {e}")
Ejemplo n.º 3
0
    async def init_default():
        config = load_test_config()

        exchange_builder = create_exchange_builder(config, TestExchangeFactory.EXCHANGE_NAME) \
            .is_simulated() \
            .is_rest_only()

        return config, exchange_builder
Ejemplo n.º 4
0
async def exchange_builder(request):
    config = None
    exchange_name = "binance"
    if hasattr(request, "param"):
        config, exchange_name = request.param

    exchange_builder_instance = create_exchange_builder(config if config is not None else load_test_config(),
                                                        exchange_name).is_simulated().is_rest_only()
    yield exchange_builder_instance
    await exchange_builder_instance.exchange_manager.stop()
Ejemplo n.º 5
0
def app():
    exchange_name = "binance"
    exchange_builder = create_exchange_builder(get_config(), exchange_name) \
        .is_simulated() \
        .is_rest_only()

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

    get_exchange(exchange_name)["exchange_thread"].start()
Ejemplo n.º 6
0
def connect(exchange_name):
    if exchange_name not in exchanges:
        exchange_builder = create_exchange_builder(get_config(), exchange_name)

        exchanges[exchange_name] = {
            "exchange_builder":
            exchange_builder,
            "exchange_thread":
            Thread(target=start_cli_exchange, args=(exchange_builder, ))
        }

        exchanges[exchange_name]["exchange_thread"].start()
    else:
        click.echo("Already connected to this exchange", err=True)
        return
    click.echo(f"Connected to {exchange_name}")
Ejemplo n.º 7
0
            "ETH": 50,
            "USDT": 1000
        }
    },
    CONFIG_TRADING: {
        "multi-session-profitability": False,
        "reference-market": "BTC",
        "risk": 0.5
    },
    CONFIG_TIME_FRAME: {TimeFrames.ONE_MINUTE, TimeFrames.ONE_HOUR}
}

if __name__ == '__main__':
    fileConfig("logs/logging_config.ini")
    logging.info("starting...")

    print("** Welcome to OctoBot-Trading command line interface **")
    cli.set_config(config)
    cli.set_should_display_callbacks_logs(True)

    exchange_name = "binance"
    exchange_builder = create_exchange_builder(
        config, exchange_name).is_simulated().is_rest_only()

    add_exchange(exchange_name, {
        "exchange_builder": exchange_builder,
        "exchange_thread": None
    })

    start_cli_exchange(exchange_builder)
Ejemplo n.º 8
0
    },
    commons_constants.CONFIG_TRADING: {
        "multi-session-profitability": False,
        "reference-market": "BTC",
        "risk": 0.5
    },
    commons_constants.CONFIG_TIME_FRAME:
    {TimeFrames.ONE_MINUTE, TimeFrames.ONE_HOUR}
}

if __name__ == '__main__':
    fileConfig("logs/logging_config.ini")
    logging.info("starting...")

    print("** Welcome to OctoBot-Trading command line interface **")
    cli.set_config(config)
    cli.set_should_display_callbacks_logs(True)

    exchange_name = "binance"
    exchange_builder = create_exchange_builder(config, exchange_name).\
        is_simulated().\
        is_rest_only().\
        disable_trading_mode()

    add_exchange(exchange_name, {
        "exchange_builder": exchange_builder,
        "exchange_thread": None
    })

    start_cli_exchange(exchange_builder)
Ejemplo n.º 9
0
async def test_create_exchange_builder():
    exchange_builder = create_exchange_builder(load_test_config(), "binance")
    assert exchange_builder