-
Notifications
You must be signed in to change notification settings - Fork 100
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
bigz/make-auction-start-baseline-more-passive #890
Changes from 1 commit
4569da8
fa504c1
a6979d1
b02841b
7add9ec
1afa87b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -376,13 +376,40 @@ impl OrderParams { | |
perp_market: &PerpMarket, | ||
direction: PositionDirection, | ||
) -> DriftResult<i64> { | ||
// price offsets baselines for perp market auctions | ||
let mark_twap_slow = perp_market | ||
if perp_market | ||
.amm | ||
.last_ask_price_twap | ||
.safe_add(perp_market.amm.last_bid_price_twap)? | ||
.safe_div(2)? | ||
.cast::<i64>()?; | ||
.historical_oracle_data | ||
.last_oracle_price_twap_ts | ||
.safe_sub(perp_market.amm.last_mark_price_twap_ts)? | ||
.abs() | ||
>= 60 | ||
{ | ||
// if uncertain with timestamp mismatch, enforce within N bps | ||
let price_divisor = if perp_market | ||
.contract_tier | ||
.is_as_safe_as_contract(&ContractTier::B) | ||
{ | ||
500 | ||
} else { | ||
100 | ||
}; | ||
|
||
return Ok(match direction { | ||
PositionDirection::Long => { | ||
perp_market.amm.last_bid_price_twap.cast::<i64>()? / price_divisor | ||
} | ||
PositionDirection::Short => { | ||
-(perp_market.amm.last_ask_price_twap.cast::<i64>()? / price_divisor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should short start above oracle, why is this negative? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is only when |
||
} | ||
}); | ||
} | ||
|
||
// price offsets baselines for perp market auctions | ||
let mark_twap_slow = match direction { | ||
PositionDirection::Long => perp_market.amm.last_bid_price_twap, | ||
PositionDirection::Short => perp_market.amm.last_ask_price_twap, | ||
} | ||
.cast::<i64>()?; | ||
|
||
let baseline_start_price_offset_slow = mark_twap_slow.safe_sub( | ||
perp_market | ||
|
@@ -402,31 +429,27 @@ impl OrderParams { | |
.last_oracle_price_twap_5min, | ||
)?; | ||
|
||
let frac_of_long_spread_in_price: i64 = perp_market | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can save some compute by doing the calculation in the match blocks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i need both of them for both though for the slow, i pushing it up slightly from the opposite side of the book |
||
.amm | ||
.long_spread | ||
.cast::<i64>()? | ||
.safe_mul(mark_twap_slow)? | ||
.safe_div(PRICE_PRECISION_I64 * 10)?; | ||
|
||
let frac_of_short_spread_in_price: i64 = perp_market | ||
.amm | ||
.short_spread | ||
.cast::<i64>()? | ||
.safe_mul(mark_twap_slow)? | ||
.safe_div(PRICE_PRECISION_I64 * 10)?; | ||
|
||
let baseline_start_price_offset = match direction { | ||
PositionDirection::Long => { | ||
let frac_of_spread_in_price: i64 = perp_market | ||
.amm | ||
.long_spread | ||
.cast::<i64>()? | ||
.safe_mul(mark_twap_slow)? | ||
.safe_div(PRICE_PRECISION_I64 * 10)?; | ||
|
||
baseline_start_price_offset_slow | ||
.max(baseline_start_price_offset_fast) | ||
.safe_add(frac_of_spread_in_price)? | ||
} | ||
PositionDirection::Short => { | ||
let frac_of_spread_in_price: i64 = perp_market | ||
.amm | ||
.short_spread | ||
.cast::<i64>()? | ||
.safe_mul(mark_twap_slow)? | ||
.safe_div(PRICE_PRECISION_I64 * 10)?; | ||
|
||
baseline_start_price_offset_slow | ||
.min(baseline_start_price_offset_fast) | ||
.safe_sub(frac_of_spread_in_price)? | ||
} | ||
PositionDirection::Long => baseline_start_price_offset_slow | ||
.safe_add(frac_of_long_spread_in_price)? | ||
.min(baseline_start_price_offset_fast.safe_sub(frac_of_short_spread_in_price)?), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so before we were doing max, which gives the more aggressive, now we're doing min, which is less aggresswive? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, doing min for long is less aggressive |
||
PositionDirection::Short => baseline_start_price_offset_slow | ||
.safe_sub(frac_of_short_spread_in_price)? | ||
.max(baseline_start_price_offset_fast.safe_add(frac_of_long_spread_in_price)?), | ||
}; | ||
|
||
Ok(baseline_start_price_offset) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be good to add comment that it's starting at bid (beneath oracle) intentionally to get a good price?