Created
March 28, 2022 09:33
-
-
Save dmihal/1d0f7da0b0b5ffd941ceb272a9864c9a to your computer and use it in GitHub Desktop.
crypto_fees_2021.py
This file contains hidden or 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
import requests | |
import pandas as pd | |
from datetime import date, timedelta | |
def cryptofees(_query_str): | |
fees_requests = requests.get("https://cryptofees.info/api/v1/feesByDay?" + _query_str) | |
json_data = fees_requests.json() | |
_df = pd.json_normalize(json_data['data'], record_path=['data'], meta=['id'], errors='ignore') | |
# _df.id.replace(id_dict, inplace=True) | |
return _df | |
id_dict = { | |
# 'eth': 'Ethereum', | |
# 'bsc': 'Binance Smart Chain', | |
# 'uniswap-v3': 'Uniswap V3', | |
# 'uniswap-v2': 'Uniswap V2', | |
# 'compound': 'Compound', | |
# 'aave-v2': 'Aave V2', | |
# 'sushiswap-ethereum': 'Sushiswap - Ethereum', | |
# 'trader-joe': 'Trade Joe', | |
# 'terraswap': 'Terraswap', | |
# 'aave-v2-polygon-proto': 'Aave - Polygon', | |
'btc': 'Bitcoin', | |
# 'maker': 'MakerDAO', | |
# 'avalanche-c-chain': 'Avalanche C-chain', | |
# 'aave-v2-avalanche-proto': 'Aave V2 - Avalanche', | |
# 'solana': 'Solana', | |
# 'quickswap': 'Quickswap', | |
# 'ens': 'Ethereum Naming Service', | |
# 'balancerv2': 'Balance V2', | |
# 'bancor': 'Bancor', | |
# 'polygon-pos': 'Polygon', | |
# 'pangolin': 'Pangolin', | |
# 'sushiswap-polygon': 'Sushiswap - Polygon', | |
# 'arbitrum-one': 'Arbitrum', | |
# 'fantom': 'Fantom', | |
# 'uniswap-polygon': 'Uniswap - Polygon', | |
# 'sushiswap-arbitrum-one': 'Sushiswap - Arbitrum', | |
# 'ada': 'Cardano', | |
# 'balancerv2-polygon': 'Balancer - Polygon', | |
# 'uniswap-arbitrum': 'Uniswap - Arbitrum', | |
# 'balancer-v1': 'Balancer V1', | |
# 'liquity': 'Liquity', | |
# 'terra': 'Terra', | |
# 'dfyn': 'Dfyn', | |
# 'aave-v1': 'Aave V1', | |
# 'tornado-ethereum': 'Tornado', | |
# 'hop-optimism': 'Hop - Optimism', | |
# 'ren': 'Ren', | |
# 'hop-polygon': 'Hop - Polygon', | |
# 'hop-arbitrum': 'Hop - Arbitrum', | |
# 'doge': 'Doge', | |
# 'xdai': 'xDAI', | |
# 'xtz': 'Tezos', | |
# 'spookyswap': '', | |
# 'abracadabra-ethereum': '', | |
# 'abracadabra-bsc': '', | |
# 'abracadabra-arbitrum-one': '', | |
# 'abracadabra-fantom': '', | |
# 'abracadabra-avalanche': '', | |
# 'polkadot': 'Polkadot', | |
# 'balancerv2-arbitrum': 'Balancer V2 - Arbitrum', | |
# 'polymarket': 'Polymarket', | |
# 'bsv': 'Bitcoin Satoshi Vision', | |
# 'zilliqa': 'Zilliqa', | |
# 'honeyswap': 'HoneySwap', | |
# 'xlm': 'Stellar', | |
# 'xrp': 'Ripple', | |
# 'ltc': 'Litecoin', | |
# 'sushiswap-fantom': 'Sushiswap - Fantom', | |
# 'swapr-xdai': 'Swapr - xDAI', | |
# 'hop-xdai': 'Hop - xDAI', | |
# 'synthetix-mainnet': 'Synthetix', | |
# 'mstable': 'mStable', | |
# 'avalanche-x-chain': 'Avalanche X-chain', | |
# 'swapr-arbitrum': 'Swapr - Arbitrum', | |
# 'xmr': 'Monero', | |
# 'bch': 'Bitcoin Cash', | |
# 'aave-v2-amm': 'Aave V2', | |
# 'swapr-ethereum': 'Swapr - Ethereum', | |
# 'kusama': 'Kusama', | |
# 'uniswap-v1': 'Uniswap V1', | |
# 'avalanche-p-chain': 'Avalanche P-chain', | |
# 'linkswap': 'Linkswap' | |
} | |
column_dict = { | |
'id': '', | |
'name': '', | |
'fee': 'Fees', | |
} | |
date_obj = pd.date_range(start="2021-01-01", end='2021-12-31', freq='D').to_pydatetime().tolist() | |
# date_obj = pd.date_range(start="2021-01-01", end="2021-01-31", freq='D').to_pydatetime().tolist() | |
date_str = [i.strftime('%Y-%m-%d') for i in date_obj] | |
separator = "," | |
get_date = separator.join(date_str) | |
query_str='' | |
df_orig = pd.DataFrame() | |
# for i in ['polygon']: | |
for i in list(id_dict.keys()): | |
print('started' + i) | |
for j in date_obj: | |
try: | |
txt = i + '=' + j.strftime('%Y-%m-%d') + '&' | |
cryptofees(txt) | |
except: | |
txt='' | |
pass | |
else: | |
query_str += txt | |
df_orig = pd.concat([df_orig, cryptofees(txt)], axis=0).reset_index(drop=True) | |
print('finished' + i) | |
df_orig.to_csv('cryptofees_yearly.csv') | |
print(df_orig) | |
# df_orig['year'] = pd.to_datetime(df_orig['date']).dt.year | |
# df_final = df_orig.groupby(['id', 'year']).sum() | |
# df_final.to_csv('cryptofees_yearly.csv') | |
# print(df_final) | |
# pd.DataFrame(missing_list).to_csv('missing_protocol_dates_1.csv') | |
# for each protocol and each day, see if data exists | |
# if data exists add it to a data frame as date, protocol, fees |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment