Throughout the history of DAI the vast majority of the volume has been through the oasis/eth2dai contract. This poses a problem when it comes to estimating the DAI/USD price using trades because it takes a few blocks to cancel a limit order. If ETH/USD moves against the maker, an arbitrager/market maker/metamask meatball will take it. In terms of DAI/USD, this trade looks like it occurred at an outlier price of +1.02/0.98 when compared to a centralized ETH/USD feed. This adds unnecessary noise to our DAI/USD error signal if DAI/USD was close to 1 the rest of the day.
The second problem with calculating the DAI/USD price by trades is liquidity. Occasionally, uniswap or tap contract pure revenue bots will chew through offers on eth2dai +2% away from the spread. If the market makers on eth2dai put their offers right back where they were (with respect to 1), then these trades also add noise to our DAI/USD error signal.
The third problem - how do we calculate DAI/USD if very few trades occurred during that hour/day? This hasn’t been an issue lately, but some days during 2018 it was. Calculating the DAI/USD price from the order book reduces these three sources of unnecessary error.
Here is eth2dai order book over around 1000 blocks.
My primary goal is to get a cleaner, more accurate, DAI/USD error signal into my PID controller for repeatable off chain SF estimation. (updated post on PID coming soon) Sites that calculate DAI/USD from trades like http://dai.descipher.io/ or https://dai.stablecoin.science/ are excellent for getting a quick look at what is going on in DeFi, but they are too noisy to make repeatable estimations possible using a PID for the reasons I listed above. Lets compare a volatile period where DAI was too low in April 2019.
Calculating the DAI/USD error signal by trades: https://gfycat.com/frighteningselfreliantadder
Calculating the DAI/USD error signal by eth2dai order book: https://gfycat.com/mintybriefamericanredsquirrel
Comparing the two on the same plot:
(plot notes: 1. I omitted a few trades that happened at extremely low or high values. 2. The hourly order book depth is calculated by the median amount of DAI available from eth2dai over a 1 hour period. 3. All error bands signify 1 standard deviation)
The benefit is marginal for when DAI is off the peg. The standard deviation bands for the order book method are slightly tighter than using trades, but overall the signals look about the same. Now, lets take a look at a less volatile (in terms of DAI/USD) period a few weeks ago.
Calculating the DAI/USD error signal by trades: https://gfycat.com/deadlygroundedblowfish
Calculating the DAI/USD error signal by eth2dai order book: https://gfycat.com/waryopenafricanporcupine
Comparing the two on the same plot:
This is where the order book method really shines. If there are asks above 1, and bids below 1, the SF is in its happy place. There is no reason to change it, so the error signal can =0 when this is the case. If you were calculating the error using trades it would be much harder to say what was going on due to all the noise.
Let me know if you have any questions/comments as the feedback I’ve gotten so far has been spectacular.
trades - dai.stablecoin.science
ETH/USD (gemini minute) - http://www.cryptodatadownload.com/data/northamerican/
order book - eth2dai/oasis contract
1000 block order book plot - https://github.com/lixwhi/order_book_plot
get the order book data - https://github.com/lixwhi/get_oasis_book
plot the book histogram and make gif https://github.com/lixwhi/oasis_hourly_histogram
dex trades histogram and compare plots- https://github.com/lixwhi/dex_trades_histogram