def test_1_status_handle(self): with patch.dict('main._CONF', self.conf): with patch('main.get_buy_signal', side_effect=lambda _: True): msg_mock = MagicMock() with patch.multiple('main.telegram', _CONF=self.conf, init=MagicMock(), send_msg=msg_mock): with patch.multiple( 'main.exchange', get_ticker=MagicMock(return_value={ 'bid': 0.07256061, 'ask': 0.072661, 'last': 0.07256061 }), buy=MagicMock(return_value='mocked_order_id')): init(self.conf, 'sqlite://') # Create some test data trade = create_trade(15.0, exchange.Exchange.BITTREX) self.assertTrue(trade) Trade.session.add(trade) Trade.session.flush() _status(bot=MagicBot(), update=self.update) self.assertEqual(msg_mock.call_count, 2) self.assertIn('[BTC_ETH]', msg_mock.call_args_list[-1][0][0])
def test_2_profit_handle(self): with patch.dict('main._CONF', self.conf): with patch('main.get_buy_signal', side_effect=lambda _: True): msg_mock = MagicMock() with patch.multiple('main.telegram', _CONF=self.conf, init=MagicMock(), send_msg=msg_mock): with patch.multiple( 'main.exchange', get_ticker=MagicMock(return_value={ 'bid': 0.07256061, 'ask': 0.072661, 'last': 0.07256061 }), buy=MagicMock(return_value='mocked_order_id')): init(self.conf, 'sqlite://') # Create some test data trade = create_trade(15.0, exchange.Exchange.BITTREX) self.assertTrue(trade) trade.close_rate = 0.07256061 trade.close_profit = 100.00 trade.close_date = datetime.utcnow() trade.open_order_id = None trade.is_open = False Trade.session.add(trade) Trade.session.flush() _profit(bot=MagicBot(), update=self.update) self.assertEqual(msg_mock.call_count, 2) self.assertIn('(100.00%)', msg_mock.call_args_list[-1][0][0])
def test_1_create_trade(self): with patch.dict('main._CONF', self.conf): with patch('main.get_buy_signal', side_effect=lambda _: True) as buy_signal: with patch.multiple('main.telegram', init=MagicMock(), send_msg=MagicMock()): with patch.multiple( 'main.exchange', get_ticker=MagicMock(return_value={ 'bid': 0.07256061, 'ask': 0.072661, 'last': 0.07256061 }), buy=MagicMock(return_value='mocked_order_id')): init(self.conf, 'sqlite://') trade = create_trade(15.0, exchange.Exchange.BITTREX) Trade.session.add(trade) Trade.session.flush() self.assertIsNotNone(trade) self.assertEqual(trade.open_rate, 0.072661) self.assertEqual(trade.pair, 'BTC_ETH') self.assertEqual(trade.exchange, exchange.Exchange.BITTREX) self.assertEqual(trade.amount, 206.43811673387373) self.assertEqual(trade.btc_amount, 15.0) self.assertEqual(trade.is_open, True) self.assertIsNotNone(trade.open_date) buy_signal.assert_called_once_with('BTC_ETH')