add retrier decorator to all exchange functions except buy/sell
This commit is contained in:
parent
c43ceb2045
commit
bc2bd7fe1e
@ -206,6 +206,7 @@ def get_balance(currency: str) -> float:
|
|||||||
return balances[currency]['free']
|
return balances[currency]['free']
|
||||||
|
|
||||||
|
|
||||||
|
@retrier
|
||||||
def get_balances() -> dict:
|
def get_balances() -> dict:
|
||||||
if _CONF['dry_run']:
|
if _CONF['dry_run']:
|
||||||
return {}
|
return {}
|
||||||
@ -274,6 +275,7 @@ def get_ticker_history(pair: str, tick_interval: str) -> List[Dict]:
|
|||||||
raise OperationalException('Could not fetch ticker data. Msg: {}'.format(e))
|
raise OperationalException('Could not fetch ticker data. Msg: {}'.format(e))
|
||||||
|
|
||||||
|
|
||||||
|
@retrier
|
||||||
def cancel_order(order_id: str, pair: str) -> None:
|
def cancel_order(order_id: str, pair: str) -> None:
|
||||||
if _CONF['dry_run']:
|
if _CONF['dry_run']:
|
||||||
return
|
return
|
||||||
@ -288,6 +290,7 @@ def cancel_order(order_id: str, pair: str) -> None:
|
|||||||
raise OperationalException(e)
|
raise OperationalException(e)
|
||||||
|
|
||||||
|
|
||||||
|
@retrier
|
||||||
def get_order(order_id: str, pair: str) -> Dict:
|
def get_order(order_id: str, pair: str) -> Dict:
|
||||||
if _CONF['dry_run']:
|
if _CONF['dry_run']:
|
||||||
order = _DRY_RUN_OPEN_ORDERS[order_id]
|
order = _DRY_RUN_OPEN_ORDERS[order_id]
|
||||||
@ -309,6 +312,7 @@ def get_order(order_id: str, pair: str) -> Dict:
|
|||||||
raise OperationalException(e)
|
raise OperationalException(e)
|
||||||
|
|
||||||
|
|
||||||
|
@retrier
|
||||||
def get_pair_detail_url(pair: str) -> str:
|
def get_pair_detail_url(pair: str) -> str:
|
||||||
try:
|
try:
|
||||||
url_base = _API.urls.get('www')
|
url_base = _API.urls.get('www')
|
||||||
@ -320,6 +324,7 @@ def get_pair_detail_url(pair: str) -> str:
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
@retrier
|
||||||
def get_markets() -> List[dict]:
|
def get_markets() -> List[dict]:
|
||||||
try:
|
try:
|
||||||
return _API.fetch_markets()
|
return _API.fetch_markets()
|
||||||
@ -339,6 +344,7 @@ def get_id() -> str:
|
|||||||
return _API.id
|
return _API.id
|
||||||
|
|
||||||
|
|
||||||
|
@retrier
|
||||||
def get_fee(symbol='ETH/BTC', type='', side='', amount=1,
|
def get_fee(symbol='ETH/BTC', type='', side='', amount=1,
|
||||||
price=1, taker_or_maker='maker') -> float:
|
price=1, taker_or_maker='maker') -> float:
|
||||||
try:
|
try:
|
||||||
|
@ -262,15 +262,17 @@ def test_get_balances_prod(default_conf, mocker):
|
|||||||
assert get_balances()['1ST']['total'] == 10.0
|
assert get_balances()['1ST']['total'] == 10.0
|
||||||
assert get_balances()['1ST']['used'] == 0.0
|
assert get_balances()['1ST']['used'] == 0.0
|
||||||
|
|
||||||
with pytest.raises(TemporaryError):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.fetch_balance = MagicMock(side_effect=ccxt.NetworkError)
|
api_mock.fetch_balance = MagicMock(side_effect=ccxt.NetworkError)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
get_balances()
|
get_balances()
|
||||||
|
assert api_mock.fetch_balance.call_count == exchange.API_RETRY_COUNT + 1
|
||||||
|
|
||||||
with pytest.raises(OperationalException):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.fetch_balance = MagicMock(side_effect=ccxt.BaseError)
|
api_mock.fetch_balance = MagicMock(side_effect=ccxt.BaseError)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
get_balances()
|
get_balances()
|
||||||
|
assert api_mock.fetch_balance.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
# This test is somewhat redundant with
|
# This test is somewhat redundant with
|
||||||
@ -397,20 +399,23 @@ def test_cancel_order(default_conf, mocker):
|
|||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
assert cancel_order(order_id='_', pair='TKN/BTC') == 123
|
assert cancel_order(order_id='_', pair='TKN/BTC') == 123
|
||||||
|
|
||||||
with pytest.raises(TemporaryError):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.cancel_order = MagicMock(side_effect=ccxt.NetworkError)
|
api_mock.cancel_order = MagicMock(side_effect=ccxt.NetworkError)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
cancel_order(order_id='_', pair='TKN/BTC')
|
cancel_order(order_id='_', pair='TKN/BTC')
|
||||||
|
assert api_mock.cancel_order.call_count == exchange.API_RETRY_COUNT + 1
|
||||||
|
|
||||||
with pytest.raises(TemporaryError):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.cancel_order = MagicMock(side_effect=ccxt.InvalidOrder)
|
api_mock.cancel_order = MagicMock(side_effect=ccxt.InvalidOrder)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
cancel_order(order_id='_', pair='TKN/BTC')
|
cancel_order(order_id='_', pair='TKN/BTC')
|
||||||
|
assert api_mock.cancel_order.call_count == exchange.API_RETRY_COUNT + 1
|
||||||
|
|
||||||
with pytest.raises(OperationalException):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.cancel_order = MagicMock(side_effect=ccxt.BaseError)
|
api_mock.cancel_order = MagicMock(side_effect=ccxt.BaseError)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
cancel_order(order_id='_', pair='TKN/BTC')
|
cancel_order(order_id='_', pair='TKN/BTC')
|
||||||
|
assert api_mock.cancel_order.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_get_order(default_conf, mocker):
|
def test_get_order(default_conf, mocker):
|
||||||
@ -429,20 +434,23 @@ def test_get_order(default_conf, mocker):
|
|||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
assert exchange.get_order('X', 'TKN/BTC') == 456
|
assert exchange.get_order('X', 'TKN/BTC') == 456
|
||||||
|
|
||||||
with pytest.raises(TemporaryError):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.fetch_order = MagicMock(side_effect=ccxt.NetworkError)
|
api_mock.fetch_order = MagicMock(side_effect=ccxt.NetworkError)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
exchange.get_order(order_id='_', pair='TKN/BTC')
|
exchange.get_order(order_id='_', pair='TKN/BTC')
|
||||||
|
assert api_mock.fetch_order.call_count == exchange.API_RETRY_COUNT + 1
|
||||||
|
|
||||||
with pytest.raises(DependencyException):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.fetch_order = MagicMock(side_effect=ccxt.InvalidOrder)
|
api_mock.fetch_order = MagicMock(side_effect=ccxt.InvalidOrder)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
exchange.get_order(order_id='_', pair='TKN/BTC')
|
exchange.get_order(order_id='_', pair='TKN/BTC')
|
||||||
|
assert api_mock.fetch_order.call_count == exchange.API_RETRY_COUNT + 1
|
||||||
|
|
||||||
with pytest.raises(OperationalException):
|
with pytest.raises(OperationalException):
|
||||||
api_mock.fetch_order = MagicMock(side_effect=ccxt.BaseError)
|
api_mock.fetch_order = MagicMock(side_effect=ccxt.BaseError)
|
||||||
mocker.patch('freqtrade.exchange._API', api_mock)
|
mocker.patch('freqtrade.exchange._API', api_mock)
|
||||||
exchange.get_order(order_id='_', pair='TKN/BTC')
|
exchange.get_order(order_id='_', pair='TKN/BTC')
|
||||||
|
assert api_mock.fetch_order.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
def test_get_name(default_conf, mocker):
|
def test_get_name(default_conf, mocker):
|
||||||
|
Loading…
Reference in New Issue
Block a user