0

Just new to Python programming. So I have crypto OHLCV data on the four hour timeframe. I want to convert them to daily, weekly, and monthly data. The data is in a csv file. Here is a sample:

BTCUSDT 06/01/2021 , 08:00:00 37253.82 37894.81 36478 36704.99 14647.05841 BTCUSDT 06/01/2021 , 12:00:00 36706.8 37443.72 36561.89 36831.58 10095.34783 BTCUSDT 06/01/2021 , 16:00:00 36831.58 36939.81 35902.43 36596.62 13819.88776 BTCUSDT 06/01/2021 , 20:00:00 36596.63 37440 35666 36235.29 22029.82561 BTCUSDT 06/02/2021 , 00:00:00 36235.28 36492.89 35716.66 35973.87 12918.45296 BTCUSDT 06/02/2021 , 04:00:00 35973.86 36800 35873.08 36693.09 7724.091195 ETHUSDT 06/01/2021 , 08:00:00 2706.15 2740 2612.63 2630.79 190770.2435 ETHUSDT 06/01/2021 , 12:00:00 2630.66 2716.33 2615.27 2652.53 166661.3018 ETHUSDT 06/01/2021 , 16:00:00 2652.37 2672.6 2547.12 2624.09 263021.1097 ETHUSDT 06/01/2021 , 20:00:00 2624.23 2666 2523.74 2568.49 294840.3197 ETHUSDT 06/02/2021 , 00:00:00 2568.62 2588 2535.72 2634.57 125258.4908 BNBUSDT 06/01/2021 , 08:00:00 353.37 364.4 343.42 345.77 727379.1453 BNBUSDT 06/01/2021 , 12:00:00 345.74 360 343.74 349.06 599663.416 BNBUSDT 06/01/2021 , 16:00:00 349.14 357.21 339.48 353.79 802504.2916 BNBUSDT 06/01/2021 , 20:00:00 353.83 358.18 342 348.85 700365.912 BNBUSDT 06/02/2021 , 00:00:00 348.85 355.19 345.77 349.74 377847.017

(The order of the columns from left to right: symbol, opening time, open, high, low, close, volume)

Source of data is from the binance. I could have just opted to download the daily timeframe, etc but I can't because:

  • it takes a lot of time to download data across different timeframes so I just opted to download lower timeframe and build higher timeframe data from them
  • I frequently get errors when downloading from the binance api (bec I probably reached the max limit of requests) so I'm minimizing my downloads to just the lower timeframes
  • lastly, when I download the daily, the opening data seems to start at 8:00:00 instead of at 00:00:00. Probably because the timezone in my area is UTC + 8.

I have seen a few variations of my question asked online with the solutions given using the pandas library. But being a newbie, I have difficulty understanding them (stuff like the index) so I prefer to not use libraries like pandas.

jomx99
  • 3
  • 4
  • You will really need to understand some basics of Python and at least some very simple examples of Pandas. It is very difficult for a newbie to do this task (resample OHLCV and deal with datetimes) without the _help_ of Pandas. There is no better way to do this. Please try to breakdown the problems one-by-one. Downloading from Binance via API / OHLCV candlestick resample / Timezone conversions are three different topics. Assuming you are really new to Python and the community, I am throwing some keywords hope it helps: `pd.read_csv()`, `pd.resample()`, `pd.to_datetime()`. – tyson.wu Apr 25 '22 at 13:20
  • Hi Tyson. Thanks for the advice. May I ask if there is a way to "turn off the timezone conversion" in binance (not sure about the correct term so I don't know what to type in the google search bar) As I've said, in the daily, the opening is set at 8:00:00 and the closing is based on the next day at 7:59:59. The weekly and monthly might also be the same. But in the intraday intervals, its fine. So when i look at the charts, it's confusing when I zoom in on the daily interval. – jomx99 Apr 25 '22 at 13:40
  • A convenient way to handle datetime info is to start with Timestamp - it is the number of seconds lapsed since 1970-01-01, so it is free from annoying timezone problems. eg. the current timestamp when I am typing this is 1650916916. From my experience this is commonly notated as field `t` in Binance API. Keywords on dealing with this is eg. pandas convert timestamp to datetime. Note that this is not a Binance-specific thing, it is common in practical programming. – tyson.wu Apr 25 '22 at 20:03

0 Answers0