def test__set_current_node_with_valid_balance(self): """ Test :meth:`ArbitrageStrategy._set_current_node` Assert :attr:`ArbitrageStrategy.current_node` is set to the first account currency with a positive balance. """ arbitrage = ArbitrageStrategy() UNCHANGED_NODE = 'FAKE' arbitrage.current_node = UNCHANGED_NODE TEST_CURRENCY = 'USD' TEST_2ND_CURRENCY = 'BTC' TEST_BALANCE = 1.0 arbitrage.accounts = [ { 'currency': TEST_CURRENCY, 'balance': TEST_BALANCE, }, { 'currency': TEST_2ND_CURRENCY, 'balance': TEST_BALANCE, } ] arbitrage.ticker = {} arbitrage._set_current_node() self.assertEqual(arbitrage.current_node, TEST_CURRENCY)
def test__set_current_node_with_empty_balances(self): """ Test :meth:`ArbitrageStrategy._set_current_node` Assert :attr:`ArbitrageStrategy.current_node` is unchanged. """ arbitrage = ArbitrageStrategy() UNCHANGED_NODE = 'FAKE' arbitrage.current_node = UNCHANGED_NODE TEST_CURRENCY = 'USD' TEST_2ND_CURRENCY = 'BTC' TEST_BALANCE = 0.0 arbitrage.accounts = [ { 'currency': TEST_CURRENCY, 'balance': TEST_BALANCE, }, { 'currency': TEST_2ND_CURRENCY, 'balance': TEST_BALANCE, } ] arbitrage.ticker = {} arbitrage._set_current_node() self.assertEqual(arbitrage.current_node, UNCHANGED_NODE)
def test__set_current_node_with_invalid_account_data(self): """ Test :meth:`ArbitrageStrategy._set_current_node` Assert :attr:`ArbitrageStrategy.current_node` is unchanged. """ arbitrage = ArbitrageStrategy() UNCHANGED_NODE = 'FAKE' arbitrage.current_node = UNCHANGED_NODE TEST_CURRENCY = 'USD' TEST_BALANCE = 1.0 arbitrage.accounts = [ { 'error': 'Invalid account data.', } ] arbitrage.ticker = {} arbitrage._set_current_node() self.assertEqual(arbitrage.current_node, UNCHANGED_NODE)
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_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)