Merge pull request '扩展体育事件、规则文本与成交价格曲线' (#5) from codex/market-data-model into main

Reviewed-on: #5
This commit was merged in pull request #5.
This commit is contained in:
2026-12-02 20:45:27 +00:00
36 changed files with 3960 additions and 112 deletions
+30
View File
@@ -41,6 +41,36 @@ impl OrderBook {
}
}
/// Buy whole shares at maker prices, walking the same FIFO ask tree as a limit buy.
pub fn match_budget_buy(&self, seq: i64, limit: i64, budget: i64) -> Vec<Fill> {
let mut cash = budget;
let mut capacity = i64::MAX;
let mut fills = Vec::new();
for ask in self.asks.values() {
if cash <= 0 || ask.price > limit || capacity == 0 {
break;
}
let affordable = if ask.price == 0 {
capacity
} else {
cash / ask.price
};
let quantity = ask.remaining.min(affordable).min(capacity);
if quantity <= 0 {
break;
}
fills.push(Fill {
bid: seq,
ask: ask.seq,
price: ask.price,
quantity,
});
cash -= ask.price * quantity;
capacity -= quantity;
}
fills
}
pub fn opening(&self) -> Vec<Fill> {
let (Some(bid), Some(ask)) = (self.bids.values().next(), self.asks.values().next()) else {
return Vec::new();