have backtest and dry-mode working

partially revert d20e3f79be - Changing the
OHLVC format should not be done at this time
This commit is contained in:
Matthias Voppichler 2018-03-24 19:51:40 +01:00
parent 85af68d807
commit ab6e32f6bb
3 changed files with 44 additions and 12 deletions

View File

@ -14,3 +14,11 @@ class OperationalException(BaseException):
Requires manual intervention. Requires manual intervention.
This happens when an exchange returns an unexpected error during runtime. This happens when an exchange returns an unexpected error during runtime.
""" """
class NetworkException(BaseException):
"""
Network related error.
This could happen when an exchange is congested, unavailable, or the user
has networking problems. Usually resolves itself after a time.
"""

View File

@ -44,13 +44,13 @@ class Analyze(object):
:param ticker: See exchange.get_ticker_history :param ticker: See exchange.get_ticker_history
:return: DataFrame :return: DataFrame
""" """
cols = ['date', 'open', 'high', 'low', 'close', 'volume'] columns = {'C': 'close', 'V': 'volume', 'O': 'open', 'H': 'high', 'L': 'low', 'T': 'date'}
frame = DataFrame(ticker, columns=cols) frame = DataFrame(ticker) \
.rename(columns=columns)
if 'BV' in frame:
frame.drop('BV', 1, inplace=True)
frame['date'] = to_datetime(frame['date'], utc=True, infer_datetime_format=True)
frame['date'] = to_datetime(frame['date'],
unit='ms',
utc=True,
infer_datetime_format=True)
frame.sort_values('date', inplace=True) frame.sort_values('date', inplace=True)
return frame return frame

View File

@ -6,11 +6,12 @@ import ccxt
from random import randint from random import randint
from typing import List, Dict, Any, Optional from typing import List, Dict, Any, Optional
from cachetools import cached, TTLCache from cachetools import cached, TTLCache
from datetime import datetime
import arrow import arrow
import requests import requests
from freqtrade import OperationalException from freqtrade import OperationalException, NetworkException
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -183,11 +184,34 @@ def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
def get_ticker_history(pair: str, tick_interval) -> List[Dict]: def get_ticker_history(pair: str, tick_interval) -> List[Dict]:
# TODO: tickers need to be in format 1m,5m # TODO: tickers need to be in format 1m,5m
# fetch_ohlcv returns an [[datetime,o,h,l,c,v]] # fetch_ohlcv returns an [[datetime,o,h,l,c,v]]
if not _API.markets: if 'fetchOHLCV' not in _API.has or not _API.has['fetchOHLCV']:
_API.load_markets() raise OperationalException(
ohlcv = _API.fetch_ohlcv(pair, str(tick_interval)+'m') 'Exhange {} does not support fetching historical candlestick data.'.format(
_API.name)
)
return ohlcv try:
history = _API.fetch_ohlcv(pair, timeframe=str(tick_interval)+"m")
history_json = []
for candlestick in history:
history_json.append({
'T': datetime.fromtimestamp(candlestick[0]/1000.0).strftime('%Y-%m-%dT%H:%M:%S.%f'),
'O': candlestick[1],
'H': candlestick[2],
'L': candlestick[3],
'C': candlestick[4],
'V': candlestick[5],
})
return history_json
except IndexError as e:
logger.warning('Empty ticker history. Msg %s', str(e))
return []
except ccxt.NetworkError as e:
raise NetworkException(
'Could not load ticker history due to networking error. Message: {}'.format(e)
)
except ccxt.BaseError as e:
raise OperationalException('Could not fetch ticker data. Msg: {}'.format(e))
def cancel_order(order_id: str) -> None: def cancel_order(order_id: str) -> None:
@ -235,7 +259,7 @@ def get_fee_taker() -> float:
def get_fee() -> float: def get_fee() -> float:
return _API.fees['trading'] return get_fee_taker()
def get_wallet_health() -> List[Dict]: def get_wallet_health() -> List[Dict]: