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

Inconsistent net calculations #290

Open
gorgos opened this issue Jun 30, 2020 · 0 comments
Open

Inconsistent net calculations #290

gorgos opened this issue Jun 30, 2020 · 0 comments

Comments

@gorgos
Copy link

gorgos commented Jun 30, 2020

Currently, we are calculating net positions for traders from the leveraged_debits:

let debits_in_usd = Self::usd_value(p.pair.quote, p.leveraged_debits.saturating_abs())?;

Which is acceptable even though not perfectly accurate. After discussion with @Antonia-Chen, this reflects traditional markets and traders are used to it. (more accurate would be differentiating between longs and shorts)

However in the ENP/ELL, we are using leveraged_held:

let new_net = pool
.long
.held
.checked_add(&pool.short.held)
.ok_or(Error::<T>::NumOutOfBound)?;
let net_in_usd = Self::usd_value(pair.base, new_net.saturating_abs())?;
let new_max = cmp::max(pool.long.held, pool.short.held.saturating_abs());
let max_in_usd = Self::usd_value(pair.base, new_max.saturating_abs())?;

While it doesn't matter from a security perspective, I think for consistency reasons it should be the same. Otherwise it gets too confusing thinking about which kind of net calculation is now being used. A simple change like this would be enough:

let new_net = pool
    .long
    .debits
    .checked_add(&pool.short.debits)
    .ok_or(Error::<T>::NumOutOfBound)?;
let net_in_usd = Self::usd_value(pair.quote, new_net.saturating_abs())?;

let new_max = cmp::max(pool.long.debits, pool.short.debits.saturating_abs());
let max_in_usd = Self::usd_value(pair.quote, new_max.saturating_abs())?;
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

No branches or pull requests

1 participant