0

New here and new to newish to Python. I've been spinning my wheels for the better part of a week and I am not getting the results I expect. I have the historic 1 min trade data in csv with labeled columns of datetime, price, and volume. Like below:

                     datetime     price    volume
0         2013-10-07 20:50:30    123.61  0.100000
1         2013-10-08 02:58:35    123.91  1.000000

But I'd like it to read out exactly as below this was from Huobi's (and Binance) 1-min candles t,o,h,l,c,v pulled from ccxt:

                                 t         o         h         l         c         v
0        2017-10-27 00:00:00+00:00   5869.70   5869.70   5869.70   5869.70  0.985300
1        2017-10-27 00:01:00+00:00   5869.70   5869.70   5869.70   5869.70  0.000000
import pandas as pd

# Load data into a DataFrame from CSV

**# This line here after loading the DataFrame is where I'm lost**

# Resample the DataFrame to 1-minute intervals and calculate the open, high, low, and close prices and volume
candles = df.resample('1T').agg({'price': ['first', 'max', 'min', 'last'], 'volume': 'sum'})

candles.columns = ['o', 'h', 'l', 'c', 'v']

print(candles)

Thanks for helping possibly point this in the right direction.

Time (t) is now the index and it's shift down a row. I expected 0,1 etc. and o,h,l has no data.

                      o   h   l         c         v
t
2013-10-07 20:50:30 NaN NaN NaN    123.61  0.100000
2013-10-08 02:58:35 NaN NaN NaN    123.91  1.000000

Like this format:

                                 t         o         h         l         c         v
0        2017-10-27 00:00:00+00:00   5869.70   5869.70   5869.70   5869.70  0.985300
1        2017-10-27 00:01:00+00:00   5869.70   5869.70   5869.70   5869.70  0.000000
Progman
  • 16,827
  • 6
  • 33
  • 48
  • If you have 1 minute data, you can build OHLC data only for _higher_ time frames 5min, 15min, 1hr, etc. Please note that in your example time between trades is ~6 hours. – Yuri Ginsburg Jan 21 '23 at 23:14
  • Thanks Yuri. I didn't know this about not being able to build data for anything less than 5mins. and the example time being 6 hours is where there was an oversight. This was from their downloadable csv's in their site. Back to the struggle to get 1min candles from the Kraken's Rest API - which is another complete uphill battle that I've run up against. – Bread Bread Jan 22 '23 at 03:41

0 Answers0