From 215ded2e0a6544c802b51abc84fc2e5c39c3b255 Mon Sep 17 00:00:00 2001 From: misagh Date: Mon, 17 Dec 2018 21:30:58 +0100 Subject: [PATCH] returning last candle close price for a pair --- freqtrade/exchange/__init__.py | 6 ++++++ freqtrade/tests/exchange/test_exchange.py | 3 +++ 2 files changed, 9 insertions(+) diff --git a/freqtrade/exchange/__init__.py b/freqtrade/exchange/__init__.py index e883175e7..4a827fcb5 100644 --- a/freqtrade/exchange/__init__.py +++ b/freqtrade/exchange/__init__.py @@ -164,6 +164,12 @@ class Exchange(object): else: return None + def last_kline_close(self, pair: str): + if pair in self._klines: + return self._klines[pair].iloc[-1]['close'] + else: + return None + def set_sandbox(self, api, exchange_config: dict, name: str): if exchange_config.get('sandbox'): if api.urls.get('test'): diff --git a/freqtrade/tests/exchange/test_exchange.py b/freqtrade/tests/exchange/test_exchange.py index 647440223..6299d8dc8 100644 --- a/freqtrade/tests/exchange/test_exchange.py +++ b/freqtrade/tests/exchange/test_exchange.py @@ -814,6 +814,9 @@ def test_refresh_tickers(mocker, default_conf, caplog) -> None: assert isinstance(exchange.klines(pair), DataFrame) assert len(exchange.klines(pair)) > 0 + # test last kline close price + assert exchange.last_kline_close('XRP/ETH') == 4 + # test caching exchange.refresh_tickers(['IOTA/ETH', 'XRP/ETH'], '5m')