Normalize Order Price and Quantity to Tick and Lot Size

Last updated: November 29, 2026

Quick Overview

Given a raw order (side, price, quantity as strings) and an instrument's tick size, lot size and minimum order size, return the exact normalized price and quantity or reject the order. Buys must round down and sells must round up so the exchange never makes an order more aggressive than the trader asked.

Gemini
Coding & Algorithms
Software Engineer
Gemini
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a raw order (side, price, quantity as strings) and an instrument's tick size, lot size and minimum order size, return the exact normalized price and quantity or reject the order. Buys must round down and sells must round up so the exchange never makes an order more aggressive than the trader asked.

A warm-up in the style of a Gemini exchange phone screen: every ActiveTrader and API order passes through validation like this before it reaches the matching engine. The interviewer is checking that you refuse binary floats for money, know which way to round for each side, and treat rejection as a first-class outcome.

What the Interviewer Expects
  • Use Decimal (or integer minor units), never float, and explain why 0.1 + 0.2 breaks validation
  • Round buy prices down and sell prices up to the tick, and quantity down to the lot
  • Reject non-positive, non-finite and below-minimum orders with clear reasons
  • Return values quantized to the instrument's precision for a canonical string form
  • Test with values already on the grid and values just off it
Key Topics to Cover
Decimal Arithmetic
Rounding Modes
Input Validation
Order Entry
Fixed Point
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you store prices if the engine is written in Scala or Go and needs speed?
  • Should the exchange round silently or reject off-tick prices, and who decides?
  • How do you handle an instrument whose tick size changes while orders are resting?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Inputs are strings as they arrive in a JSON API payload: side (buy or sell), price, qty, plus instrument metadata tick (for example 0.01 USD for BTCUSD), lot (0.00000001 BTC) and `min_qt...

High-Level Design

Parse with Decimal straight from the string so no binary float error appears. Divide by the tick, round to an integer with a side-dependent rounding mode, multiply back. Same for quantity with floor...


Submit Your Answer
Markdown supported

Related Questions