Perp: Add PerpOpenOrder::is_active_for_market()
This commit is contained in:
parent
30ebf173ee
commit
be37f33946
|
@ -551,7 +551,7 @@ impl<
|
||||||
client_order_id: u64,
|
client_order_id: u64,
|
||||||
) -> Option<&PerpOpenOrder> {
|
) -> Option<&PerpOpenOrder> {
|
||||||
self.all_perp_orders()
|
self.all_perp_orders()
|
||||||
.find(|&oo| oo.market == market_index && oo.client_id == client_order_id)
|
.find(|&oo| oo.is_active_for_market(market_index) && oo.client_id == client_order_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn perp_find_order_with_order_id(
|
pub fn perp_find_order_with_order_id(
|
||||||
|
@ -560,7 +560,7 @@ impl<
|
||||||
order_id: u128,
|
order_id: u128,
|
||||||
) -> Option<&PerpOpenOrder> {
|
) -> Option<&PerpOpenOrder> {
|
||||||
self.all_perp_orders()
|
self.all_perp_orders()
|
||||||
.find(|&oo| oo.market == market_index && oo.id == order_id)
|
.find(|&oo| oo.is_active_for_market(market_index) && oo.id == order_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn being_liquidated(&self) -> bool {
|
pub fn being_liquidated(&self) -> bool {
|
||||||
|
|
|
@ -767,6 +767,10 @@ impl PerpOpenOrder {
|
||||||
pub fn side_and_tree(&self) -> SideAndOrderTree {
|
pub fn side_and_tree(&self) -> SideAndOrderTree {
|
||||||
SideAndOrderTree::try_from(self.side_and_tree).unwrap()
|
SideAndOrderTree::try_from(self.side_and_tree).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_active_for_market(&self, perp_market_index: PerpMarketIndex) -> bool {
|
||||||
|
self.market == perp_market_index
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::state::MangoAccountRefMut;
|
use crate::state::MangoAccountRefMut;
|
||||||
use crate::{
|
use crate::{
|
||||||
error::*,
|
error::*,
|
||||||
state::{orderbook::bookside::*, EventQueue, PerpMarket, FREE_ORDER_SLOT},
|
state::{orderbook::bookside::*, EventQueue, PerpMarket},
|
||||||
};
|
};
|
||||||
use anchor_lang::prelude::*;
|
use anchor_lang::prelude::*;
|
||||||
use bytemuck::cast;
|
use bytemuck::cast;
|
||||||
|
@ -280,7 +280,7 @@ impl<'a> Orderbook<'a> {
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for i in 0..mango_account.header.perp_oo_count() {
|
for i in 0..mango_account.header.perp_oo_count() {
|
||||||
let oo = mango_account.perp_order_by_raw_index(i);
|
let oo = mango_account.perp_order_by_raw_index(i);
|
||||||
if oo.market == FREE_ORDER_SLOT || oo.market != perp_market.perp_market_index {
|
if !oo.is_active_for_market(perp_market.perp_market_index) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue