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:
parent
dbb0a6261f
commit
016232a8e9
@ -44,12 +44,13 @@ class Analyze(object):
|
||||
:param ticker: See exchange.get_ticker_history
|
||||
:return: DataFrame
|
||||
"""
|
||||
columns = {'C': 'close', 'V': 'volume', 'O': 'open', 'H': 'high', 'L': 'low', 'T': 'date'}
|
||||
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)
|
||||
cols = ['date', 'open', 'high', 'low', 'close', 'volume']
|
||||
frame = DataFrame(ticker, columns=cols)
|
||||
|
||||
frame['date'] = to_datetime(frame['date'],
|
||||
unit='ms',
|
||||
utc=True,
|
||||
infer_datetime_format=True)
|
||||
|
||||
frame.sort_values('date', inplace=True)
|
||||
return frame
|
||||
|
@ -181,26 +181,18 @@ def get_ticker(pair: str, refresh: Optional[bool] = True) -> dict:
|
||||
|
||||
# @cached(TTLCache(maxsize=100, ttl=30))
|
||||
@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
|
||||
# fetch_ohlcv returns an [[datetime,o,h,l,c,v]]
|
||||
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 []
|
||||
|
||||
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
|
||||
ohlcv = _API.fetch_ohlcv(pair, timeframe=str(tick_interval)+"m")
|
||||
|
||||
return ohlcv
|
||||
except IndexError as e:
|
||||
logger.warning('Empty ticker history. Msg %s', str(e))
|
||||
except ccxt.NetworkError as e:
|
||||
|
@ -4,6 +4,7 @@ import gzip
|
||||
import json
|
||||
import os
|
||||
from typing import Optional, List, Dict, Tuple
|
||||
from datetime import datetime
|
||||
|
||||
from freqtrade import misc
|
||||
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):
|
||||
with open(filename, "rt") as file:
|
||||
data = json.load(file)
|
||||
logger.debug("Current Start: %s", data[1]['T'])
|
||||
logger.debug("Current End: %s", data[-1:][0]['T'])
|
||||
logger.debug("Current Start: %s", format_ms_time(data[1][0]))
|
||||
logger.debug("Current End: %s", format_ms_time(data[-1:][0][0]))
|
||||
else:
|
||||
data = []
|
||||
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:
|
||||
if row not in data:
|
||||
data.append(row)
|
||||
logger.debug("New Start: %s", data[1]['T'])
|
||||
logger.debug("New End: %s", data[-1:][0]['T'])
|
||||
data = sorted(data, key=lambda data: data['T'])
|
||||
logger.debug("New Start: %s", format_ms_time(data[0][0]))
|
||||
logger.debug("New End: %s", format_ms_time(data[-1:][0][0]))
|
||||
data = sorted(data, key=lambda data: data[0])
|
||||
|
||||
misc.file_dump_json(filename, data)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def format_ms_time(date: str) -> str:
|
||||
return datetime.fromtimestamp(date/1000.0).strftime('%Y-%m-%dT%H:%M:%S')
|
||||
|
Loading…
Reference in New Issue
Block a user