Ejemplo n.º 1
0
    def test__track_order__that_has_been_filled(self):
        """
        Test :meth:`ArbitrageStrategy._track_order`

        Assert the current order data is cleared and `False` is returned.
        """

        arbitrage = ArbitrageStrategy()

        test_order = {
            'id': 1,
        }
        arbitrage.order = test_order

        trader = MagicMock()

        test_order_update = {
            'id': 2,
            'status': 'done',
            'settled': True,
        }
        trader.get_order.return_value = test_order_update

        arbitrage.trader = trader

        success = arbitrage._track_order()

        self.assertFalse(success)
        self.assertEqual(arbitrage.order, None)
Ejemplo n.º 2
0
    def test__track_order_success(self):
        """
        Test :meth:`ArbitrageStrategy._track_order`

        Assert the current order data is updated and `True` is returned.
        """

        arbitrage = ArbitrageStrategy()

        test_order = {
            'id': 1,
        }
        arbitrage.order = test_order

        trader = MagicMock()

        test_order_update = {
            'id': 2,
        }
        trader.get_order.return_value = test_order_update

        arbitrage.trader = trader

        success = arbitrage._track_order()

        self.assertTrue(success)
        self.assertEqual(arbitrage.order, test_order_update)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def test__track_order_with_no_current_order(self):
        """
        Test :meth:`ArbitrageStrategy._track_order`

        Assert `False` is returned.
        """

        arbitrage = ArbitrageStrategy()

        arbitrage.order = None

        trader = MagicMock()

        test_order_update = {
            'id': 2,
        }
        trader.get_order.return_value = test_order_update

        arbitrage.trader = trader

        success = arbitrage._track_order()

        self.assertFalse(success)
        self.assertEqual(arbitrage.order, None)