我有一个来自websocket的数据帧:
df = pd.DataFrame(self._ws.tick,
columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
df = df.set_index('timestamp')
我这样子:
timestamp open high low close volume
2019-05-20 16:22:00 7880.0 7880.0 7880.0 7880.0 2000
2019-05-20 16:22:05 7880.0 7880.0 7880.0 7880.0 0
2019-05-20 16:22:10 7880.0 7881.5 7880.0 7881.0 17725
2019-05-20 16:22:15 7881.0 7881.5 7881.0 7881.5 32437
然后我获得第一行的时间戳并将其转换为Unix时间:
frow = df.index.min()
since = datetime.timestamp(ldf_time) * 1000
利用这段时间来请求历史记录OHLC:
ohlc_1m = pd.DataFrame(fetch_ohlcv(since=since),
columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
ohlc_1m['timestamp'] = pd.to_datetime(ohlc_1m['timestamp'], unit='ms')
ohlc_1m = ohlc_1m.set_index('timestamp')
得到了:
timestamp open high low close volume
2019-05-20 16:22:00 7880.0 7880.0 7880.0 7880.0 56426
2019-05-20 16:21:00 7880.0 7880.0 7880.0 7880.0 46543
2019-05-20 16:20:00 7880.0 7881.5 7880.0 7881.0 63656
2019-05-20 16:19:00 7881.0 7881.5 7881.0 7881.5 56835
现在,如何在流式传输时将第二个数据帧添加到第一个数据帧的开头?我需要实时从第一个数据框中获取数据以计算指标。