Keep original timestamp in dataframe

This commit is contained in:
Matthias 2023-08-18 07:05:42 +02:00
parent d97d0e4426
commit 26c89d89e4
4 changed files with 7 additions and 6 deletions

View File

@ -248,7 +248,7 @@ def trades_to_ohlcv(trades: DataFrame, timeframe: str) -> DataFrame:
timeframe_minutes = timeframe_to_minutes(timeframe)
if trades.empty:
raise ValueError('Trade-list empty.')
df = trades.set_index('timestamp')
df = trades.set_index('date', drop=True)
df_new = df['price'].resample(f'{timeframe_minutes}min').ohlc()
df_new['volume'] = df['amount'].resample(f'{timeframe_minutes}min').sum()

View File

@ -218,7 +218,7 @@ class IDataHandler(ABC):
:return: List of trades
"""
trades = trades_df_remove_duplicates(self._trades_load(pair, timerange=timerange))
trades['timestamp'] = to_datetime(trades['timestamp'], unit='ms', utc=True)
trades['date'] = to_datetime(trades['timestamp'], unit='ms', utc=True)
return trades
def trades_load_aslist(self, pair: str, timerange: Optional[TimeRange] = None) -> TradeList:

View File

@ -102,7 +102,7 @@ class JsonDataHandler(IDataHandler):
column sequence as in DEFAULT_TRADES_COLUMNS
"""
filename = self._pair_trades_filename(self._datadir, pair)
data.loc[:, 'timestamp'] = data.loc[:, 'timestamp'].view(np.int64) // 1000 // 1000
data.loc[:, 'timestamp'] = data.loc[:, 'timestamp']
trades = data[DEFAULT_TRADES_COLUMNS].values.tolist()
misc.file_dump_json(filename, trades, is_zip=self._use_zip)

View File

@ -319,11 +319,11 @@ def test_hdf5datahandler_trades_load(testdatadir):
# unfiltered load has trades before starttime
assert len(trades.loc[trades['timestamp'] < timerange.startdt]) >= 0
assert len(trades.loc[trades['timestamp'] < timerange.startts * 1000]) >= 0
# filtered list does not have trades before starttime
assert len(trades2.loc[trades2['timestamp'] < timerange.startts * 1000]) == 0
# unfiltered load has trades after endtime
assert len(trades.loc[trades['timestamp'] > timerange.stopdt]) >= 0
assert len(trades.loc[trades['timestamp'] > timerange.stopts * 1000]) >= 0
# filtered list does not have trades after endtime
assert len(trades2.loc[trades2['timestamp'] > timerange.stopts * 1000]) == 0
# assert len([t for t in trades2 if t[0] > timerange.stopts * 1000]) == 0
@ -486,7 +486,8 @@ def test_featherdatahandler_trades_load(testdatadir):
dh = get_datahandler(testdatadir, 'feather')
trades = dh.trades_load('XRP/ETH')
assert isinstance(trades, DataFrame)
assert trades.iloc[0]['timestamp'] == Timestamp('2019-10-11 00:00:11.620000+0000')
assert trades.iloc[0]['timestamp'] == 1570752011620
assert trades.iloc[0]['date'] == Timestamp('2019-10-11 00:00:11.620000+0000')
assert trades.iloc[-1]['cost'] == 0.1986231
trades1 = dh.trades_load('UNITTEST/NONEXIST')