GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - grandizzy/uniswap-python: The unofficial Python client for the Uniswap exchange.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

108 Commits
108 Commits

Folders and files

NameName
Last commit message
Last commit date
tests
tests
 
 
uniswap
uniswap
 
 
.gitignore
.gitignore
 
 
.travis.yml
.travis.yml
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
requirements-dev.txt
requirements-dev.txt
 
 
requirements.txt
requirements.txt
 
 
setup.py
setup.py
 
 

Repository files navigation

uniswap-python

Build Status Downloads License Code style: black

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 all available contract functions and variables
  • 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.

  • https://docs.uniswap.io/

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()
eth = "0x0000000000000000000000000000000000000000"
bat = "0x0D8775F648430679A709E98d2b0Cb6250d2887EF"
dai = "0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359"

Market Methods

  • get_fee_maker
uniswap_wrapper.get_fee_maker()
  • get_fee_taker
uniswap_wrapper.get_fee_taker()
  • get_eth_token_input_price
# 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_token_eth_input_price
# 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_eth_token_output_price
# 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_token_eth_output_price
# 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_eth_balance
# Get the balance of ETH in an exchange contract.
uniswap_wrapper.get_eth_balance(bat)
  • get_token_balance
# Get the balance of a token in an exchange contract.
uniswap_wrapper.get_token_balance(bat)
  • get_exchange_rate
# Get the balance of a token in an exchange contract.
uniswap_wrapper.get_exchange_rate(bat)

Liquidity Methods

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

Trading

  • make_trade
  • eth_to_token_input * ethToTokenSwapInput * ethToTokenTransferInput
  • token_to_eth_input * tokenToEthSwapInput * tokenToEthTransferInput
  • token_to_token_input * tokenToTokenSwapInput * tokenToTokenTransferInput
# 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_trade_output
  • eth_to_token_swap_output * ethToTokenSwapOutput * ethToTokenTransferOutput
  • token_to_eth_swap_output * tokenToEthSwapOutput * tokenToEthTransferOutput
  • token_to_token_swap_output * tokenTotokenSwapOutput * tokenTotokenTransferOutput)
# 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 the Rinkeby network.

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

python -m pytest -W ignore::DeprecationWarning

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.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

About

The unofficial Python client for the Uniswap exchange.

Resources

Readme
MIT license

Code of conduct

Code of conduct
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.