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

Factor trade volume into hourly price instants #182

Merged
merged 4 commits into from
Jul 16, 2021

Conversation

kumar-ish
Copy link
Contributor

@kumar-ish kumar-ish commented Jul 8, 2021

Motivation

Currently, when calculating the average price in a given hour of a market, the cumulative price is set to be the sum of the prices of all the trades, ignoring the weight of the actual trades (i.e. the number of positions sold in that trade). This leads to asymmetric averages.

e.g. Currently, for the following two trades that happen in an hour:

  • 90 pos. @ $1.25
  • 10 pos. @ $1.50

The average price for that hour is calculated to be (1.25 + 1.5) / 2 = $1.375, even though based on the actual positions that were filled, it should be (90x1.25 + 10x1.5) / 100 = $1.275

This PR solves this: code-423n4/2021-06-tracer-findings#119

Changes

  • Factor trade volume into hourly price instants
  • Misc. gas optimisation in TracerPerpetualSwaps

@kumar-ish kumar-ish force-pushed the record-trade-fillamount branch 2 times, most recently from ca3e4a1 to 6956900 Compare July 8, 2021 06:08
@CalabashSquash CalabashSquash self-requested a review July 8, 2021 23:05
@kumar-ish kumar-ish force-pushed the record-trade-fillamount branch from 6956900 to 9dbc942 Compare July 11, 2021 21:49
@kumar-ish kumar-ish force-pushed the record-trade-fillamount branch from aa9d160 to c7e447a Compare July 15, 2021 12:01
@kumar-ish kumar-ish requested a review from CalabashSquash July 15, 2021 13:12
@kumar-ish kumar-ish merged commit aa263f8 into contracts-v2 Jul 16, 2021
@kumar-ish kumar-ish deleted the record-trade-fillamount branch July 16, 2021 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants