Exemple #1
0
    def test_enabled(self):
        config, _, trader_inst = self.init_default()
        self.stop(trader_inst)

        config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = True
        assert Trader.enabled(config)

        config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
        assert not Trader.enabled(config)
Exemple #2
0
    def test_enabled(self):
        config, _, trader_inst = self.init_default()
        self.stop(trader_inst)

        config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = True
        assert Trader.enabled(config)

        config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False
        assert not Trader.enabled(config)
 def init_default():
     config = load_test_config()
     exchange_manager = ExchangeManager(config,
                                        ccxt.binance,
                                        is_simulated=True)
     exchange_inst = exchange_manager.get_exchange()
     trader_inst = Trader(config, exchange_inst, 1)
     order_manager_inst = trader_inst.get_order_manager()
     return config, exchange_inst, trader_inst, order_manager_inst
 async def init_default():
     config = load_test_config()
     config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = True
     exchange_manager = ExchangeManager(config,
                                        ccxt.binance,
                                        is_simulated=True)
     await exchange_manager.initialize()
     exchange_inst = exchange_manager.get_exchange()
     trader_real_inst = Trader(config, exchange_inst, 1)
     trader_simulator_inst = TraderSimulator(config, exchange_inst, 1)
     order_manager_inst = trader_real_inst.get_order_manager()
     order_manager_simulator_inst = trader_simulator_inst.get_order_manager(
     )
     return config, exchange_inst, trader_real_inst, order_manager_inst, trader_simulator_inst, \
         order_manager_simulator_inst
Exemple #5
0
    def create_exchange_traders(self):
        self.backtesting_enabled = Backtesting.enabled(self.config)

        available_exchanges = ccxt.exchanges
        for exchange_class_string in self.config[CONFIG_EXCHANGES]:
            if exchange_class_string in available_exchanges:
                exchange_type = getattr(ccxt, exchange_class_string)

                # Backtesting Exchange
                if self.backtesting_enabled:
                    exchange_manager = ExchangeManager(self.config,
                                                       exchange_type,
                                                       is_simulated=True)
                else:
                    # True Exchange
                    exchange_manager = ExchangeManager(self.config,
                                                       exchange_type,
                                                       is_simulated=False)

                exchange_inst = exchange_manager.get_exchange()
                self.exchanges_list[exchange_inst.get_name()] = exchange_inst

                # create trader instance for this exchange
                exchange_trader = Trader(self.config, exchange_inst)
                self.exchange_traders[
                    exchange_inst.get_name()] = exchange_trader

                # create trader simulator instance for this exchange
                exchange_trader_simulator = TraderSimulator(
                    self.config, exchange_inst)
                self.exchange_trader_simulators[
                    exchange_inst.get_name()] = exchange_trader_simulator
            else:
                self.logger.error(
                    "{0} exchange not found".format(exchange_class_string))
Exemple #6
0
    def test_get_risk(self):
        config, exchange_inst, trader_inst = self.init_default()
        self.stop(trader_inst)

        config[CONFIG_TRADER][CONFIG_TRADER_RISK] = 0
        trader_1 = Trader(config, exchange_inst)
        assert trader_1.get_risk() == CONFIG_TRADER_RISK_MIN
        self.stop(trader_1)

        config[CONFIG_TRADER][CONFIG_TRADER_RISK] = 2
        trader_2 = Trader(config, exchange_inst)
        assert trader_2.get_risk() == CONFIG_TRADER_RISK_MAX
        self.stop(trader_2)

        config[CONFIG_TRADER][CONFIG_TRADER_RISK] = 0.5
        trader_2 = Trader(config, exchange_inst)
        assert trader_2.get_risk() == 0.5
        self.stop(trader_2)
Exemple #7
0
    def create_exchange_traders(self):
        for exchange_type in self.exchanges:
            exchange_inst = Exchange(self.config, exchange_type)

            # create trader instance for this exchange
            exchange_trader = Trader(self.config, exchange_inst)
            exchange_trader_simulator = TraderSimulator(
                self.config, exchange_inst)

            self.exchanges_list[exchange_type.__name__] = exchange_inst
            self.exchange_traders[exchange_type.__name__] = exchange_trader
            self.exchange_trader_simulators[
                exchange_type.__name__] = exchange_trader_simulator
