I am using Python and web3.py.
I have to swap eth to tokens using swapExactEthforTokens in Uniswap. And then I have to tokens to eth using swapExactTokensforEth in Uniswap.
How do get calculate profit?
I have to predict the profit.
This is a case of an Arbitrage. In summary, an Arbitrage is the transferring of goods from market to market while buying at a lower price in one and selling for higher in the other market. The practice is enabled by the fact that markets are not that fast to know exactly the price of a certain good in all other markets in order to fix its pricing.
The arbitrage is a product of that issue and is the best way to fixing it. The prediction is an exercise of "The shortest route" algorithms.
here is a more elaborate post on that : Finance And money StackExchange