Skip to content

Commit 38105a9

Browse files
committed
docs: improved CLI docs, changed unipy price to use common pair order for pricing
1 parent e1082e9 commit 38105a9

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎docs/cli.rst‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,22 @@ uniswap-python provides a basic command line interface named ``unipy``, to let y
66
Examples
77
--------
88

9+
**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.
10+
911
.. code:: shell
1012
1113
# Get price for 1 WETH quoted in DAI
12-
$ unipy price 0x6b175474e89094c44da98b954eedeac495271d0f 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
14+
$ unipy price WETH DAI
1315
3350.883387688622
1416
15-
# Get price for 1 WETH quoted in DAI, skip normalization
16-
$ unipy price --raw 0x6b175474e89094c44da98b954eedeac495271d0f 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
17+
# Get price for 1 WETH quoted in DAI, skip decimal normalization
18+
$ unipy price --raw WETH DAI
1719
3350883387688622003541
1820
21+
# Get price for 1 WETH quoted in USDT
22+
$ unipy price WETH 0xdac17f958d2ee523a2206206994597c13d831ec7
23+
3348.128969
24+
1925
# Get token metadata from its ERC20 contract
2026
$ unipy token 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
2127
{'name': 'Wrapped Ether', 'symbol': 'WETH', 'decimals': 18}

‎uniswap/cli.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,24 @@ def main(verbose: bool) -> None:
3939
@click.option(
4040
"--raw",
4141
is_flag=True,
42-
help="Don't normalize the quoted price to the input tokens's decimals",
42+
help="Don't normalize the quoted price to the output token's decimals",
4343
)
4444
@click.option(
4545
"--quantity",
46-
help="Quantity of output tokens to get price of. Falls back to one full unit of the output by default (10**18 for WETH, for example).",
46+
help="Quantity of output tokens to get price of. Falls back to one full unit of the input token by default (10**18 for WETH, for example).",
4747
)
4848
def price(
4949
token_in: AddressLike, token_out: AddressLike, raw: bool, quantity: int = None
5050
) -> None:
51-
"""Returns the price of ``quantity`` tokens of ``token_out`` quoted in ``token_in``."""
51+
"""Returns the price of ``quantity`` tokens of ``token_in`` quoted in ``token_out``."""
5252
uni = Uniswap(None, None, version=2)
5353
if quantity is None:
54-
quantity = 10 ** uni.get_token(token_out)["decimals"]
55-
price = uni.get_token_token_output_price(token_in, token_out, qty=quantity)
54+
quantity = 10 ** uni.get_token(token_in)["decimals"]
55+
price = uni.get_token_token_input_price(token_in, token_out, qty=quantity)
5656
if raw:
5757
print(price)
5858
else:
59-
decimals = uni.get_token(token_in)["decimals"]
59+
decimals = uni.get_token(token_out)["decimals"]
6060
print(price / 10 ** decimals)
6161

6262

0 commit comments

Comments
 (0)