Last active
February 2, 2023 04:57
-
-
Save yuyasugano/fd5ab6749ed90a39e9464f4b5447a8b0 to your computer and use it in GitHub Desktop.
ccxt library in Python to fetch OHLCV data test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import ccxt | |
import calendar | |
from datetime import datetim | |
binance = ccxt.binance() | |
now = datetime.utcnow() | |
unixtime = calendar.timegm(now.utctimetuple()) | |
since = (unixtime - 60*60) * 1000 # UTC timestamp in milliseconds | |
ohlcv = binance.fetch_ohlcv(symbol='ETH/BTC', timeframe='5m', since=since, limit=12) | |
start_dt = datetime.fromtimestamp(ohlcv[0][0]/1000) | |
end_dt = datetime.fromtimestamp(ohlcv[-1][0]/1000) | |
# convert it into Pandas DataFrame | |
import pandas as pd | |
df = pd.DataFrame(ohlcv, columns = ['Time', 'Open', 'High', 'Low', 'Close', 'Volume']) | |
df['Time'] = [datetime.fromtimestamp(float(time)/1000) for time in df['Time']] | |
df.set_index('Time', inplace=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
take it easy