Add tick best-price matching modes
This commit is contained in:
@@ -56,6 +56,9 @@ pub enum MatchingType {
|
||||
CurrentBarClose,
|
||||
NextBarOpen,
|
||||
NextTickLast,
|
||||
NextTickBestOwn,
|
||||
NextTickBestCounterparty,
|
||||
CounterpartyOffer,
|
||||
Vwap,
|
||||
}
|
||||
|
||||
@@ -271,9 +274,51 @@ where
|
||||
quote: &IntradayExecutionQuote,
|
||||
side: OrderSide,
|
||||
) -> Option<f64> {
|
||||
let raw_price = match side {
|
||||
OrderSide::Buy => quote.buy_price(),
|
||||
OrderSide::Sell => quote.sell_price(),
|
||||
let raw_price = match self.matching_type {
|
||||
MatchingType::NextTickBestOwn => match side {
|
||||
OrderSide::Buy => {
|
||||
if quote.bid1.is_finite() && quote.bid1 > 0.0 {
|
||||
Some(quote.bid1)
|
||||
} else {
|
||||
quote
|
||||
.last_price
|
||||
.is_finite()
|
||||
.then_some(quote.last_price)
|
||||
.filter(|price| *price > 0.0)
|
||||
}
|
||||
}
|
||||
OrderSide::Sell => {
|
||||
if quote.ask1.is_finite() && quote.ask1 > 0.0 {
|
||||
Some(quote.ask1)
|
||||
} else {
|
||||
quote
|
||||
.last_price
|
||||
.is_finite()
|
||||
.then_some(quote.last_price)
|
||||
.filter(|price| *price > 0.0)
|
||||
}
|
||||
}
|
||||
},
|
||||
MatchingType::NextTickBestCounterparty | MatchingType::CounterpartyOffer => {
|
||||
match side {
|
||||
OrderSide::Buy => quote.buy_price(),
|
||||
OrderSide::Sell => quote.sell_price(),
|
||||
}
|
||||
}
|
||||
MatchingType::NextTickLast | MatchingType::Vwap => {
|
||||
if quote.last_price.is_finite() && quote.last_price > 0.0 {
|
||||
Some(quote.last_price)
|
||||
} else {
|
||||
match side {
|
||||
OrderSide::Buy => quote.buy_price(),
|
||||
OrderSide::Sell => quote.sell_price(),
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => match side {
|
||||
OrderSide::Buy => quote.buy_price(),
|
||||
OrderSide::Sell => quote.sell_price(),
|
||||
},
|
||||
}?;
|
||||
let execution_price = self.quote_execution_price(snapshot, side, raw_price);
|
||||
if execution_price.is_finite() && execution_price > 0.0 {
|
||||
|
||||
Reference in New Issue
Block a user