Skip to main content

An unofficial python wrapper for the Uniswap exchange

Project description

uniswap-python

Build Status Downloads License

The unofficial Python client for the Uniswap.

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

Functionality

  • A simple to use Python wrapper for both public and authenticated endpoints.
  • Easy interaction with the Uniswap smart contracts
  • Simple parsing of data returned from the Uniswap contract

Under Development

  • Run tests on a private chain rather than Rinkeby
  • 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

import uniswap
uniswap_wrapper = uniswap.UniswapWrapper()

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

# Get the balance of ETH in an exchange contract.
uniswap_wrapper.get_eth_balance("bat")
# Get the balance of a token in an exchange contract.
uniswap_wrapper.get_token_balance("bat")
# Get the balance of a token in an exchange contract.
uniswap_wrapper.get_exchange_rate("bat")

Liquidity Methods

# Add liquidity to the pool.
uniswap_wrapper.add_liquidity("bat", 1*10**18)
# Remove liquidity from the pool.
uniswap_wrapper.removeliquidity("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
# 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) # calls _token_to_token_swap_output

Testing

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

Test are run on the Rinkeby network.

To run the full test suite and ignore warnings, in the project directory run:

python -m pytest -W ignore::DeprecationWarning

Changelog

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uniswap-python-0.3.0.tar.gz (7.2 kB view details)

Uploaded Source

File details

Details for the file uniswap-python-0.3.0.tar.gz.

File metadata

  • Download URL: uniswap-python-0.3.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.6

File hashes

Hashes for uniswap-python-0.3.0.tar.gz
Algorithm Hash digest
SHA256 e74f6132674b59a955bd3b811cfd1f85b7cff4a81d7b8f155ab26ef1d723baa2
MD5 fea6b4c63b23290e33da0271729e04b1
BLAKE2b-256 80a60f6fb7fc44610d5d6326f291b711742926903559ab7058f0d0f685a55784

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page