Beispiel #1
0
    def test_create_btc_bot(self):
        """ tests storing and querying a bot that trades with btc as quote asset. """
        session = get_session()
        self.assertEqual(len(session.query(Models.Bot).all()), 0)
        
        # Create ADABOT
        adabot = Models.Bot(
                    name="ada_test_bot",
                    quote_asset = 'BTC',
                    starting_balance = 1,
                    current_balance = 1,
                    profit_target = 2,
                    test_run=True
                    )

        session.add(adabot)
        session.commit()
        self.assertEqual(len(session.query(Models.Bot).all()), 1)

        adabot = session.query(Models.Bot).filter_by(name="ada_test_bot").first()
        self.assertEqual(adabot.test_run, True)
        self.assertEqual(adabot.quote_asset, 'BTC')
        self.assertEqual(adabot.starting_balance, 1)
        self.assertEqual(adabot.current_balance, 1)
        self.assertEqual(adabot.profit_target, 2)
        self.assertEqual(adabot.profit_loss, 100)  
Beispiel #2
0
    def setUp(self):

        self.exchange = Binance()
        self.df_BTCUSD_1k = pd.read_csv('./tests/data/BTCUSD_1m_1k.csv')
        self.df_BTCUSD_10k = pd.read_csv('./tests/data/BTCUSD_1m_10k.csv')
        self.df_ADABTC_1k = pd.read_csv('./tests/data/ADABTC_1m_1k.csv')

        # define bot params
        self.bot_name = 'ada_test_bot'
        self.bot_id = 1
        self.starting_balance = 2
        self.current_balance = 3
        self.profit_target = 4
        self.test_run = True
        self.quote_asset = 'BTC'

        # define pair params
        self.pair_id_ada = 2
        self.symbol_ada = 'ADABTC'
        self.profit_loss_ada = 5

        self.pair_id_eth = 3
        self.symbol_eth = 'ETHBTC'
        self.profit_loss_eth = 6

        # define order params
        self.order_1_id = 1
        self.order_2_id = 2
        self.order_symbol = self.symbol_eth
        self.entry_price = 2
        self.original_quantity = 3
        self.executed_quantity = 4
        self.status = 'NEW'
        self.is_closed = True
        self.side = 'BUY'
        self.is_test = True

        self.session = get_session()
        self.assertEqual(len(self.session.query(Bot).all()), 0)

        # Create bot
        bot = Bot(
            id=self.bot_id,
            name=self.bot_name,
            quote_asset=self.quote_asset,
            starting_balance=self.starting_balance,
            current_balance=self.current_balance,
            profit_target=self.profit_target,
            test_run=self.test_run,
        )

        # Create ETHBTC pair
        ethpair = Pair(
            id=self.pair_id_eth,
            bot_id=self.bot_id,
            symbol=self.symbol_eth,
            profit_loss=self.profit_loss_eth,
        )
        # Create ADABTC pair
        adapair = Pair(
            id=self.pair_id_ada,
            bot_id=self.bot_id,
            symbol=self.symbol_ada,
            profit_loss=self.profit_loss_ada,
        )

        # Create ethereum buy order
        eth_order = Order(
            id=self.order_1_id,
            bot_id=self.bot_id,
            symbol=self.order_symbol,
            entry_price=self.entry_price,
            original_quantity=self.original_quantity,
            executed_quantity=self.executed_quantity,
            status=self.status,
            side=self.side,
            is_test=self.is_test,
        )

        eth_order_closed = Order(
            id=self.order_2_id,
            bot_id=self.bot_id,
            symbol=self.order_symbol,
            entry_price=self.entry_price,
            original_quantity=self.original_quantity,
            executed_quantity=self.executed_quantity,
            is_closed=self.is_closed,
            status=self.status,
            side=self.side,
            is_test=self.is_test,
        )
        self.session.add(bot)
        self.session.add(adapair)
        self.session.add(ethpair)
        self.session.add(eth_order)
        self.session.add(eth_order_closed)
        self.session.commit()

        self.bot = self.session.query(Bot).filter_by(
            name=self.bot_name).first()
        self.strategy = EMACrossover(5, 30)

        self.om = OrderManagement(bot=self.bot,
                                  session=self.session,
                                  exchange=self.exchange,
                                  strategy=self.strategy)
