Set Fee in Uniswap-Python – How to Set the Fee in uniswap.get_price_input()?

external-apipythonuniswap

I am successfully using uniswap.get_price_input(eth, dai, 10**18) to get the price of the ETH/DAI pair. In addition, I receive the get the message "No fee set, assuming 0.3%" in my terminal.

I would like to remove that message and set the fee to .3% but receive a variety of errors, depending on my attempt.

Attempt 1

>>>uniswap.get_price_input(eth, dai, 10**18, .3)

>>>Could not identify the intended function with name `quoteExactInputSingle`, positional argument(s) of type `(<class 'str'>, <class 'str'>, <class 'float'>, <class 'int'>, <class 'int'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `quoteExactInputSingle`: ['quoteExactInputSingle(address,address,uint24,uint256,uint160)']
Function invocation failed due to no matching argument types.

Attempt 2

>>>uniswap.get_price_input(eth, dai, 10**18, int(.3))


>>>raise ContractLogicError('execution reverted')
>>>web3.exceptions.ContractLogicError: execution reverted

Attempt 3

>>>uniswap.get_price_input(eth, dai, 10**18, fee=.3)

>>>Could not identify the intended function with name `quoteExactInputSingle`, positional argument(s) of type `(<class 'str'>, <class 'str'>, <class 'float'>, <class 'int'>, <class 'int'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `quoteExactInputSingle`: ['quoteExactInputSingle(address,address,uint24,uint256,uint160)']
Function invocation failed due to no matching argument types.

For reference:
get_price_input(token0: Union[Address, ChecksumAddress], token1: Union[Address, ChecksumAddress], qty: int, fee: Optional[int] = None, route: Optional[List[Union[Address, ChecksumAddress]]] = None) → int

How do you set the fee?

Best Answer

Casting 0.3 to int will return 0.

If you check the function prototype, the default fee of 0.3% is passed as 3000, which is therefore the value you should use.