Exemple #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)  
Exemple #2
0
 def test_create_pair_table(self):
     """ tests initialization of pair table """
     pair_table = Models.PairModel()
     self.assertEqual(pair_table.__tablename__, 'pair')
     self.assertEqual(pair_table.id, None)
     self.assertEqual(pair_table.bot_id, None)
     self.assertEqual(pair_table.symbol, None)
     self.assertEqual(pair_table.active, None)
     self.assertEqual(pair_table.current_order_id, None)
     self.assertEqual(pair_table.profit_loss, None)
Exemple #3
0
 def test_create_bot_table(self):
     """ tests initialization of bot table """
     bot_table = Models.TABotModel()
     self.assertEqual(bot_table.__tablename__, 'ta_bot')
     self.assertEqual(bot_table.id, None)
     self.assertEqual(bot_table.name, None)
     self.assertEqual(bot_table.is_running, None)
     self.assertEqual(bot_table.test_run, None)
     self.assertEqual(bot_table.quote_asset, None)
     self.assertEqual(bot_table.starting_balance, None)
     self.assertEqual(bot_table.current_balance, None)
     self.assertEqual(bot_table.profit_loss, None)
Exemple #4
0
 def test_create_order_table(self):
     """ tests initialization of order table """
     order_table = Models.OrderModel()
     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_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)
Exemple #5
0
 def setUp(self):
     self.scale = 13
     self.sqlite_decimal = Models.SqliteDecimal(self.scale)
Exemple #6
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.TABotModel).all()), 0)

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

        # TODO Should check if pair contains the quote asset saved in bot.
        # Create ETHBTC pair
        ethpair = Models.PairModel(
            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.PairModel(
            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.OrderModel(
            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.TABotModel).filter_by(name=self.bot_name).first()