You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a477227
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/getting-started.rst
+19-11Lines changed: 19 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,14 +76,14 @@ Quoting prices
76
76
77
77
.. note::
78
78
79
-
These methods assume a certain route for the swap to take, which may not be the optimal route. See :issue:`69` for details.
79
+
These methods assume a certain route for the swap to take, which may not be the optimal route. See :issue:`93` for details.
80
80
81
81
There are two functions to retrieve the price for a given pair, one for specifying how much you get given a certain amount of the input token, and another for specifying how much you need to pay to receive a certain amount of the output token.
82
82
83
83
:func:`~uniswap.Uniswap.get_price_input`
84
84
````````````````````````````````````````
85
85
86
-
Returns the cost of the given number of input tokens, priced in the output token.
86
+
Returns the amount of output tokens you get for a given amount of input tokens.
87
87
88
88
.. code:: python
89
89
@@ -120,26 +120,34 @@ Making trades
120
120
121
121
The same route assumptions and need for handling decimals apply here as those mentioned in the previous section.
122
122
123
+
.. warning::
124
+
125
+
Always check the expected price before executing a trade. It's important that you're using a pool with adequate liquidity, or else you may suffer significant losses! (see :issue:`198`)
126
+
127
+
Use the Uniswap version with the most liquidity for your route, and if using v3, make sure you set the ``fee`` parameter to use the best pool.
128
+
123
129
:func:`~uniswap.Uniswap.make_trade`
124
130
```````````````````````````````````
125
131
126
132
.. code:: python
127
133
128
-
# Make a trade where the input qty being known parameters
129
-
uniswap.make_trade(eth, bat, 1*10**18) # sell 1 ETH for however many BAT
130
-
uniswap.make_trade(bat, eth, 1*10**18) # sell 1 BAT for however many ETH
131
-
uniswap.make_trade(bat, dai, 1*10**18) # sell 1 BAT for however many DAI
132
-
uniswap.make_trade(eth, bat, 1*10**18, "0x123...") # sell 1 ETH for however many BAT, and send the BAT to the provided address
134
+
# Make a trade by specifying the quantity of the input token you wish to sell
135
+
uniswap.make_trade(eth, bat, 1*10**18) # sell 1 ETH for BAT
136
+
uniswap.make_trade(bat, eth, 1*10**18) # sell 1 BAT for ETH
137
+
uniswap.make_trade(bat, dai, 1*10**18) # sell 1 BAT for DAI
138
+
uniswap.make_trade(eth, bat, 1*10**18, "0x123...") # sell 1 ETH for BAT, and send the BAT to the provided address
139
+
uniswap.make_trade(dai, usdc, 1*10**18, fee=500) # sell 1 DAI for USDC using the 0.05% fee pool (v3 only)
133
140
134
141
:func:`~uniswap.Uniswap.make_trade_output`
135
142
``````````````````````````````````````````
136
143
137
144
.. code:: python
138
145
139
-
# Make a trade where the output qty is known, based on the input parameters
140
-
uniswap.make_trade_output(eth, bat, 1*10**18) # buy however many ETH for 1 BAT
141
-
uniswap.make_trade_output(bat, eth, 1*10**18) # buy however many BAT for 1 ETH
142
-
uniswap.make_trade_output(bat, dai, 1*10**18, "0x123...") # buy however many BAT for 1 DAI, and send the BAT to the provided address
146
+
# Make a trade by specifying the quantity of the output token you wish to buy
147
+
uniswap.make_trade_output(eth, bat, 1*10**18) # buy ETH for 1 BAT
148
+
uniswap.make_trade_output(bat, eth, 1*10**18) # buy BAT for 1 ETH
149
+
uniswap.make_trade_output(bat, dai, 1*10**18, "0x123...") # buy BAT for 1 DAI, and send the BAT to the provided address
150
+
uniswap.make_trade_output(dai, usdc, 1*10**8, fee=500) # buy USDC for 1 DAI using the 0.05% fee pool (v3 only)
0 commit comments