Remove cache from get_ticker

This commit is contained in:
enenn 2018-03-26 21:33:14 +02:00
parent 916165a7c5
commit 954e5c095f
3 changed files with 5 additions and 33 deletions

View File

@ -26,7 +26,6 @@ API_RETRY_COUNT = 4
# Holds all open sell orders for dry_run
_DRY_RUN_OPEN_ORDERS: Dict[str, Any] = {}
_TICKER_CACHE: dict = {}
def retrier(f):
def wrapper(*args, **kwargs):
@ -218,15 +217,11 @@ def get_balances() -> dict:
raise OperationalException(e)
# TODO: remove refresh argument, keeping it to keep track of where it was intended to be used
@retrier
def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
global _TICKER_CACHE
try:
if not refresh:
if _TICKER_CACHE and pair in _TICKER_CACHE:
return _TICKER_CACHE[pair]
_TICKER_CACHE[pair] = _API.fetch_ticker(pair)
return _TICKER_CACHE[pair]
return _API.fetch_ticker(pair)
except ccxt.NetworkError as e:
raise NetworkException(
'Could not load tickers due to networking error. Message: {}'.format(e)

View File

@ -468,8 +468,8 @@ class FreqtradeBot(object):
fmt_exp_profit = round(trade.calc_profit_percent(rate=limit) * 100, 2)
profit_trade = trade.calc_profit(rate=limit)
current_rate = exchange.get_ticker(trade.pair, False)['bid']
profit = trade.calc_profit_percent(current_rate)
current_rate = exchange.get_ticker(trade.pair)['bid']
profit = trade.calc_profit_percent(limit)
message = "*{exchange}:* Selling\n" \
"*Current Pair:* [{pair}]({pair_url})\n" \

View File

@ -280,30 +280,7 @@ def test_get_ticker(default_conf, mocker):
# if not caching the result we should get the same ticker
# if not fetching a new result we should get the cached ticker
ticker = get_ticker(pair='ETH/BTC', refresh=False)
assert ticker['bid'] == 0.00001098
assert ticker['ask'] == 0.00001099
# force ticker refresh
ticker = get_ticker(pair='ETH/BTC', refresh=True)
assert ticker['bid'] == 0.5
assert ticker['ask'] == 1
# change the ticker to a different pair which should not be cached
tick = {
'symbol': 'LTC/BTC',
'bid': 2,
'ask': 3,
'last': 4,
}
api_mock.fetch_ticker = MagicMock(return_value=tick, refresh=False)
mocker.patch('freqtrade.exchange._API', api_mock)
ticker = get_ticker(pair='LTC/BTC', refresh=False)
assert ticker['bid'] == 2
assert ticker['ask'] == 3
# check that ETH/BTC is still cached
ticker = get_ticker(pair='ETH/BTC', refresh=False)
ticker = get_ticker(pair='ETH/BTC')
assert ticker['bid'] == 0.5
assert ticker['ask'] == 1