@@ -227,6 +227,9 @@ pub struct MarketState {
227227 pub perp_markets : HashMap < u16 , PerpMarket , FxBuildHasher > ,
228228 pub spot_oracle_prices : HashMap < u16 , OraclePriceData , FxBuildHasher > ,
229229 pub perp_oracle_prices : HashMap < u16 , OraclePriceData , FxBuildHasher > ,
230+ pub spot_pyth_prices : HashMap < u16 , i64 , FxBuildHasher > , // Override spot with pyth price
231+ 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).
230233}
231234
232235impl MarketState {
@@ -246,6 +249,30 @@ impl MarketState {
246249 self . perp_oracle_prices . get ( & market_index) . unwrap ( )
247250 }
248251
252+ pub fn get_spot_pyth_price ( & self , market_index : u16 ) -> Option < OraclePriceData > {
253+ self . spot_pyth_prices
254+ . get ( & market_index)
255+ . map ( |& price| OraclePriceData {
256+ price,
257+ confidence : 0 ,
258+ delay : 0 ,
259+ has_sufficient_number_of_data_points : true ,
260+ sequence_id : None ,
261+ } )
262+ }
263+
264+ pub fn get_perp_pyth_price ( & self , market_index : u16 ) -> Option < OraclePriceData > {
265+ self . perp_pyth_prices
266+ . get ( & market_index)
267+ . map ( |& price| OraclePriceData {
268+ price,
269+ confidence : 0 ,
270+ delay : 0 ,
271+ has_sufficient_number_of_data_points : true ,
272+ sequence_id : None ,
273+ } )
274+ }
275+
249276 pub fn set_spot_market ( & mut self , market : SpotMarket ) {
250277 self . spot_markets . insert ( market. market_index , market) ;
251278 }
@@ -261,4 +288,12 @@ impl MarketState {
261288 pub fn set_perp_oracle_price ( & mut self , market_index : u16 , price_data : OraclePriceData ) {
262289 self . perp_oracle_prices . insert ( market_index, price_data) ;
263290 }
291+
292+ pub fn set_spot_pyth_price ( & mut self , market_index : u16 , price_data : i64 ) {
293+ self . spot_pyth_prices . insert ( market_index, price_data) ;
294+ }
295+
296+ pub fn set_perp_pyth_price ( & mut self , market_index : u16 , price_data : i64 ) {
297+ self . perp_pyth_prices . insert ( market_index, price_data) ;
298+ }
264299}
0 commit comments