Update: I now made this into a package called defillama2. You can install it via pip install defillama2
.
DefiLlama recently released their token price API but I couldn’t find any python clients for it. So I decided to write one myself. In total, DefiLlama offers five APIs: TVL, coins, stabelcoins, yields, and abi-decoder. I finished the TVL API and here are the things you can do with it:
Get historical DeFi TVL on all chains
Get historical TVL of a chain
Get current TVL of all chains
Get current TVL of a protocol
Get current TVL of a protocol by chain
Get historical TVL of a protocol by chain
Get fundamentals for all protocols
To use it, import/load this script, instantiate a DefiLlama object, and invoke method calls. All method calls return a tidy data frame that’s ready for downstream analysis.
obj = DefiLlama()
# major method calls
obj.get_defi_hist_tvl() # don't give any input
obj.get_chain_hist_tvl('Arbitrum') # or any chain name
obj.get_chains_curr_tvl() # don't give any input
obj.get_protocol_curr_tvl('gmx') # or any protocol name
obj.get_protocol_curr_tvl_by_chain('gmx') # or any protocol name
obj.get_protocol_hist_tvl_by_chain('gmx') # or any protocol name
obj.get_protocols_fundamentals() # don't give any input
Code
Python client for DeFiLlama’s API
Referrals
This section contains affiliate links to crypto products. If you click on the link and use the product, I may receive a small commission at no cost to you. I only link to products I use myself.
Get 5% discount when trading on GMX.
Juno Finance offers free onramp to Arbitrum, Optimism and Solana, a high interest bearing checking account (currently at 5%), and a great loyalty program that gives ledger, gift cards, and 5% cash back for spending. You will get $10 and 500 JCOIN if you use my referral link to open an account and fund it with $50 worth crypto or more. Available to US persons and requires KYC.
If you enjoyed this article and would like to buy me a coffee, you can send ETH, WBTC, AVAX, BNB, USDC, USDT to 0x783c5546C863f65481BD05Fd0e3FD5f26724604E, or you can tip me sat. Thank you and have a great day!