returning last candle close price for a pair

This commit is contained in:
misagh 2018-12-17 21:30:58 +01:00
parent 1dbcab0b09
commit 215ded2e0a
2 changed files with 9 additions and 0 deletions

View File

@ -164,6 +164,12 @@ class Exchange(object):
else: else:
return None 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): def set_sandbox(self, api, exchange_config: dict, name: str):
if exchange_config.get('sandbox'): if exchange_config.get('sandbox'):
if api.urls.get('test'): if api.urls.get('test'):

View File

@ -814,6 +814,9 @@ def test_refresh_tickers(mocker, default_conf, caplog) -> None:
assert isinstance(exchange.klines(pair), DataFrame) assert isinstance(exchange.klines(pair), DataFrame)
assert len(exchange.klines(pair)) > 0 assert len(exchange.klines(pair)) > 0
# test last kline close price
assert exchange.last_kline_close('XRP/ETH') == 4
# test caching # test caching
exchange.refresh_tickers(['IOTA/ETH', 'XRP/ETH'], '5m') exchange.refresh_tickers(['IOTA/ETH', 'XRP/ETH'], '5m')