Skip to content

feat: added basic CLI #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.PHONY: test typecheck lint precommit docs

test:
poetry run pytest -v --cov=uniswap --cov-report html
poetry run pytest -v --cov=uniswap --cov-report html --cov-report term

typecheck:
poetry run mypy --pretty
Expand Down
42 changes: 42 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Command line interface
======================

uniswap-python provides a basic command line interface named ``unipy``, to let you easier query the chain for things like the current price and token metadata.

Examples
--------

**Note:** uniswap-python contains a small database of token contract addresses for convenience. You can always provide a contract address in place of a shorthand, and need to do so for all tokens not in the bundled database, or if you're not on mainnet.

.. code:: shell

# Get price for 1 WETH quoted in DAI
$ unipy price WETH DAI
3350.883387688622

# Get price for 1 WETH quoted in DAI, skip decimal normalization
$ unipy price --raw WETH DAI
3350883387688622003541

# Get price for 1 WETH quoted in USDT
$ unipy price WETH 0xdac17f958d2ee523a2206206994597c13d831ec7
3348.128969

# Get token metadata from its ERC20 contract
$ unipy token 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
{'name': 'Wrapped Ether', 'symbol': 'WETH', 'decimals': 18}

# List known/hardcoded tokens, with metadata
$ unipy tokendb --metadata
{'name': 'Wrapped Ether', 'symbol': 'WETH', 'decimals': 18}
{'name': 'Dai Stablecoin', 'symbol': 'DAI', 'decimals': 18}
{'name': 'Wrapped BTC', 'symbol': 'WBTC', 'decimals': 8}
...


Usage
-----

.. click:: uniswap.cli:main
:prog: unipy
:nested: full
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ["sphinx.ext.autodoc"]
extensions = ["sphinx.ext.autodoc", "sphinx_click"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
7 changes: 6 additions & 1 deletion docs/forks.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Using uniswap-python for Uniswap forks
======================================

While not officially supported, you can use this library to trade across several Uniswap forks like Sushiswap (mainnet), Honeyswap (xDai), Pancakeswap (BSC), etc.
While not officially supported, you can use this library to trade across several Uniswap forks, like:

- Sushiswap (mainnet)
- Honeyswap (xDai)
- Pancakeswap (BSC)
- And any other forks that don't deviate too much from the ABI.

See the issues for details about how to do so.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Welcome to uniswap-python's documentation!
:caption: Contents:

api
cli
examples
forks

Expand Down
Loading