Skip to content
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

how to set gas price and gas limit for a trade ? #34

Closed
tanpv opened this issue Sep 30, 2020 · 10 comments
Closed

how to set gas price and gas limit for a trade ? #34

tanpv opened this issue Sep 30, 2020 · 10 comments
Labels
duplicate This issue or pull request already exists

Comments

@tanpv
Copy link

tanpv commented Sep 30, 2020

hi, using uniswap-python lib, Could I set the gas price and gas limit for the trade ?
seem I do not find this from readme document, please help

also have same question with slip page setting.
Do we support this in near future ?

@tanpv tanpv changed the title how to set gas price for a trade ? how to set gas price and gas limit for a trade ? Sep 30, 2020
@ErikBjare
Copy link
Member

Duplicate of #23.

You need to pass in a custom Web3 instance to the constructor, with the gas strategy that you want. See the Web3 docs for how to do that: https://web3py.readthedocs.io/en/stable/gas_price.html

also have same question with slippage setting.

There's a constructor parameter for that as well: https://github.com/shanefontaine/uniswap-python/blob/672ce87c9f330a20bb5f17742d65eafbaf484e80/uniswap/uniswap.py#L132

@tanpv
Copy link
Author

tanpv commented Sep 30, 2020

many thanks @ErikBjare

@stamatelou
Copy link

@ErikBjare were you able to pass the instance to the constructor? And if yes, in which part of the uniswap.py script you added the instance from web3 ?

@alb2001
Copy link

alb2001 commented Mar 30, 2021

@ErikBjare Could you please provide an example on this
I've been taking a look at the uniswap.py class, but I cannot seem to figure out how you would pass that w3 parameter in the constructor and what you would need to put there.

something like this doesn't work
uniswap_wrapper = Uniswap(address=eth_address, private_key=eth_priv_key, provider=eth_infura_node, web3=web3.gas_strategies.time_based.fast_gas_price_strategy)

@ErikBjare
Copy link
Member

ErikBjare commented Mar 30, 2021

You need to pass a Web3 object, not a gas strategy object. Read the Web3py docs:

The provider and web3 parameters are mutually exclusive. The former is essentially just a shorthand for the latter.

For specifics on the behavior, see the first few lines of Uniswap.__init__:
https://github.com/shanefontaine/uniswap-python/blob/5ec7a1c5c6d861f90d935ab5faf680d2ab3aa112/uniswap/uniswap.py#L143-L150

@alb2001
Copy link

alb2001 commented Mar 30, 2021

Hello @ErikBjare

Thanks a lot. Correct. WHat I did was creating a w3 instance like this:

w3 = Web3(Web3.HTTPProvider(eth_infura_node, request_kwargs={"timeout": 60})) w3.eth.setGasPriceStrategy(fast_gas_price_strategy)

Then pass it through the w3 argument of the Uniswap constructor class. Seems it worked. But would you add this as a parameter on the class where we can specify the gwei directly? I think it's much easier.

@ErikBjare
Copy link
Member

ErikBjare commented Mar 30, 2021

But would you add this as a parameter on the class where we can specify the gwei directly? I think it's much easier.

That would not be appropriate. It might make your code slightly shorter, but it unnecessarily complicates the code for uniswap-python to handle all the complexities of Web3 initialization and gas pricing strategies.

As the Zen of Python states: "there should be one, and preferably only one, obvious way to do it"

@alb2001
Copy link

alb2001 commented Mar 30, 2021

Thank you

@Marsh-James
Copy link

I'm happy to make a PR for overwriting the default gas limit if you have a preference for how it should be passed in. Such as in the constructor or with each individual make_trade call or by some other means.

@Weizilla Makes an interesting point, any thoughts @ErikBjare? Was there a particular rationale behind this?

@troublesprouter
Copy link

Was a simple and quick way to make the transaction very fast found? I'm finding that using a custom web3 makes the process much slower, defeating the process of making the transaction faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

6 participants