/// 订单簿单条(不可变) /// 实现 == / hashCode 让 .select() 能正确跳过无变化的重建。 class OrderBookEntry { final double price; final double amount; final double total; // 累计量 const OrderBookEntry({ required this.price, required this.amount, required this.total, }); @override bool operator ==(Object other) => identical(this, other) || other is OrderBookEntry && price == other.price && amount == other.amount && total == other.total; @override int get hashCode => Object.hash(price, amount, total); } /// 订单簿(买盘 + 卖盘) /// 实现 == / hashCode,让 .select((s) => s.orderBook) 能正确跳过无变化的重建。 /// 依赖 OrderBookEntry 已实现的 == 做逐元素深比较。 class OrderBook { final List asks; // 卖盘(从低到高) final List bids; // 买盘(从高到低) const OrderBook({required this.asks, required this.bids}); @override bool operator ==(Object other) { if (identical(this, other)) return true; if (other is! OrderBook) return false; if (asks.length != other.asks.length || bids.length != other.bids.length) { return false; } for (var i = 0; i < asks.length; i++) { if (asks[i] != other.asks[i]) return false; } for (var i = 0; i < bids.length; i++) { if (bids[i] != other.bids[i]) return false; } return true; } @override int get hashCode => Object.hash( Object.hashAll(asks), Object.hashAll(bids)); }