Skip to content

Instantly share code, notes, and snippets.

@evanaze
Last active August 21, 2020 16:41
Show Gist options
  • Save evanaze/36f739885f1f229d417a19b003de6a4b to your computer and use it in GitHub Desktop.
Save evanaze/36f739885f1f229d417a19b003de6a4b to your computer and use it in GitHub Desktop.
# helper functions
def to_df(response):
"Turns the repsonse into a dataframe"
# load the data into a DataFrame and rename the columns
data = pd.DataFrame(response["data"]).rename({0: "date", 1: "volatility", 2: "sharpe"}, axis=1)
# turn the date column into datetime type
data["date"] = pd.to_datetime(data["date"])
# set the date as the index
data.set_index("date", inplace=True)
return data
def get_sharpe(token):
"Gets the Sharpe Ratio for the token"
# the URL for the response
url = f"https://web3api.io/api/v2/market/metrics/{token}/historical/sharpe"
# get the response
response = get_response(url, headers)
try:
return response
except TypeError:
print("No Response")
# the Sharpe Data querystring
querystring = {
"startDate": start,
"endDate": end,
"timeFrame": "1d"
}
# the list of tokens we wish to get data for
tokens = ['btc', 'eth', 'link', 'xlm', 'bch']
# a dictionary to save our returned data
results = {}
# lets iterate over the tokens of interest
for token in tokens:
# get the token name in lower case
token = token.lower()
# get the result
token_sharpe = get_sharpe(token)
# if we got a response
if token_sharpe:
# if the response has data
if token_sharpe["data"]:
# save the result as a dataframe
results[token] = to_df(token_sharpe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment