Esempio n. 1
0
async def _get_tools(symbol="BTC/USDT"):
    config = test_config.load_test_config()
    config[commons_constants.CONFIG_SIMULATOR][commons_constants.CONFIG_STARTING_PORTFOLIO]["USDT"] = 1000
    exchange_manager = exchanges.ExchangeManager(config, "binance")
    exchange_manager.tentacles_setup_config = test_utils_config.get_tentacles_setup_config()

    # use backtesting not to spam exchanges apis
    exchange_manager.is_simulated = True
    exchange_manager.is_backtesting = True
    backtesting = await backtesting_api.initialize_backtesting(
        config,
        exchange_ids=[exchange_manager.id],
        matrix_id=None,
        data_files=[
            os.path.join(test_config.TEST_CONFIG_FOLDER, "AbstractExchangeHistoryCollector_1586017993.616272.data")])
    exchange_manager.exchange = exchanges.ExchangeSimulator(exchange_manager.config,
                                                            exchange_manager,
                                                            backtesting)
    await exchange_manager.exchange.initialize()
    for exchange_channel_class_type in [exchanges_channel.ExchangeChannel, exchanges_channel.TimeFrameExchangeChannel]:
        await channel_util.create_all_subclasses_channel(exchange_channel_class_type, exchanges_channel.set_chan,
                                                         exchange_manager=exchange_manager)

    trader = exchanges.TraderSimulator(config, exchange_manager)
    await trader.initialize()

    mode = Mode.DailyTradingMode(config, exchange_manager)
    await mode.initialize()
    # add mode to exchange manager so that it can be stopped and freed from memory
    exchange_manager.trading_modes.append(mode)

    # set BTC/USDT price at 1000 USDT
    trading_api.force_set_mark_price(exchange_manager, symbol, 1000)

    return mode.producers[0], mode.consumers[0], trader
Esempio n. 2
0
async def _get_tools(symbol, btc_holdings=None, additional_portfolio={}, fees=None):
    config = test_config.load_test_config()
    config[commons_constants.CONFIG_SIMULATOR][commons_constants.CONFIG_STARTING_PORTFOLIO]["USDT"] = 1000
    config[commons_constants.CONFIG_SIMULATOR][commons_constants.CONFIG_STARTING_PORTFOLIO][
        "BTC"] = 10 if btc_holdings is None else btc_holdings
    config[commons_constants.CONFIG_SIMULATOR][commons_constants.CONFIG_STARTING_PORTFOLIO].update(additional_portfolio)
    if fees is not None:
        config[commons_constants.CONFIG_SIMULATOR][commons_constants.CONFIG_SIMULATOR_FEES][
            commons_constants.CONFIG_SIMULATOR_FEES_TAKER] = fees
        config[commons_constants.CONFIG_SIMULATOR][commons_constants.CONFIG_SIMULATOR_FEES][
            commons_constants.CONFIG_SIMULATOR_FEES_MAKER] = fees
    exchange_manager = exchanges.ExchangeManager(config, "binance")
    exchange_manager.tentacles_setup_config = test_utils_config.get_tentacles_setup_config()

    # use backtesting not to spam exchanges apis
    exchange_manager.is_simulated = True
    exchange_manager.is_backtesting = True
    backtesting = await backtesting_api.initialize_backtesting(
        config,
        exchange_ids=[exchange_manager.id],
        matrix_id=None,
        data_files=[
            os.path.join(test_config.TEST_CONFIG_FOLDER, "AbstractExchangeHistoryCollector_1586017993.616272.data")])
    exchange_manager.exchange = exchanges.ExchangeSimulator(exchange_manager.config,
                                                            exchange_manager,
                                                            backtesting)
    await exchange_manager.exchange.initialize()
    for exchange_channel_class_type in [exchanges_channel.ExchangeChannel, exchanges_channel.TimeFrameExchangeChannel]:
        await channel_util.create_all_subclasses_channel(exchange_channel_class_type, exchanges_channel.set_chan,
                                                         exchange_manager=exchange_manager)

    trader = exchanges.TraderSimulator(config, exchange_manager)
    await trader.initialize()

    # set BTC/USDT price at 1000 USDT
    trading_api.force_set_mark_price(exchange_manager, symbol, 1000)

    mode, producer = await _init_trading_mode(config, exchange_manager, symbol)

    producer.flat_spread = decimal.Decimal(10)
    producer.flat_increment = decimal.Decimal(5)
    producer.buy_orders_count = 25
    producer.sell_orders_count = 25

    return producer, mode.consumers[0], exchange_manager
Esempio n. 3
0
async def exchange(exchange_name, backtesting=None, symbol="BTC/USDT"):
    exchange_manager = None
    try:
        config = test_config.load_test_config()
        config[commons_constants.CONFIG_SIMULATOR][
            commons_constants.CONFIG_STARTING_PORTFOLIO]["USDT"] = 2000
        exchange_manager = exchanges.ExchangeManager(config, exchange_name)
        exchange_manager.tentacles_setup_config = test_utils_config.get_tentacles_setup_config(
        )

        # use backtesting not to spam exchanges apis
        exchange_manager.is_simulated = True
        exchange_manager.is_backtesting = True
        backtesting = backtesting or await backtesting_api.initialize_backtesting(
            config,
            exchange_ids=[exchange_manager.id],
            matrix_id=None,
            data_files=[
                os.path.join(
                    test_config.TEST_CONFIG_FOLDER,
                    "AbstractExchangeHistoryCollector_1586017993.616272.data")
            ])

        exchange_manager.exchange = exchanges.ExchangeSimulator(
            exchange_manager.config, exchange_manager, backtesting)
        await exchange_manager.exchange.initialize()
        for exchange_channel_class_type in [
                exchanges_channel.ExchangeChannel,
                exchanges_channel.TimeFrameExchangeChannel
        ]:
            await channel_util.create_all_subclasses_channel(
                exchange_channel_class_type,
                exchanges_channel.set_chan,
                exchange_manager=exchange_manager)

        trader = exchanges.TraderSimulator(config, exchange_manager)
        await trader.initialize()

        mode = modes.ArbitrageTradingMode(config, exchange_manager)
        mode.symbol = None if mode.get_is_symbol_wildcard() else symbol
        await mode.initialize()
        # add mode to exchange manager so that it can be stopped and freed from memory
        exchange_manager.trading_modes.append(mode)

        # set BTC/USDT price at 1000 USDT
        trading_api.force_set_mark_price(exchange_manager, symbol, 1000)
        # force triggering_price_delta_ratio equivalent to a 0.2% setting in minimal_price_delta_percent
        delta_percent = 2
        mode.producers[
            0].inf_triggering_price_delta_ratio = 1 - delta_percent / 100
        mode.producers[
            0].sup_triggering_price_delta_ratio = 1 + delta_percent / 100
        yield mode.producers[0], mode.consumers[0], exchange_manager
    finally:
        if exchange_manager is not None:
            for importer in backtesting_api.get_importers(
                    exchange_manager.exchange.backtesting):
                await backtesting_api.stop_importer(importer)
            if exchange_manager.exchange.backtesting.time_updater is not None:
                await exchange_manager.exchange.backtesting.stop()
            await exchange_manager.stop()