Created
August 23, 2020 21:04
-
-
Save evanaze/17336ec11166b0f0d3f7d3a3c588dd31 to your computer and use it in GitHub Desktop.
Get high resolution historical Bitcoin OHLCV from Amberdata using a jumping rather than sliding window.
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
dfs = [] | |
n_days = 5 | |
for i in range(n_days): | |
print(f"Iteration: {i}") | |
# get the start and end dates in timestamps | |
startDate = results.timestamp.min() + timedelta(i-1) | |
endDate = startDate + timedelta(1) | |
# convert to UNIX format | |
startDate = str(round(startDate.timestamp()*10**3)) | |
endDate = str(round(endDate.timestamp()*10**3)) | |
# the url for our endpoint | |
url = "https://web3api.io/api/v2/market/ohlcv/btc_usd/historical" | |
# our query | |
querystring = { | |
"timeInterval": "minutes", | |
"timeFormat": "iso", | |
'startDate': startDate, | |
'endDate': endDate, | |
"exchange": "bitfinex" | |
} | |
# the API key | |
headers = {'x-api-key': api_key["AMBERDATA_API_KEY"]} | |
# the response for our query | |
payload = get_response(url, headers, querystring) | |
# we save the OHLCV data | |
bfx = payload['data']['bitfinex'] | |
# get the columns and make a dataframe | |
columns = payload['metadata']['columns'] | |
bfx_df = pd.DataFrame(bfx, columns=columns) | |
# append the dataframe to a list | |
dfs.append(bfx_df) | |
# combine the several days of OHLCV data | |
ohlcv = pd.concat(dfs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment