Back
Challenge 12 - Immediate Or Cancel Buy
HardOrderbookIOC12 / 12

Challenge 12: Immediate Or Cancel Buy

An IOC order executes immediately and cancels whatever cannot fill.

Task

Implement ioc_buy.

Rules

  • Consume asks from lowest price to highest price.
  • Track total base filled.
  • Track total quote spent.
  • Return leftover quantity as canceled.
  • Do not insert leftover quantity into the book.

Example

Trying to buy 8 base units against:

  • 2 at 100
  • 3 at 105

Only 5 units can fill:

filled = 5
spent = 2*100 + 3*105 = 515
canceled = 3
LanguageRust
Loading editor...
Run works without login. Submit requires sign-in so completion can be saved.
Run cases to compare your output against each configured input. Submit saves progress only when every case passes.
    Challenge 12 - Immediate Or Cancel Buy · ORDERBOOK Exercise | learn.sol