Settle sub-cent orders and migrate historical book prices
This commit is contained in:
@@ -27,7 +27,10 @@ impl Quote {
|
||||
let (bid, ask) = if outcome == "YES" {
|
||||
(bid, ask)
|
||||
} else {
|
||||
(ask.map(|p| 100 - p), bid.map(|p| 100 - p))
|
||||
(
|
||||
ask.map(|p| crate::tick_size::PAR - p),
|
||||
bid.map(|p| crate::tick_size::PAR - p),
|
||||
)
|
||||
};
|
||||
Ok(Self {
|
||||
seq: row.get(0)?,
|
||||
@@ -55,22 +58,22 @@ impl Quote {
|
||||
pub fn mark(&self, phase: &str) -> Option<(i64, &'static str)> {
|
||||
if phase == "continuous" {
|
||||
if let (Some(b), Some(a)) = (self.bid, self.ask) {
|
||||
if (0..=10).contains(&(a - b)) {
|
||||
return Some(((a + b) * 5000, "midpoint"));
|
||||
if (0..=1000).contains(&(a - b)) {
|
||||
return Some(((a + b) * 50, "midpoint"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if matches!(phase, "continuous" | "closed") {
|
||||
return self.last.map(|p| (p * 10000, "last_trade"));
|
||||
return self.last.map(|p| (p * 100, "last_trade"));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn event(&self) -> Value {
|
||||
let pair = self.bid.zip(self.ask);
|
||||
json!({"seq":self.seq,"at_ms":self.at_ms,"best_bid_micros":self.bid.map(|p|p*10000),
|
||||
"best_ask_micros":self.ask.map(|p|p*10000),"spread_micros":pair.map(|(b,a)|(a-b)*10000),
|
||||
"midpoint_micros":pair.map(|(b,a)|(a+b)*5000)})
|
||||
json!({"seq":self.seq,"at_ms":self.at_ms,"best_bid_micros":self.bid.map(|p|p*100),
|
||||
"best_ask_micros":self.ask.map(|p|p*100),"spread_micros":pair.map(|(b,a)|(a-b)*100),
|
||||
"midpoint_micros":pair.map(|(b,a)|(a+b)*50)})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,7 +187,13 @@ fn price_rows(db: &Connection, requests: &[PriceRequest]) -> Result<Vec<Option<S
|
||||
Side::Buy => quote.ask,
|
||||
Side::Sell => quote.bid,
|
||||
};
|
||||
prices.push(price.map(|cents| format!("{}.{:02}", cents / 100, cents % 100)));
|
||||
prices.push(price.map(|p| {
|
||||
let mut text = format!("{}.{:04}", p / 10000, p % 10000);
|
||||
while text.len() > 4 && text.ends_with('0') {
|
||||
text.pop();
|
||||
}
|
||||
text
|
||||
}));
|
||||
}
|
||||
Ok(prices)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user