Tools for use in DeFi. Impermanent Loss calculations, staking and farming strategies, coingecko and pancakeswap API queries, liquidity pools and more

Overview

DeFi open source tools

Downloads License Twitter Update Update


Get Started

General Tools

CoinGecko API

PancakeSwap API



Get started


Instalation

pip install defi

Impermanent Loss

import defi.defi_tools as dft

# Impermanent loss for stableCoin & -20% return token 
dft.iloss(0.8)

-0.62%

import defi.defi_tools as dft

# Impermanent loss for stableCoin & +60% return token 
dft.iloss(1.6, numerical=True)

0.027 # Same as 2.7%


Buy&Hold vs Stake & Farming strategy

import defi.defi_tools as dft

# Exercise: Get returns after 20 days, assuming token A is a stablecoin, token B perform + 150%
# individual staking pools for both = 0.01% & 0.05% daily
# liquidity-pool farming rewards =0.2% daily & Earn by fees/day = 0.01%
dft.compare(days=20, var_A=0, var_B=150, rw_pool_A=0.01, rw_pool_B=0.05, rw_pool_AB=0.2, fees_AB=0.01)
{
 "buy_hold": "75.00%",
 "stake": "75.60%",
 "farm": "71.96%",
 "Best": "Stake"
}

DeFi protocols

import defi.defi_tools as dft

metadata, df = dft.getProtocol('Uniswap')
metadata
{
 "id": "1",
 "name": "Uniswap",
 "address": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
 "symbol": "UNI",
 "url": "https://info.uniswap.org/",
 "description": "A fully decentralized protocol for automated liquidity provision on Ethereum.\r\n",
 "chain": "Ethereum",
 "logo": "None",
 "audits": "2",
 "audit_note": "None",
 "gecko_id": "uniswap",
 "cmcId": "7083",
 "category": "Dexes",
 "chains": ["Ethereum"],
 "module": "uniswap.js"
}

Top 20 dapps TVL by chain

import defi.defi_tools as dft
import matplotlib.pyplot as plt

df = dft.getProtocols()
fig, ax = plt.subplots(figsize=(12,6))
top_20 = df.sort_values('tvl', ascending=False).head(20)

chains = top_20.groupby('chain').size().index.values.tolist()
for chain in chains:
    filtro = top_20.loc[top_20.chain==chain]
    ax.bar(filtro.index, filtro.tvl, label=chain)

ax.set_title('Top 20 dApp TVL, groupBy dApp main Chain', fontsize=14)
plt.legend()
plt.xticks(rotation=90)
plt.show()

import defi.defi_tools as dft
import pandas as pd

exchanges = ['pancakeswap', 'venus', 'uniswap','Compound', 'AAVE']

hist = [dft.getProtocol(exchange)[1] for exchange in exchanges]
df = pd.concat(hist, axis=1)
df.columns = exchanges
df.plot(figsize=(12,6))


CoinGecko API

Endpoints available, some examples:

* dft.geckoPrice("bitcoin,ethereum", "usd,eur,brl")
	# coinGecko quotes

* dft.geckoList(page=1, per_page=250)
	# full coinGecko cyptocurrency list

* dft.geckoMarkets("ethereum")
	# top 100 liquidity markets, prices, and more, for eth or other coin

* dft.geckoHistorical('cardano')
	# full history containing price, market cap and volume 

CoinGecko - Get price for coins at diferent currencies

import defi.defi_tools as dft

dft.geckoPrice("bitcoin,ethereum", "usd,eur,brl")
{"ethereum": {"usd": 2149.85, "eur": 1807.58, "brl": 12208.77},
 "bitcoin": {"usd": 60188, "eur": 50606, "brl": 341802}}

CoinGecko - Get main exchanges for a coin or token

import defi.defi_tools as dft

df = dft.geckoMarkets("ethereum")
print(df.info())
# returns top 100 ethereum quotes by volume
Index: 100 entries, IDCM to FTX.US
Data columns (total 9 columns):
 #   Column       Non-Null Count  Dtype              
---  ------       --------------  -----              
 0   base         100 non-null    object             
 1   target       100 non-null    object             
 2   last         100 non-null    float64            
 3   volume       100 non-null    float64            
 4   spread       100 non-null    float64            
 5   timestamp    100 non-null    datetime64[ns, UTC]
 6   volume_usd   100 non-null    float64            
 7   price_usd    100 non-null    float64            
 8   trust_score  100 non-null    object             
dtypes: datetime64[ns, UTC](1), float64(5), object(3)
memory usage: 7.8+ KB

CoinGecko - historical prices for a coin

import defi.defi_tools as dft

df = dft.geckoHistorical('cardano')
print(df)
                        price   market_caps  total_volumes
date                                                      
2017-10-18 00:00:00  0.026845  6.960214e+08   2.351678e+06
2017-10-19 00:00:00  0.026830  6.956220e+08   2.815156e+06
2017-10-20 00:00:00  0.030300  7.855800e+08   8.883473e+06
2017-10-21 00:00:00  0.028588  7.412021e+08   5.308857e+06
2017-10-22 00:00:00  0.027796  7.206698e+08   2.901876e+06
...                       ...           ...            ...
2021-04-13 00:00:00  1.319790  4.223483e+10   5.005258e+09
2021-04-14 00:00:00  1.422447  4.565529e+10   5.693373e+09
2021-04-15 00:00:00  1.456105  4.676570e+10   8.920293e+09
2021-04-16 00:00:00  1.478071  4.730118e+10   5.151595e+09
2021-04-17 03:47:55  1.433489  4.595961e+10   5.152747e+09

[1278 rows x 3 columns]

PancakeSwap - Get tokens prices in real time

import defi.defi_tools as dft

df = dft.pcsTokens()
print(df)
                                                         name     symbol       price  price_BNB                 updated
0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82  PancakeSwap Token       Cake     24.0636     0.0450 2021-04-17 04:29:08.332
0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c        Wrapped BNB       WBNB    534.2575     1.0000 2021-04-17 04:29:08.332
0x0F9E4D49f25de22c2202aF916B681FBB3790497B             Perlin        PRL      0.2091     0.0004 2021-04-17 04:29:08.332
0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56         BUSD Token       BUSD      1.0000     0.0019 2021-04-17 04:29:08.332
0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c         BTCB Token       BTCB  62166.5517   116.3604 2021-04-17 04:29:08.332
...                                                       ...        ...         ...        ...                     ...
0xB6802C06A441BA63624751C53C7c0708b75F06EC          FinalMoon  FINALMOON      0.0651     0.0001 2021-04-17 04:29:08.332
0x2cF0DA1EB4165d73156CE1E32450e4A0E1c1791b        FairUnicorn       FUni      0.0000     0.0000 2021-04-17 04:29:08.332
0x5CeD26185f82B07E1516d0B013c54CcBD252A4Ad            Peaches      PEACH      0.1130     0.0002 2021-04-17 04:29:08.332
0x2bA64EFB7A4Ec8983E22A49c81fa216AC33f383A        Wrapped BGL       WBGL      0.1000     0.0002 2021-04-17 04:29:08.332
0x019bE1796178516e060072004F267B59a49A0801     Pepper Finance       PEPR      0.1819     0.0003 2021-04-17 04:29:08.332

[854 rows x 5 columns]

PancakeSwap - Get pairs, liquidity, and more

import defi.defi_tools as dft

pairs = dft.pcsPairs(as_df=False)
print(pairs)
{"updated_at": 1618645355351,
 "data": {"0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82_0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c": 
 	{"pair_address": "0xA527a61703D82139F8a06Bc30097cC9CAA2df5A6",
	   "base_name": "PancakeSwap Token",
	   "base_symbol": "Cake",
	   "base_address": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
	   "quote_name": "Wrapped BNB",
	   "quote_symbol": "WBNB",
	   "quote_address": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
	   "price": "0.04503969270521829587",
	   "base_volume": "5473068.824002232134035221",
	   "quote_volume": "239997.1228321299572591638",
	   "liquidity": "1076144814.0632013827775993748053",
	   "liquidity_BNB": "2007551.221740467021401314"
	},
}

PancakeSwap - Get token info

import defi.defi_tools as dft
dft.pcsTokenInfo('cake')
{"name": "PancakeSwap Token",
 "symbol": "Cake",
 "price": "24.03353223898417117634582253598019",
 "price_BNB": "0.04503467915973850237292527741402623"
}

PancakeSwap - Get pair info

import defi.defi_tools as dft
dft.pcsPairInfo('cake','bnb')
{"pair_address": "0xA527a61703D82139F8a06Bc30097cC9CAA2df5A6",
 "base_name": "PancakeSwap Token",
 "base_symbol": "Cake",
 "base_address": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
 "quote_name": "Wrapped BNB",
 "quote_symbol": "WBNB",
 "quote_address": "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
 "price": "0.04503969270521829587",
 "base_volume": "5473068.824002232134035221",
 "quote_volume": "239997.1228321299572591638",
 "liquidity": "1076144814.0632013827775993748053",
 "liquidity_BNB": "2007551.221740467021401314"
}

PancakeSwap - Simulate LP invest

import defi.defi_tools as dft
dft.value_f, iloss = dft.iloss_simulate('cake','bnb', value=1000, base_pct_chg=50, quote_pct_chg=-25)


About

Owner
Juan Pablo Pisano
Profe @UCEMA-QUANt empresario pyme, programador, matemático, ingeniero UTN FRBA, altoNerd, Autor de libros: "Python para finanzas Quant"
Juan Pablo Pisano
Polar devices Python API and CLI.

loophole - Polar devices API About Python API for Polar devices. Command line interface included. Tested with: A360 Loop M400 Installation pip install

[roscoe] 145 Sep 14, 2022
Minecraft name sniper written in python.

⚠️ IMPORTANT ⚠️ DO NOT USE MCSNIPERPY -- READ BELOW This sniper does not support Microsoft accounts or prename / gc sniping and is MUCH harder to use

MCsniperPY 201 Dec 30, 2022
HelpDESK Dynamics

Helpdesk Application The project is a Helpdesk application (Helpdesk dynamics) where staff of an organization can raise and assign job/trouble tickets

Okeoma Ihunwo 0 Nov 14, 2021
Bancos de Dados Relacionais (SQL) na AWS com Amazon RDS.

Bancos de Dados Relacionais (SQL) na AWS com Amazon RDS Explorando o Amazon RDS, um serviço de provisionamente e gerenciamento de banco de dados relac

Lucas Magalhães 1 Dec 05, 2021
A simple Discord Mass-Ban that's still working with Member Scraper.

Mass-Ban [!] This was made for education / you can use for revenge. Please don't skid it. [!] If you want to use it, please use member scraper before

WoahThatsHot 1 Nov 20, 2021
短信发送 Python 程序(包含1000+有效接口)

短信轰炸 Python 程序(包含1000+有效接口) 前言 这是一个爬取网络上在线轰炸的接口,后通过 Python 异步 请求接口以达到 手机短信轰炸 的目的。 此为开源项目,仅供娱乐学习使用,使用者所带来的一切后果与作者无关,使用请遵守相关的法律法规,合理使用,请勿滥用。 食用方法 1. 爬取接

蓝鲸落 10.2k Jan 02, 2023
pyhakuna is a client to access the API of the time keeping service hakuna.ch.

pyhakuna pyhakuna is a client to access the API of the time keeping service hakuna.ch. The Hakuna API is – unfortunately – personal and currently does

Christian Mäder 1 Feb 15, 2022
📖 GitHub action schedular (cron) that posts a Hadith every hour on Twitter & Facebook.

Hadith Every Hour 📖 A bot that posts a Hadith every hour on Twitter & Facebook (Every 3 hours for now to avoid spamming) Follow on Twitter @HadithEve

Ananto 13 Dec 14, 2022
New developed moderation discord bot by archisha

Monitor42 New developed moderation discord bot by αrchιshα#5518. Details Prefix: 42! Commands: Moderation Use 42!help to get command list. Invite http

Kamilla Youver 0 Jun 29, 2022
Jika ada pertanyaan lebih lanjut, hubungi kontak dibawah ini. Terimakasih...

⚡ Lynx Userbot ⚡ Userbot Used for Fun on Telegram, and for Maintianing Your Group. This is a Repo Lynx-Userbot. This is Repo was Created by Axel From

29 Aug 30, 2021
Url-shortener - A url shortener made in python using the API's from the pyshorteners lib

URL Shortener Um encurtador de link feito em python usando as API's da lib pysho

Spyware 3 Jan 07, 2022
Discord Bot for Genshin Impact Wish Simulating

Genshin Inpact Wish Simulation Discord Bot Bot Links Invite Reddit Official Discord Features Discord embed reaction menu for wishes Simple code scalin

Jeffrey Shum 2 Jan 04, 2023
The most expensive version of Conway's Game of Life - running on the Ethereum Blockchain

GameOfLife The most expensive implementation of Conway's Game of Life ever - over $2,000 per step! (Probably the slowest too!) Conway's Game of Life r

75 Nov 26, 2022
Built for streamlining development of Google Assistant Actions

Apprentice Apprentice is a framework built for developing Google Actions via Dialogflow and Google Cloud (serverless) Functions. Includes: plug-and-pl

Andrew Graham-Yooll 9 May 16, 2019
A full-fledged discord bot with moderation and a lot more.

HOT-BOT-POL-POT ⭐ Star me on GitHub m'lady.... hot-bot-pol-pot is a moderation discord bot written using enhanced-dpy library with many functionalitie

Pure Cheekbones 4 Oct 08, 2022
A tool for exporting Telegram group chats into static websites, preserving chat history like mailing list archives.

tg-archive is a tool for exporting Telegram group chats into static websites, preserving chat history like mailing list archives. Preview The @fossuni

Kailash Nadh 400 Dec 27, 2022
Autov2new - Pro Auto Filter Bot V2

Pro Auto Filter Bot V2 Deploy You can deploy this bot anywhere. Watch Deploying

1 Jan 06, 2022
A discord bot for checking what linked profiles a user has to their Ubisoft account

ubisoft_discord_profiles A Discord bot for checking what linked profiles a user has to their Ubisoft account. This can be setup using an enviromental

Andrei 1 Dec 17, 2021
Currency And Gold Prices - Currency And Gold Prices For Python

Currency_And_Gold_Prices Photos from the app New Update Show range Change better

Ali HemmatNia 4 Sep 19, 2022
Drcom-pt-client - Drcom Pt version client with refresh timer

drcom-pt-client Drcom Pt version client with refresh timer Dr.com Pt版本客户端 可用于网页认

4 Nov 16, 2022