2018-11-30 19:42:16 +00:00
|
|
|
"""
|
|
|
|
Dataprovider
|
|
|
|
Responsible to provide data to the bot
|
|
|
|
including Klines, tickers, historic data
|
|
|
|
Common Interface for bot and strategy to access data.
|
|
|
|
"""
|
|
|
|
import logging
|
2018-12-17 05:52:13 +00:00
|
|
|
from pathlib import Path
|
2018-12-02 14:57:49 +00:00
|
|
|
from typing import List, Dict
|
2018-11-30 19:42:16 +00:00
|
|
|
|
2018-12-02 08:16:35 +00:00
|
|
|
from pandas import DataFrame
|
|
|
|
|
2018-11-30 19:42:16 +00:00
|
|
|
from freqtrade.exchange import Exchange
|
2018-12-17 05:52:13 +00:00
|
|
|
from freqtrade.data.history import load_pair_history
|
2018-11-30 19:42:16 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
class DataProvider(object):
|
|
|
|
|
2018-12-02 08:16:35 +00:00
|
|
|
def __init__(self, config: dict, exchange: Exchange) -> None:
|
|
|
|
self._config = config
|
|
|
|
self._exchange = exchange
|
2018-11-30 19:42:16 +00:00
|
|
|
|
2018-12-02 14:57:49 +00:00
|
|
|
def refresh(self, pairlist: List[str]) -> None:
|
2018-11-30 19:42:16 +00:00
|
|
|
"""
|
|
|
|
Refresh data, called with each cycle
|
|
|
|
"""
|
2018-12-02 14:57:49 +00:00
|
|
|
self._exchange.refresh_tickers(pairlist, self._config['ticker_interval'])
|
2018-11-30 19:42:16 +00:00
|
|
|
|
2018-12-02 14:57:49 +00:00
|
|
|
def ohlcv(self, pair: str) -> List[str]:
|
2018-11-30 19:42:16 +00:00
|
|
|
"""
|
2018-12-02 08:16:35 +00:00
|
|
|
get ohlcv data for the given pair as DataFrame
|
2018-11-30 19:42:16 +00:00
|
|
|
"""
|
2018-12-02 08:16:35 +00:00
|
|
|
# TODO: Should not be stored in exchange but in this class
|
2018-12-17 05:43:01 +00:00
|
|
|
return self._exchange.klines(pair)
|
2018-11-30 19:42:16 +00:00
|
|
|
|
2018-12-17 05:52:13 +00:00
|
|
|
def historic_ohlcv(self, pair: str, ticker_interval: str) -> DataFrame:
|
2018-11-30 19:42:16 +00:00
|
|
|
"""
|
|
|
|
get historic ohlcv data stored for backtesting
|
|
|
|
"""
|
2018-12-17 05:52:13 +00:00
|
|
|
return load_pair_history(pair=pair,
|
|
|
|
ticker_interval=ticker_interval,
|
|
|
|
refresh_pairs=False,
|
|
|
|
datadir=Path(self.config['datadir']) if self.config.get(
|
|
|
|
'datadir') else None
|
|
|
|
)
|
2018-11-30 19:42:16 +00:00
|
|
|
|
2018-12-02 08:16:35 +00:00
|
|
|
def ticker(self, pair: str):
|
|
|
|
"""
|
|
|
|
Return last ticker data
|
|
|
|
"""
|
2018-11-30 19:42:16 +00:00
|
|
|
pass
|
|
|
|
|
2018-12-02 08:16:35 +00:00
|
|
|
def orderbook(self, pair: str, max: int):
|
|
|
|
"""
|
|
|
|
return latest orderbook data
|
|
|
|
"""
|
2018-11-30 19:42:16 +00:00
|
|
|
pass
|
|
|
|
|
2018-12-02 08:16:35 +00:00
|
|
|
def balance(self, pair):
|
2018-11-30 19:42:16 +00:00
|
|
|
# TODO: maybe use wallet directly??
|
|
|
|
pass
|
2018-12-02 20:57:30 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def runmode(self) -> str:
|
|
|
|
"""
|
|
|
|
Get runmode of the bot
|
|
|
|
can be "live", "dry-run", "backtest", "edgecli", "hyperopt".
|
|
|
|
"""
|
2018-12-17 05:52:13 +00:00
|
|
|
# TODO: this needs to be set somewhere ...
|
2018-12-02 20:57:30 +00:00
|
|
|
return self._config.get['runmode']
|