Beispiel #3
0
    def setUp(self):
        """Create a bot with 2 pairs and 1 open orders"""

        # define bot params
        self.bot_name = 'ada_test_bot'
        self.bot_id = 1
        self.starting_balance = 2
        self.current_balance = 3
        self.profit_target = 4
        self.test_run = True
        self.quote_asset = 'BTC'
        
        # define pair params
        self.pair_id_ada = 2
        self.symbol_ada = 'ADABTC'
        self.profit_loss_ada = 5

        self.pair_id_eth = 3
        self.symbol_eth = 'ETHBTC'
        self.profit_loss_eth = 6

        # define order params
        self.order_id = 1
        self.order_symbol = self.symbol_eth
        self.entry_price = 2
        self.original_quantity = 3
        self.executed_quantity = 4
        self.status = 'NEW'
        self.side = 'BUY'
        self.is_test = True

        self.session = get_session()
        self.assertEqual(len(self.session.query(Models.Bot).all()), 0)

        # Create bot
        bot = Models.Bot(
                    id=self.bot_id,
                    name=self.bot_name,
                    quote_asset=self.quote_asset,
                    starting_balance=self.starting_balance,
                    current_balance=self.current_balance,
                    profit_target=self.profit_target,
                    test_run=self.test_run,
                    )

        # TODO Should check if pair contains the quote asset saved in bot.
        # Create ETHBTC pair
        ethpair = Models.Pair(
                            id=self.pair_id_eth,
                            bot_id=self.bot_id,
                            symbol=self.symbol_eth,
                            profit_loss=self.profit_loss_eth,
                             )
        # Create ADABTC pair
        adapair = Models.Pair(
                            id=self.pair_id_ada,
                            bot_id=self.bot_id,
                            symbol=self.symbol_ada,
                            profit_loss=self.profit_loss_ada,
                             )

        # Create ethereum buy order
        ethorder = Models.Order(
            id=self.order_id,
            bot_id=self.bot_id,
            symbol=self.order_symbol,
            entry_price=self.entry_price,
            original_quantity=self.original_quantity,
            executed_quantity=self.executed_quantity,
            status=self.status,
            side=self.side,
            is_test=self.is_test,
        )

        self.session.add(bot)
        self.session.add(adapair)
        self.session.add(ethpair)
        self.session.add(ethorder)
        self.session.commit()

        self.bot = self.session.query(Models.Bot).filter_by(name=self.bot_name).first()
    def setUp(self):

        self.exchange = Binance()
        self.df_BTCUSD_1k = pd.read_csv('./tests/data/BTCUSD_1m_1k.csv')
        self.df_BTCUSD_10k = pd.read_csv('./tests/data/BTCUSD_1m_10k.csv')
        self.df_ADABTC_1k = pd.read_csv('./tests/data/ADABTC_1m_1k.csv')

        # define bot params
        self.bot_name = 'ada_test_bot'
        self.bot_id = 1
        self.starting_balance = 2
        self.current_balance = 3
        self.profit_target = 4
        self.test_run = True
        self.quote_asset = 'BTC'

        # define pair params
        self.pair_id_ada = 2
        self.symbol_ada = 'ADABTC'
        self.profit_loss_ada = 5

        self.pair_id_eth = 3
        self.symbol_eth = 'ETHBTC'
        self.profit_loss_eth = 6

        # define order params
        self.order_1_id = 1
        self.order_2_id = 2
        self.order_symbol = self.symbol_eth
        self.entry_price = 2
        self.original_quantity = 3
        self.executed_quantity = 4
        self.status = 'NEW'
        self.is_closed = True
        self.side = 'BUY'
        self.is_test = True

        self.session = get_session()
        self.assertEqual(len(self.session.query(Bot).all()), 0)

        # Create bot
        bot = Bot(
            id=self.bot_id,
            name=self.bot_name,
            quote_asset=self.quote_asset,
            starting_balance=self.starting_balance,
            current_balance=self.current_balance,
            # profit_target=self.profit_target,
            test_run=self.test_run,
        )
        # Create entry and exit settings
        entrysets = EntrySettings(
            id=1,
            name='TimStoploss',
            initial_entry_allocation=0.01,
            signal_distance=0.2,  # in %
        )
        exitsets = ExitSettings(
            id=1,
            name='TimLoss',
            profit_target=1,  # in %
            stop_loss_value=10,  # in %
            exit_on_signal=False)
        bot.entry_settings = entrysets
        bot.exit_settings = exitsets

        # Create ETHBTC pair
        ethpair = Pair(
            id=self.pair_id_eth,
            bot_id=self.bot_id,
            symbol=self.symbol_eth,
            profit_loss=self.profit_loss_eth,
        )
        # Create ADABTC pair
        adapair = Pair(
            id=self.pair_id_ada,
            bot_id=self.bot_id,
            symbol=self.symbol_ada,
            profit_loss=self.profit_loss_ada,
        )

        # Create ethereum buy order
        eth_order = Order(
            id=self.order_1_id,
            bot_id=self.bot_id,
            symbol=self.order_symbol,
            entry_price=self.entry_price,
            original_quantity=self.original_quantity,
            executed_quantity=self.executed_quantity,
            status=self.status,
            side=self.side,
            is_test=self.is_test,
        )

        eth_order_closed = Order(
            id=self.order_2_id,
            bot_id=self.bot_id,
            symbol=self.order_symbol,
            entry_price=self.entry_price,
            original_quantity=self.original_quantity,
            executed_quantity=self.executed_quantity,
            is_closed=self.is_closed,
            status=self.status,
            side=self.side,
            is_test=self.is_test,
        )
        self.session.add(bot)
        self.session.add(adapair)
        self.session.add(ethpair)
        self.session.add(eth_order)
        self.session.add(eth_order_closed)
        self.session.commit()

        self.bot = self.session.query(Bot).filter_by(
            name=self.bot_name).first()
        self.strategy = EMAXStrategy(5, 30)

        self.om = BotController(bot=self.bot,
                                session=self.session,
                                exchange=self.exchange,
                                strategy=self.strategy)