Skip to content

Instantly share code, notes, and snippets.

@thecodingrobot
Created January 13, 2019 12:27
Show Gist options
  • Save thecodingrobot/23da93e210a40619f64e7260885aa6ae to your computer and use it in GitHub Desktop.
Save thecodingrobot/23da93e210a40619f64e7260885aa6ae to your computer and use it in GitHub Desktop.
import ccxt
import pandas as pd
import time
bfx = ccxt.bitfinex2()
def fetch(since, limit=1000):
header = ['Timestamp', 'Open', 'High', 'Low', 'Close', 'Volume']
data = bfx.fetch_ohlcv('BTC/USD', '1h', since=since, limit=limit)
df = pd.DataFrame(data, columns=header).set_index('Timestamp')
df['Date'] = pd.to_datetime(df.index, unit='ms')
return df
start_ts = 1483228800000
max_ts = 1547377200000
df = x(since=start_ts)
while df.index.max() < max_ts:
df = df.append(x(since=df.index.max() + 1))
time.sleep(5)
print(df)
df.to_csv('bfx.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment