All Projects â†’ shanefontaine â†’ Uniswap Python

shanefontaine / Uniswap Python

Licence: mit
🦄 The unofficial Python client for the Uniswap exchange.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Uniswap Python

uniswap-python
🦄 The unofficial Python client for the Uniswap exchange.
Stars: ✭ 533 (+179.06%)
Mutual labels:  wrapper, crypto, trading, currency, trading-api, exchange, trade, eth, dex
Ccxt
A JavaScript / Python / PHP cryptocurrency trading API with support for more than 100 bitcoin/altcoin exchanges
Stars: ✭ 22,501 (+11680.63%)
Mutual labels:  api, ethereum, trade, eth, trading, exchange, crypto
Ccxt Rest
Open Source Unified REST API of 100+ Crypto Exchange Sites (18k+ docker pulls) - https://ccxt-rest.io/
Stars: ✭ 210 (+9.95%)
Mutual labels:  api, ethereum, eth, trading, exchange, crypto
Coinbase Pro Node
Coinbase Pro API written in TypeScript and covered by tests.
Stars: ✭ 116 (-39.27%)
Mutual labels:  api, ethereum, trading-api, trading, exchange
Ccxt.net
CCXT.NET – CryptoCurrency eXchange Trading Library for .NET
Stars: ✭ 89 (-53.4%)
Mutual labels:  api, trade, trading, exchange, crypto
Kupi Terminal
Ccxt based, open source, customized, extendable trading platform that supports 130+ crypto exchanges.
Stars: ✭ 104 (-45.55%)
Mutual labels:  trade, trading-api, trading, exchange, crypto
Qtbitcointrader
Secure multi crypto exchange trading client
Stars: ✭ 520 (+172.25%)
Mutual labels:  ethereum, trade, trading, exchange, crypto
Python Poloniex
Poloniex API wrapper for Python 2.7 & 3
Stars: ✭ 557 (+191.62%)
Mutual labels:  api, wrapper, trading-api, trading, exchange
Coinbasepro Python
The unofficial Python client for the Coinbase Pro API
Stars: ✭ 1,386 (+625.65%)
Mutual labels:  wrapper, ethereum, trading, exchange
Coinapi Sdk
SDKs for CoinAPI
Stars: ✭ 238 (+24.61%)
Mutual labels:  api, ethereum, trading-api, exchange
b2s-trader
Application to automate trading process
Stars: ✭ 22 (-88.48%)
Mutual labels:  crypto, trading, exchange, trade
Wolfbot
Crypto currency trading bot written in TypeScript for NodeJS
Stars: ✭ 335 (+75.39%)
Mutual labels:  ethereum, trade, trading, exchange
Coinbase Pro Node
DEPRECATED — The official Node.js library for Coinbase Pro
Stars: ✭ 782 (+309.42%)
Mutual labels:  ethereum, trade, trading-api, trading
Cryptocurrency Portfolio
Google Sheets automatic creation with Google Apps Script (GAS) for managing a cryptocurrency tracking spreadsheet with multi exchanges
Stars: ✭ 134 (-29.84%)
Mutual labels:  api, currency, exchange, crypto
Socktrader
🚀 Websocket based trading bot for 💰cryptocurrencies 📈
Stars: ✭ 152 (-20.42%)
Mutual labels:  trading, exchange, crypto
Crypto Trading Bot
Cryptocurrency trading bot in javascript for Bitfinex, Bitmex, Binance, FTX, Bybit ... (public edition)
Stars: ✭ 1,089 (+470.16%)
Mutual labels:  trading, exchange, crypto
Bot18
Bot18 is a high-frequency cryptocurrency trading bot developed by Zenbot creator @carlos8f
Stars: ✭ 157 (-17.8%)
Mutual labels:  ethereum, eth, trading
Telegram Kraken Bot
Python bot to trade on Kraken via Telegram
Stars: ✭ 156 (-18.32%)
Mutual labels:  ethereum, trade, eth
Currency
Handles currency calculations, storage etc
Stars: ✭ 109 (-42.93%)
Mutual labels:  api, currency, exchange
Jesse
An advanced crypto trading bot written in Python
Stars: ✭ 1,038 (+443.46%)
Mutual labels:  trade, trading, crypto

uniswap-python

GitHub Actions Downloads License Typechecking: Mypy Code style: black

The unofficial Python client for Uniswap.

The authors are in no way affiliated with or funded by Uniswap, uniswap.io, or any subsidiaries or affiliates of any of the previously mentioned entities.

This package supports Uniswap V2 as of version 0.4.0.

Functionality

  • A simple to use Python wrapper for all available contract functions and variables
  • Simple parsing of data returned from the Uniswap contract

Under Development

  • Better error handling

Getting Started

This README is documentation on the syntax of the python client presented in this repository. See function docstrings for full syntax details. This API attempts to present a clean interface to Uniswap, but in order to use it to its full potential, you must familiarize yourself with the official Uniswap documentation.

You may manually install the project or use pip:

pip install uniswap-python

# or

pip install git+git://github.com/shanefontaine/uniswap-python.git

Environment Variables

The program expects an environment variables to be set in order to run the program. You can use an Infura node, since the transactions are being signed locally and broadcast as a raw transaction. The environment variable is:

PROVIDER  # HTTP Provider for web3

Public Client

