uniswap交换的非官方python包装器

uniswap-python的Python项目详细描述


UniswapPython

Build StatusDownloadsLicense

Uniswap的非官方python客户端。

i决不隶属于或由uniswap、uniswap.io或任何上述实体的子公司或附属公司资助。

功能性

  • 一个简单易用的python包装器,用于所有可用的契约函数和变量
  • Uniswap合同返回数据的简单解析

开发中

  • 在私人连锁店而不是Rinkeby上运行测试
  • 更好的错误处理

开始

本自述文件是关于此存储库中显示的python客户机语法的文档。有关完整语法详细信息,请参见函数docstrings。 这个api试图向uniswap提供一个干净的接口,但是为了充分发挥它的潜力,您必须熟悉uniswap的官方文档。

您可以手动安装项目或使用pip:

pipinstalluniswap-python# orpipinstallgit+git://github.com/shanefontaine/uniswap-python.git

环境变量

程序希望设置环境变量以运行程序。您可以使用infura节点,因为事务在本地签名,并作为原始事务广播。环境变量是:

PROVIDER  # HTTP Provider for web3

公共客户

api中只有一些端点对每个人都可用。可以使用publicclient访问公共端点

importuniswapuniswap_wrapper=uniswap.UniswapWrapper()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 outputuniswap_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池方法
# 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.removeliquidity(bat,1*10**18)

交易
# Make a trade based on the input parametersuniswap_wrapper.make_trade(eth,bat,1*10**18)# calls _eth_to_token_inputuniswap_wrapper.make_trade(bat,eth,1*10**18)# calls _token_to_eth_inputuniswap_wrapper.make_trade(bat,dai,1*10**18)# calls _token_to_token_inputuniswap_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 parametersuniswap_wrapper.make_trade_output(eth,bat,1*10**18)# calls _eth_to_token_swap_outputuniswap_wrapper.make_trade_output(bat,eth,1*10**18)# calls _token_to_eth_swap_outputuniswap_wrapper.make_trade_output(bat,dai,1*10**18,"0x123...")# calls _token_to_token_swap_output

测试

使用pytest框架正在开发单元测试。欢迎投稿!

测试在Rinkeby网络上运行。

要运行完整的测试套件并忽略警告,请在项目目录中运行:

python -m pytest -W ignore::DeprecationWarning

所有权披露

  • 我有一些蝙蝠和傣族代币,可以在上面的例子中看到。这些代币仅用于举例目的,并不意味着是背书。我不隶属于蝙蝠,勇敢,基本注意令牌,勇敢浏览器,戴,制造商,马克道,或任何子公司。

更改日志

0.3.3

  • 提供标记输入作为地址而不是名称

0.3.2

  • 增加交易后转移代币的能力
  • 为此新功能添加测试

0.3.1

  • 为所有类型的交易添加测试

0.3.0

  • 增加进行各种交易的能力
  • 向自述文件中添加示例

0.2.1

  • 增加流动性测试

0.2.0

  • 增加流动性和ERC20池方法

0.1.1

  • 主要自述文件更新

0.1.0

  • 添加市场端点
  • 为市场端点添加测试

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
HTTP标头的java InputStream未终止   java测试SpringWebListener   具有定义的替换编号Java的regex ReplaceAll   在java中使用contains()方法   java在选择查询中使用JoinColumn字段   具有用户的java Start-stop demon不是以给定用户启动   java glBufferData生成GL\u无效\u操作   java中循环代码的循环   Java位无符号移位(>>>>)会产生奇怪的结果   java HQL使用点分隔符从select获取结果   条纹、弹簧、玩耍(或?):使用哪种高性能Java框架?   广播接收机中的java停止服务   java回收器视图占据整个屏幕。不在上面显示我的UI元素   java使MySQL查询更快   java MappedByteBuffer查询   java递归算法问题