Exemple #8
0
    def create_exchange_traders(self):
        available_exchanges = ccxt.exchanges
        for exchange_class_string in self.config[CONFIG_EXCHANGES]:
            if exchange_class_string in available_exchanges:
                exchange_type = getattr(ccxt, exchange_class_string)

                # Backtesting Exchange
                if self.backtesting_enabled:
                    exchange_manager = ExchangeManager(self.config,
                                                       exchange_type,
                                                       is_simulated=True)
                else:
                    # Real Exchange
                    exchange_manager = ExchangeManager(self.config,
                                                       exchange_type,
                                                       is_simulated=False)

                exchange_inst = exchange_manager.get_exchange()
                self.exchanges_list[exchange_inst.get_name()] = exchange_inst

                # create trader instance for this exchange
                exchange_trader = Trader(self.config, exchange_inst)
                self.exchange_traders[
                    exchange_inst.get_name()] = exchange_trader

                # create trader simulator instance for this exchange
                exchange_trader_simulator = TraderSimulator(
                    self.config, exchange_inst)
                self.exchange_trader_simulators[
                    exchange_inst.get_name()] = exchange_trader_simulator

                # create trading mode
                try:
                    self.trading_mode = get_activated_trading_mode(
                        self.config)(self.config, exchange_inst)
                    self.exchange_trading_modes[
                        exchange_inst.get_name()] = self.trading_mode
                    self.logger.debug(
                        f"Using {self.trading_mode.get_name()} trading mode")
                except RuntimeError as e:
                    self.logger.error(e.args[0])
                    raise e
            else:
                self.logger.error(
                    f"{exchange_class_string} exchange not found")
Exemple #9
0
 def init_default():
     config = load_test_config()
     exchange_inst = ExchangeSimulator(config, ccxt.binance)
     trader_inst = Trader(config, exchange_inst)
     order_manager_inst = trader_inst.get_order_manager()
     return config, exchange_inst, trader_inst, order_manager_inst
Exemple #10
0
    async def create_exchange_traders(self, ignore_config=False):
        self.async_loop = asyncio.get_running_loop()
        available_exchanges = ccxt.exchanges
        for exchange_class_string in self.config[CONFIG_EXCHANGES]:
            if exchange_class_string in available_exchanges:
                exchange_type = getattr(ccxt, exchange_class_string)

                # Backtesting Exchange
                if self.backtesting_enabled:
                    exchange_manager = ExchangeManager(self.config,
                                                       exchange_type,
                                                       is_simulated=True)
                else:
                    # Real Exchange
                    exchange_manager = ExchangeManager(
                        self.config,
                        exchange_type,
                        is_simulated=False,
                        ignore_config=ignore_config)
                await exchange_manager.initialize()

                exchange_inst = exchange_manager.get_exchange()
                self.exchanges_list[exchange_inst.get_name()] = exchange_inst
                self.global_updaters_by_exchange[exchange_inst.get_name(
                )] = GlobalPriceUpdater(exchange_inst)

                # create trader instance for this exchange
                exchange_trader = Trader(self.config, exchange_inst)
                await exchange_trader.initialize()
                self.exchange_traders[
                    exchange_inst.get_name()] = exchange_trader

                # create trader simulator instance for this exchange
                exchange_trader_simulator = TraderSimulator(
                    self.config, exchange_inst)
                await exchange_trader_simulator.initialize()
                self.exchange_trader_simulators[
                    exchange_inst.get_name()] = exchange_trader_simulator

                if not (exchange_trader_simulator.enabled(self.config)
                        or exchange_trader.enabled(self.config)):
                    self.logger.error(
                        f"No trader simulator nor real trader activated on {exchange_inst.get_name()}"
                    )

                # create trading mode
                try:
                    self.trading_mode = get_activated_trading_mode(
                        self.config)(self.config, exchange_inst)
                    self.exchange_trading_modes[
                        exchange_inst.get_name()] = self.trading_mode
                    self.logger.debug(
                        f"Using {self.trading_mode.get_name()} trading mode")
                except RuntimeError as e:
                    self.logger.error(e.args[0])
                    raise e

                # register trading modes on traders
                exchange_trader.register_trading_mode(self.trading_mode)
                exchange_trader_simulator.register_trading_mode(
                    self.trading_mode)
            else:
                self.logger.error(
                    f"{exchange_class_string} exchange not found")
 def init_default():
     config = load_test_config()
     exchange_inst = ExchangeSimulator(config, ccxt.binance)
     trader_inst = Trader(config, exchange_inst)
     trades_manager_inst = trader_inst.get_trades_manager()
     return config, exchange_inst, trader_inst, trades_manager_inst