Only some endpoints in the API are available to everyone. The public endpoints can be reached using PublicClient

from uniswap import Uniswap
address = "YOUR ADDRESS"          # or "0x0000000000000000000000000000000000000000", if you're not making transactions
private_key = "YOUR PRIVATE KEY"  # or None, if you're not going to make transactions
uniswap_wrapper = Uniswap(address, private_key, version=2)  # pass version=2 to use Uniswap v2
eth = "0x0000000000000000000000000000000000000000"
bat = "0x0D8775F648430679A709E98d2b0Cb6250d2887EF"
dai = "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359"

Market Methods

uniswap_wrapper.get_fee_maker()
uniswap_wrapper.get_fee_taker()
# Get the public price for ETH to Token trades with an exact input.
uniswap_wrapper.get_eth_token_input_price(bat, 1*10**18)
uniswap_wrapper.get_eth_token_input_price(dai, 5*10**18)
# Get the public price for token to ETH trades with an exact input.
uniswap_wrapper.get_token_eth_input_price(bat, 1*10**18)
uniswap_wrapper.get_token_eth_input_price(dai, 5*10**18)
# Get the public price for ETH to Token trades with an exact output
uniswap_wrapper.get_eth_token_output_price(bat, 1*10**18)
uniswap_wrapper.get_eth_token_output_price(dai, 5*10**18)
# Get the public price for token to ETH trades with an exact output.
uniswap_wrapper.get_token_eth_output_price(bat, 1*10**18)
uniswap_wrapper.get_token_eth_output_price(dai, 5*10**18)

ERC20 Pool Methods (v1 only)

# Get the balance of ETH in an exchange contract.
uniswap_wrapper.get_ex_eth_balance(bat)
# Get the balance of a token in an exchange contract.
uniswap_wrapper.get_ex_token_balance(bat)
# Get the exchange rate of token/ETH
uniswap_wrapper.get_exchange_rate(bat)

Liquidity Methods (v1 only)

# Add liquidity to the pool.
uniswap_wrapper.add_liquidity(bat, 1*10**18)
# Remove liquidity from the pool.
uniswap_wrapper.remove_liquidity(bat, 1*10**18)

Trading

# Make a trade based on the input parameters
uniswap_wrapper.make_trade(eth, bat, 1*10**18) # calls _eth_to_token_input
uniswap_wrapper.make_trade(bat, eth, 1*10**18) # calls _token_to_eth_input
uniswap_wrapper.make_trade(bat, dai, 1*10**18) # calls _token_to_token_input
uniswap_wrapper.make_trade(eth, bat, 1*10**18, "0x123...") # calls _eth_to_token_input
# Make a trade where the output qty is known based on the input parameters
uniswap_wrapper.make_trade_output(eth, bat, 1*10**18) # calls _eth_to_token_swap_output
uniswap_wrapper.make_trade_output(bat, eth, 1*10**18) # calls _token_to_eth_swap_output
uniswap_wrapper.make_trade_output(bat, dai, 1*10**18, "0x123...") # calls _token_to_token_swap_output

Testing

Unit tests are under development using the pytest framework. Contributions are welcome!

Test are run on a fork of the main net using ganache-cli. You need to install it with npm install -g ganache-cli before running tests.

To run the full test suite, in the project directory run:

make test

Authors

Ownership Disclosure

  • I own some BAT and DAI tokens that are seen in the examples above. These tokens are used only for example purposes and are not meant to be an endorsement. I am not affiliated with BAT, Brave, Basic Attention Token, Brave Browser, DAI, Maker, MakerDAO, or any subsidiaries.

Changelog

0.4.6

  • Bug fix: Update bleach package from 3.1.4 to 3.3.0

0.4.5

  • Bug fix: Use .eth instead of .ens

0.4.4

  • General: Add new logo for Uniswap V2
  • Bug fix: Invalid balance check (#25)
  • Bug fix: Fixed error when passing WETH as token

0.4.3

  • Allow kwargs in approved decorator.

0.4.2

  • Add note about Uniswap V2 support

0.4.1

  • Update changelog for PyPi and clean up

0.4.0

A huge thank you Erik Bjäreholt for adding Uniswap V2 support, as well as all changes in this version!

  • Added support for Uniswap v2
  • Handle arbitrary tokens (by address) using the factory contract
  • Switched from setup.py to pyproject.toml/poetry
  • Switched from Travis to GitHub Actions
  • For CI to work in your repo, you need to set the secret MAINNET_PROVIDER. I use Infura.
  • Running tests on a local fork of mainnet using ganache-cli (started as a fixture)
  • Fixed tests for make_trade and make_trade_output
  • Added type annotations to the entire codebase and check them with mypy in CI
  • Formatted entire codebase with black
  • Moved stuff around such that the basic import becomes from uniswap import Uniswap (instead of from uniswap.uniswap import UniswapWrapper)
  • Fixed misc bugs

0.3.3

  • Provide token inputs as addresses instead of names

0.3.2

  • Add ability to transfer tokens after a trade
  • Add tests for this new functionality

0.3.1

  • Add tests for all types of trades

0.3.0

  • Add ability to make all types of trades
  • Add example to README

0.2.1

  • Add liquidity tests

0.2.0

  • Add liquidity and ERC20 pool methods

0.1.1

  • Major README update

0.1.0

  • Add market endpoints
  • Add tests for market endpoints
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].