Refactor exchange to class

This commit is contained in:
xmatthias
2018-06-17 12:41:33 +02:00
parent e3c91df081
commit 21edcbdc27
5 changed files with 356 additions and 371 deletions

View File

@@ -8,7 +8,7 @@ from typing import Optional, List, Dict, Tuple, Any
import arrow
from freqtrade import misc, constants
from freqtrade.exchange import get_ticker_history
from freqtrade.exchange import Exchange
from freqtrade.arguments import TimeRange
logger = logging.getLogger(__name__)
@@ -183,6 +183,7 @@ def load_cached_data_for_updating(filename: str,
def download_backtesting_testdata(datadir: str,
exchange: Exchange,
pair: str,
tick_interval: str = '5m',
timerange: Optional[TimeRange] = None) -> None:
@@ -216,7 +217,8 @@ def download_backtesting_testdata(datadir: str,
logger.debug("Current Start: %s", misc.format_ms_time(data[1][0]) if data else 'None')
logger.debug("Current End: %s", misc.format_ms_time(data[-1][0]) if data else 'None')
new_data = get_ticker_history(pair=pair, tick_interval=tick_interval, since_ms=since_ms)
new_data = exchange.get_ticker_history(pair=pair, tick_interval=tick_interval,
since_ms=since_ms)
data.extend(new_data)
logger.debug("New Start: %s", misc.format_ms_time(data[0][0]))

View File

@@ -14,7 +14,7 @@ from pandas import DataFrame
from tabulate import tabulate
import freqtrade.optimize as optimize
from freqtrade import exchange
from freqtrade.exchange import Exchange
from freqtrade.analyze import Analyze
from freqtrade.arguments import Arguments
from freqtrade.configuration import Configuration
@@ -61,7 +61,7 @@ class Backtesting(object):
self.config['exchange']['password'] = ''
self.config['exchange']['uid'] = ''
self.config['dry_run'] = True
exchange.init(self.config)
self.exchange = Exchange(self.config)
@staticmethod
def get_timeframe(data: Dict[str, DataFrame]) -> Tuple[arrow.Arrow, arrow.Arrow]:
@@ -130,7 +130,7 @@ class Backtesting(object):
stake_amount = args['stake_amount']
max_open_trades = args.get('max_open_trades', 0)
fee = exchange.get_fee()
fee = self.exchange.get_fee()
trade = Trade(
open_rate=buy_row.close,
open_date=buy_row.date,
@@ -256,7 +256,7 @@ class Backtesting(object):
if self.config.get('live'):
logger.info('Downloading data for all pairs in whitelist ...')
for pair in pairs:
data[pair] = exchange.get_ticker_history(pair, self.ticker_interval)
data[pair] = self.exchange.get_ticker_history(pair, self.ticker_interval)
else:
logger.info('Using local backtesting data (using whitelist in given config) ...')