Esempio n. 1
0
 def test_create_order_table(self):
     """ tests initialization of order table """
     order_table = Models.Order()
     self.assertEqual(order_table.__tablename__, 'order')
     self.assertEqual(order_table.bot_id, None)
     self.assertEqual(order_table.symbol, None)
     self.assertEqual(order_table.timestamp, None)
     self.assertEqual(order_table.entry_price, None)
     self.assertEqual(order_table.take_profit_price, None)
     self.assertEqual(order_table.stop_loss_price, None)
     self.assertEqual(order_table.original_quantity, None)
     self.assertEqual(order_table.executed_quantity, None)
     self.assertEqual(order_table.status, None)
     self.assertEqual(order_table.side, None)
     self.assertEqual(order_table.is_entry, None)
     self.assertEqual(order_table.is_closed, None)
     self.assertEqual(order_table.matched_order_id, None)
     self.assertEqual(order_table.is_test, None)
Esempio n. 2
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()