Guest User

Untitled

a guest
Oct 17th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. # install pandas with pip install pandas, perfect library for manipulate our dataset
  2. import pandas as pd
  3. symbol = 'BTC/USDT'
  4. print(symbol)
  5. ohlcv_dataframe = pd.DataFrame()
  6. for hours in range(4320,0,-600): # 6 month is around 24hours * 30days * 6 = 4320
  7. if binance.has['fetchOHLCV']:
  8. time.sleep (binance.rateLimit / 1000) # time.sleep wants seconds
  9. # the limit from binance is 1000 timesteps
  10. ohlcv = binance.fetch_ohlcv(symbol, '1d', since=current_milli_time(hours),
  11. limit=1000)
  12. ohlcv_dataframe = ohlcv_dataframe.append(pd.DataFrame(ohlcv))
  13. print(hours)
  14. # We are changing the name of the columns, important to use trading indicators later on
  15. ohlcv_dataframe['date'] = ohlcv_dataframe[0]
  16. ohlcv_dataframe['open'] = ohlcv_dataframe[1]
  17. ohlcv_dataframe['high'] = ohlcv_dataframe[2]
  18. ohlcv_dataframe['low'] = ohlcv_dataframe[3]
  19. ohlcv_dataframe['close'] = ohlcv_dataframe[4]
  20. ohlcv_dataframe['volume'] = ohlcv_dataframe[5]
  21. ohlcv_dataframe = ohlcv_dataframe.set_index('date')
  22. # Change the timstamp to date in UTC
  23. ohlcv_dataframe = ohlcv_dataframe.set_index(
  24. pd.to_datetime(ohlcv_dataframe.index, unit='ms').tz_localize('UTC'))
  25. ohlcv_dataframe.drop([0,1,2,3,4,5], axis=1, inplace=True)
  26. # Create CSV file from our panda dataFrame
  27. ohlcv_dataframe.to_csv('data_since6months_freq15min'+symbol.split('/')[0]+'.csv')
Add Comment
Please, Sign In to add comment