Revert OHLVC dataformat to ccxt format

* Also fixes backtesting - but data must be refreshed for now as no
conversation is happening yet
This commit is contained in:
Matthias Voppichler 2018-03-25 13:32:46 +02:00
parent dbb0a6261f
commit 016232a8e9
3 changed files with 23 additions and 25 deletions

View File

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

View File

@ -181,26 +181,18 @@ def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
# @cached(TTLCache(maxsize=100, ttl=30)) # @cached(TTLCache(maxsize=100, ttl=30))
@retrier @retrier
def get_ticker_history(pair: str, tick_interval) -> List[Dict]: def get_ticker_history(pair: str, tick_interval) -> List[List]:
# 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 'fetchOHLCV' not in _API.has or not _API.has['fetchOHLCV']: if 'fetchOHLCV' not in _API.has or not _API.has['fetchOHLCV']:
logger.warning('Exhange %s does not support fetching historical candlestick data.', _API.name) logger.warning('Exhange %s does not support fetching historical candlestick data.',
_API.name)
return [] return []
try: try:
history = _API.fetch_ohlcv(pair, timeframe=str(tick_interval)+"m") ohlcv = _API.fetch_ohlcv(pair, timeframe=str(tick_interval)+"m")
history_json = []
for candlestick in history: return ohlcv
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: except IndexError as e:
logger.warning('Empty ticker history. Msg %s', str(e)) logger.warning('Empty ticker history. Msg %s', str(e))
except ccxt.NetworkError as e: except ccxt.NetworkError as e:

View File

@ -4,6 +4,7 @@ import gzip
import json import json
import os import os
from typing import Optional, List, Dict, Tuple from typing import Optional, List, Dict, Tuple
from datetime import datetime
from freqtrade import misc from freqtrade import misc
from freqtrade.exchange import get_ticker_history from freqtrade.exchange import get_ticker_history
@ -135,8 +136,8 @@ def download_backtesting_testdata(datadir: str, pair: str, interval: int = 5) ->
if os.path.isfile(filename): if os.path.isfile(filename):
with open(filename, "rt") as file: with open(filename, "rt") as file:
data = json.load(file) data = json.load(file)
logger.debug("Current Start: %s", data[1]['T']) logger.debug("Current Start: %s", format_ms_time(data[1][0]))
logger.debug("Current End: %s", data[-1:][0]['T']) logger.debug("Current End: %s", format_ms_time(data[-1:][0][0]))
else: else:
data = [] data = []
logger.debug("Current Start: None") logger.debug("Current Start: None")
@ -146,10 +147,14 @@ def download_backtesting_testdata(datadir: str, pair: str, interval: int = 5) ->
for row in new_data: for row in new_data:
if row not in data: if row not in data:
data.append(row) data.append(row)
logger.debug("New Start: %s", data[1]['T']) logger.debug("New Start: %s", format_ms_time(data[0][0]))
logger.debug("New End: %s", data[-1:][0]['T']) logger.debug("New End: %s", format_ms_time(data[-1:][0][0]))
data = sorted(data, key=lambda data: data['T']) data = sorted(data, key=lambda data: data[0])
misc.file_dump_json(filename, data) misc.file_dump_json(filename, data)
return True return True
def format_ms_time(date: str) -> str:
return datetime.fromtimestamp(date/1000.0).strftime('%Y-%m-%dT%H:%M:%S')