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__cancel_order_without_order(self): """ Test :meth:`ArbitrageStrategy._cancel_order` Assert `False` is returned. """ arbitrage = ArbitrageStrategy() arbitrage.order = None trader = MagicMock() arbitrage.trader = trader success = arbitrage._cancel_order() self.assertFalse(success)
def test__cancel_order_with_valid_order(self): """ Test :meth:`ArbitrageStrategy._cancel_order` Assert :meth:`GDAXTrader.cancel_order` is called with current order ID and `True` is returned. """ arbitrage = ArbitrageStrategy() TEST_ID = 1 arbitrage.order = { 'order_id': TEST_ID, } trader = MagicMock() arbitrage.trader = trader success = arbitrage._cancel_order() trader.cancel_order.assert_called_with(TEST_ID) self.assertTrue(success)
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)