stefanmendoza / uniswap-price-feed

Real time price feeds from Uniswap by leveraging Infura
MIT License
27 stars 9 forks source link

Prices are sometimes wrong #3

Open crypto456 opened 4 years ago

crypto456 commented 4 years ago

I just installed it and ran: $ yarn start ETH USDC Every hour the prices are sometimes wrong... You can easily tell by the % change. It appears that it gives wrong output only when showing a complex, multi-swap transaction using 1inch.exchange or similar.

2 Feature Requests:

  1. Allow local IPC web3 connection
  2. Output block numbers by default on every price line. After the % change

Other than this price problem it works great 👍👍

Example when it's wrong:

$ yarn start ETH USDC

[2020-08-22 02:26:52] Sold 12.568529 ETH for 4810.996386 USDC (382.781 USDC / -0.06%)
[2020-08-22 02:26:52] Sold 7.967268 ETH for 3047.232091 USDC (382.469 USDC / -0.08%)
[2020-08-22 02:26:52] Sold 20 ETH for 7640.893426 USDC (382.045 USDC / -0.11%)
[2020-08-22 02:26:56] Sold 1.603707 ETH for 612.161733 USDC (381.717 USDC / -0.09%)
---> [2020-08-22 02:26:56] Bought 25.56931 ETH for 11679.712219 USDC (456.786 USDC / +19.67%)
---> [2020-08-22 02:27:20] Sold 2.3026 ETH for 897.637987 USDC (389.837 USDC / -14.66%)
[2020-08-22 02:27:45] Sold 2.042209 ETH for 799.178 USDC (391.330 USDC / +0.38%)
[2020-08-22 02:27:51] Bought 0.35326886 ETH for 135.427461 USDC (383.355 USDC / -2.04%)
[2020-08-22 02:27:51] Sold 3.531791 ETH for 1345.649935 USDC (381.011 USDC / -0.61%)

---> 25.56931 ETH: https://etherscan.io/tx/0x3251ff67be0408bcbd1afd53ef15f061270a33c328d9f1d1f258a1b2fee3e508/

uniswap.info's transaction table when I viewed the transaction live: Swap ETH for USDC total value: $9,750 token amount: 25.56931 ETH token amount: 9,750 USDC

stefanmendoza commented 4 years ago

Yeah, I've also noticed this. There's also the case where an arbitrage happens:

Swap 1 ETH for 1 LINK on Uniswap
Swap 1 LINK for 1 USDC on Balancer
Swap 1 USDC for 1 USDT on Balancer
Swap 1 USDT fo 1 LINK on Balancer
Swap 1 LINK for 1 ETH on Uniswap

in this case, we should consider both the initial buy and the final sell vs. just treating this as a buy as it'll throw off the next transaction.

I'm working on refactoring the code to make it more manageable then see if I can leverage the amounts in each reserve token to calculate the pricer more correctly. I need to dig more into Uniswap's documentation on how the midPrice and nextExecutionPrice are handled in V2.

Thanks for bringing this u!