def test__update_pending_order_with_change(self): """ Test :meth:`ArbitrageStrategy._update_pending_order` Assert :meth:`ArbitrageStrategy._cancel_order` is called and `True` is returned. """ arbitrage = ArbitrageStrategy() TEST_PRODUCT = 'BTC-USD' TEST_PRICE = 1.0 arbitrage.order = { 'product_id': TEST_PRODUCT, 'price': TEST_PRICE, } NEW_PRICE = 2.0 arbitrage._get_market_price = MagicMock(return_value=NEW_PRICE) cancel_order = MagicMock() arbitrage._cancel_order = cancel_order success = arbitrage._update_pending_order(CurrencyGraph.BUY_ORDER, TEST_PRODUCT) self.assertEqual(cancel_order.called, 1) self.assertTrue(success)
def test_next_update_pending_order(self): """ Test :meth:`ArbitrageStrategy.next` Assert :meth:`ArbitrageStrategy._update_pending_order` is called and `True` is returned. """ arbitrage = ArbitrageStrategy() trade_signal = (CurrencyGraph.BUY_ORDER, 'BTC-USD', 1.0,) arbitrage._get_trade_signal = MagicMock(return_value=trade_signal) arbitrage._set_current_node = MagicMock() arbitrage._track_order = MagicMock(return_value=True) arbitrage._update_pending_order = MagicMock() arbitrage._place_order = MagicMock() success = arbitrage.next() self.assertTrue(success) self.assertEqual(arbitrage._update_pending_order.called, 1) self.assertEqual(arbitrage._place_order.called, 0)
def test__update_pending_order_without_order(self): """ Test :meth:`ArbitrageStrategy._update_pending_order` Assert :meth:`ArbitrageStrategy._cancel_order` is not called and `False` is returned. """ arbitrage = ArbitrageStrategy() TEST_PRODUCT = 'BTC-USD' TEST_PRICE = 1.0 arbitrage.order = None arbitrage._get_market_price = MagicMock(return_value=TEST_PRICE) cancel_order = MagicMock() arbitrage._cancel_order = cancel_order success = arbitrage._update_pending_order(CurrencyGraph.BUY_ORDER, TEST_PRODUCT) self.assertEqual(cancel_order.called, 0) self.assertFalse(success)
def test_next_trade_signal_error(self): """ Test :meth:`ArbitrageStrategy.next` Assert :meth:`ArbitrageStrategy._update_pending_order` and :meth:`ArbitrageStrategy._place_order` are not called and `False` is returned. """ arbitrage = ArbitrageStrategy() error = MissingCurrencyGraph() arbitrage._get_trade_signal = MagicMock(side_effect=error) arbitrage._set_current_node = MagicMock() arbitrage._track_order = MagicMock(return_value=False) arbitrage._update_pending_order = MagicMock() arbitrage._place_order = MagicMock() success = arbitrage.next() self.assertFalse(success) self.assertEqual(arbitrage._update_pending_order.called, 0) self.assertEqual(arbitrage._place_order.called, 0)