Rs
Module 5HashMap & BTreeMapLesson 5 of 820 min

BTreeMap Order Levels

Sorted price levels for a toy limit book.

BTreeMap keeps keys sorted

rust
use std::collections::BTreeMap;
let mut asks = BTreeMap::new();
asks.insert(10005, 8.0);

Best levels

Best ask: first key. Best bid: last key via next_back(). Integer ticks avoid float keys.

Challenge

Build bids map and print best bid with next_back().

Tips
  • BTreeMap keys are Ord
  • i64 ticks are practical
  • Full book struct later

Try it live

BTreeMap Order LevelsRust 2021
Loading editor…
Output
Press Run to compile and execute.