Skip to content

Commit 616d521

Browse files
committed
add threshold param
1 parent ade3ebb commit 616d521

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/margin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn calculate_simplified_margin_requirement(
9090
let oracle = market_state.get_spot_oracle_price(spot_position.market_index);
9191
let diff_bps = (pyth_price.price.abs_diff(oracle.price) * 10_000)
9292
/ oracle.price.unsigned_abs();
93-
if diff_bps > 5 {
93+
if diff_bps > market_state.pyth_oracle_diff_threshold_bps {
9494
pyth_price
9595
} else {
9696
*oracle
@@ -203,7 +203,7 @@ pub fn calculate_simplified_margin_requirement(
203203
let oracle = market_state.get_perp_oracle_price(perp_position.market_index);
204204
let diff_bps = (pyth_price.price.abs_diff(oracle.price) * 10_000)
205205
/ oracle.price.unsigned_abs();
206-
if diff_bps > 5 {
206+
if diff_bps > market_state.pyth_oracle_diff_threshold_bps {
207207
pyth_price
208208
} else {
209209
*oracle

src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ pub struct MarketState {
229229
pub perp_oracle_prices: HashMap<u16, OraclePriceData, FxBuildHasher>,
230230
pub spot_pyth_prices: HashMap<u16, i64, FxBuildHasher>, // Override spot with pyth price
231231
pub perp_pyth_prices: HashMap<u16, i64, FxBuildHasher>, // Override perp with pyth price
232+
pub pyth_oracle_diff_threshold_bps: u64, // Min bps diff to prefer pyth price over oracle. Defaults to 0 (always use pyth when set).
232233
}
233234

234235
impl MarketState {

0 commit comments

Comments
 (0)