Use Dataprovider

This commit is contained in:
Matthias 2018-12-02 15:57:49 +01:00
parent b119a767de
commit 7206287b00
2 changed files with 10 additions and 6 deletions

View File

@ -5,6 +5,7 @@ including Klines, tickers, historic data
Common Interface for bot and strategy to access data.
"""
import logging
from typing import List, Dict
from pandas import DataFrame
@ -19,13 +20,13 @@ class DataProvider(object):
self._config = config
self._exchange = exchange
def refresh() -> None:
def refresh(self, pairlist: List[str]) -> None:
"""
Refresh data, called with each cycle
"""
pass
self._exchange.refresh_tickers(pairlist, self._config['ticker_interval'])
def ohlcv(self, pair: str) -> DataFrame:
def ohlcv(self, pair: str) -> List[str]:
"""
get ohlcv data for the given pair as DataFrame
"""

View File

@ -16,6 +16,7 @@ from freqtrade import (DependencyException, OperationalException,
TemporaryError, __version__, constants, persistence)
from freqtrade.data.converter import order_book_to_dataframe
from freqtrade.edge import Edge
from freqtrade.dataprovider import DataProvider
from freqtrade.exchange import Exchange
from freqtrade.persistence import Trade
from freqtrade.rpc import RPCManager, RPCMessageType
@ -57,6 +58,8 @@ class FreqtradeBot(object):
self.persistence = None
self.exchange = Exchange(self.config)
self.wallets = Wallets(self.exchange)
self.dataprovider = DataProvider(self.config, self.exchange)
pairlistname = self.config.get('pairlist', {}).get('method', 'StaticPairList')
self.pairlists = PairListResolver(pairlistname, self, self.config).pairlist
@ -167,7 +170,7 @@ class FreqtradeBot(object):
if trade.pair not in self.active_pair_whitelist])
# Refreshing candles
self.exchange.refresh_tickers(self.active_pair_whitelist, self.strategy.ticker_interval)
self.dataprovider.refresh(self.active_pair_whitelist)
# First process current opened trades
for trade in trades:
@ -317,7 +320,7 @@ class FreqtradeBot(object):
# running get_signal on historical data fetched
for _pair in whitelist:
(buy, sell) = self.strategy.get_signal(_pair, interval, self.exchange.klines(_pair))
(buy, sell) = self.strategy.get_signal(_pair, interval, self.dataprovider.ohlcv(_pair))
if buy and not sell:
stake_amount = self._get_trade_stake_amount(_pair)
if not stake_amount:
@ -579,7 +582,7 @@ class FreqtradeBot(object):
experimental = self.config.get('experimental', {})
if experimental.get('use_sell_signal') or experimental.get('ignore_roi_if_buy_signal'):
(buy, sell) = self.strategy.get_signal(trade.pair, self.strategy.ticker_interval,
self.exchange.klines(trade.pair))
self.dataprovider.ohlcv(trade.pair))
config_ask_strategy = self.config.get('ask_strategy', {})
if config_ask_strategy.get('use_order_book', False):