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 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
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
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"
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)
# 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)
# 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)
# 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
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
0.4.4
0.4.3
approved
decorator.0.4.2
0.4.1
0.4.0
A huge thank you Erik Bjäreholt for adding Uniswap V2 support, as well as all changes in this version!
0.3.3
0.3.2
0.3.1
0.3.0
0.2.1
0.2.0
0.1.1
0.1.0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。