Remove cache from get_ticker
This commit is contained in:
parent
916165a7c5
commit
954e5c095f
@ -26,7 +26,6 @@ API_RETRY_COUNT = 4
|
|||||||
# Holds all open sell orders for dry_run
|
# Holds all open sell orders for dry_run
|
||||||
_DRY_RUN_OPEN_ORDERS: Dict[str, Any] = {}
|
_DRY_RUN_OPEN_ORDERS: Dict[str, Any] = {}
|
||||||
|
|
||||||
_TICKER_CACHE: dict = {}
|
|
||||||
|
|
||||||
def retrier(f):
|
def retrier(f):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
@ -218,15 +217,11 @@ def get_balances() -> dict:
|
|||||||
raise OperationalException(e)
|
raise OperationalException(e)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: remove refresh argument, keeping it to keep track of where it was intended to be used
|
||||||
@retrier
|
@retrier
|
||||||
def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
|
def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
|
||||||
global _TICKER_CACHE
|
|
||||||
try:
|
try:
|
||||||
if not refresh:
|
return _API.fetch_ticker(pair)
|
||||||
if _TICKER_CACHE and pair in _TICKER_CACHE:
|
|
||||||
return _TICKER_CACHE[pair]
|
|
||||||
_TICKER_CACHE[pair] = _API.fetch_ticker(pair)
|
|
||||||
return _TICKER_CACHE[pair]
|
|
||||||
except ccxt.NetworkError as e:
|
except ccxt.NetworkError as e:
|
||||||
raise NetworkException(
|
raise NetworkException(
|
||||||
'Could not load tickers due to networking error. Message: {}'.format(e)
|
'Could not load tickers due to networking error. Message: {}'.format(e)
|
||||||
|
@ -468,8 +468,8 @@ class FreqtradeBot(object):
|
|||||||
|
|
||||||
fmt_exp_profit = round(trade.calc_profit_percent(rate=limit) * 100, 2)
|
fmt_exp_profit = round(trade.calc_profit_percent(rate=limit) * 100, 2)
|
||||||
profit_trade = trade.calc_profit(rate=limit)
|
profit_trade = trade.calc_profit(rate=limit)
|
||||||
current_rate = exchange.get_ticker(trade.pair, False)['bid']
|
current_rate = exchange.get_ticker(trade.pair)['bid']
|
||||||
profit = trade.calc_profit_percent(current_rate)
|
profit = trade.calc_profit_percent(limit)
|
||||||
|
|
||||||
message = "*{exchange}:* Selling\n" \
|
message = "*{exchange}:* Selling\n" \
|
||||||
"*Current Pair:* [{pair}]({pair_url})\n" \
|
"*Current Pair:* [{pair}]({pair_url})\n" \
|
||||||
|
@ -280,30 +280,7 @@ def test_get_ticker(default_conf, mocker):
|
|||||||
|
|
||||||
# if not caching the result we should get the same ticker
|
# if not caching the result we should get the same ticker
|
||||||
# if not fetching a new result we should get the cached ticker
|
# if not fetching a new result we should get the cached ticker
|
||||||
ticker = get_ticker(pair='ETH/BTC', refresh=False)
|
ticker = get_ticker(pair='ETH/BTC')
|
||||||
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)
|
|
||||||
assert ticker['bid'] == 0.5
|
assert ticker['bid'] == 0.5
|
||||||
assert ticker['ask'] == 1
|
assert ticker['ask'] == 1
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user