retry_call.assert_called_with(request,
delay=1, tries=10, fargs=["foo"],
fkwargs={'api': 'public', 'method': 'GET', 'params': {}, 'headers': None, 'body': None},
- exceptions=(market.ccxt.RequestTimeout,))
+ exceptions=(market.ccxt.RequestTimeout, market.ccxt.InvalidNonce))
request.assert_not_called()
with self.subTest(desc="private GET"):
retry_call.assert_called_with(request,
delay=1, tries=10, fargs=["foo"],
fkwargs={'api': 'private', 'method': 'GET', 'params': {}, 'headers': None, 'body': None},
- exceptions=(market.ccxt.RequestTimeout,))
+ exceptions=(market.ccxt.RequestTimeout, market.ccxt.InvalidNonce))
request.assert_not_called()
with self.subTest(desc="private POST regexp"):
retry_call.assert_called_with(request,
delay=1, tries=10, fargs=["returnFoo"],
fkwargs={'api': 'private', 'method': 'POST', 'params': {}, 'headers': None, 'body': None},
- exceptions=(market.ccxt.RequestTimeout,))
+ exceptions=(market.ccxt.RequestTimeout, market.ccxt.InvalidNonce))
request.assert_not_called()
with self.subTest(desc="private POST non-regexp"):
retry_call.assert_called_with(request,
delay=1, tries=10, fargs=["getMarginPosition"],
fkwargs={'api': 'private', 'method': 'POST', 'params': {}, 'headers': None, 'body': None},
- exceptions=(market.ccxt.RequestTimeout,))
+ exceptions=(market.ccxt.RequestTimeout, market.ccxt.InvalidNonce))
request.assert_not_called()
retry_call.reset_mock()
request.reset_mock()
m.ccxt.transfer_balance.side_effect = [
market.ccxt.RequestTimeout,
+ market.ccxt.InvalidNonce,
True
]
m.move_balances()
self.ccxt.transfer_balance.assert_has_calls([
+ mock.call("BTC", 3, "exchange", "margin"),
mock.call("BTC", 3, "exchange", "margin"),
mock.call("BTC", 3, "exchange", "margin")
])
- self.assertEqual(2, fetch_balances.call_count)
+ self.assertEqual(3, fetch_balances.call_count)
m.report.log_error.assert_called_with(mock.ANY, message="Retrying", exception=mock.ANY)
- self.assertEqual(2, m.report.log_move_balances.call_count)
+ self.assertEqual(3, m.report.log_move_balances.call_count)
self.ccxt.transfer_balance.reset_mock()
m.report.reset_mock()
self.assertEqual(5, self.m.report.log_error.call_count)
self.m.report.log_error.assert_called_with(mock.ANY, message="Giving up Order(buy long 0.00096060 ETH at 0.1 BTC [pending])", exception=mock.ANY)
+ self.m.reset_mock()
+ with self.subTest(invalid_nonce=True):
+ with self.subTest(retry_success=True):
+ order = portfolio.Order("buy", portfolio.Amount("ETH", "0.001"),
+ D("0.1"), "BTC", "long", self.m, "trade")
+ self.m.ccxt.create_order.side_effect = [
+ portfolio.InvalidNonce,
+ portfolio.InvalidNonce,
+ { "id": 123 },
+ ]
+ order.run()
+ self.m.ccxt.create_order.assert_has_calls([
+ mock.call('ETH/BTC', 'limit', 'buy', D('0.0010'), account='exchange', price=D('0.1')),
+ mock.call('ETH/BTC', 'limit', 'buy', D('0.0010'), account='exchange', price=D('0.1')),
+ mock.call('ETH/BTC', 'limit', 'buy', D('0.0010'), account='exchange', price=D('0.1')),
+ ])
+ self.assertEqual(3, self.m.ccxt.create_order.call_count)
+ self.assertEqual(3, order.tries)
+ self.m.report.log_error.assert_called()
+ self.assertEqual(2, self.m.report.log_error.call_count)
+ self.m.report.log_error.assert_called_with(mock.ANY, message="Retrying after invalid nonce", exception=mock.ANY)
+ self.assertEqual(123, order.id)
+
+ self.m.reset_mock()
+ with self.subTest(retry_success=False):
+ order = portfolio.Order("buy", portfolio.Amount("ETH", "0.001"),
+ D("0.1"), "BTC", "long", self.m, "trade")
+ self.m.ccxt.create_order.side_effect = [
+ portfolio.InvalidNonce,
+ portfolio.InvalidNonce,
+ portfolio.InvalidNonce,
+ portfolio.InvalidNonce,
+ portfolio.InvalidNonce,
+ ]
+ order.run()
+ self.assertEqual(5, self.m.ccxt.create_order.call_count)
+ self.assertEqual(5, order.tries)
+ self.m.report.log_error.assert_called()
+ self.assertEqual(5, self.m.report.log_error.call_count)
+ self.m.report.log_error.assert_called_with(mock.ANY, message="Giving up Order(buy long 0.00100000 ETH at 0.1 BTC [pending]) after invalid nonce", exception=mock.ANY)
+ self.assertEqual("error", order.status)
+
self.m.reset_mock()
with self.subTest(request_timeout=True):
order = portfolio.Order("buy", portfolio.Amount("ETH", "0.001"),