A price field can contain a perfectly valid decimal and still fail a venue's tick rule. That creates an awkward temptation in a client application: round the number until the request looks acceptable. The user then submits a different price from the one they entered.
This example keeps validation separate from changing an input. It checks one static price filter, returns specific reasons for rejection, and makes no network calls. It does not submit orders or predict whether an exchange will accept one.
Start with an explicit snapshot
The Binance Spot API documentation describes PRICE_FILTER with three independently enabled rules: a lower bound, an upper bound and a tick increment. A zero value disables the corresponding price rule. The tick test is a multiple of the increment from zero; the minimum price is a separate bound. These details matter when writing fixtures: subtracting the minimum before checking the increment would implement a different rule.
Source checked on November 23, 2026: Binance's official binance-spot-api-docs repository, filters.md, the PRICE_FILTER section. The numbers below are invented test inputs, not a current symbol's trading rules. In an application, store the symbol, product, retrieval time and original metadata response alongside each snapshot.
Validate without changing the submitted value
import re from decimal import Decimal def decimal_input(text): # A bounded demo grammar; reject signs, exponents and special values. if not isinstance(text, str) or not re.fullmatch( r"[0-9]{1,18}(?:\.[0-9]{1,18})?", text ): raise ValueError("use a non-negative decimal string") return Decimal(text) def is_multiple(value, increment): # Integer arithmetic avoids Decimal context precision in division. vn, vd = value.as_integer_ratio() sn, sd = increment.as_integer_ratio() return (vn * sd) % (vd * sn) == 0 def price_errors(text, snapshot): price = decimal_input(text) low, high, tick = ( decimal_input(snapshot[key]) for key in ("minPrice", "maxPrice", "tickSize") ) if low and high and low > high: raise ValueError("inconsistent filter snapshot") errors = [] if price == 0: errors.append("application requires a positive limit price") if low and price < low: errors.append("below minPrice") if high and price > high: errors.append("above maxPrice") if tick and not is_multiple(price, tick): errors.append("not a multiple of tickSize") return errors rules = {"minPrice": "0.01", "maxPrice": "10", "tickSize": "0.05"} assert price_errors("1.20", rules) == [] assert price_errors("1.21", rules) == ["not a multiple of tickSize"] assert price_errors("0.01", rules) == ["not a multiple of tickSize"] assert price_errors("10.05", rules) == ["above maxPrice"] assert price_errors("1.21", {**rules, "tickSize": "0"}) == [] The third assertion protects a small but consequential distinction. A price can equal the minimum while still violating the increment rule. The final assertion checks that disabling the tick rule does not accidentally invoke a modulo operation with zero.
The decimal parser is deliberately narrower than every possible API representation. It accepts at most eighteen digits on either side of the point. If a metadata format exceeds those bounds, reject the snapshot and review the parser instead of truncating the value. A float is rejected even when it appears to print the desired decimal; the caller must preserve the original text.
Keep failure categories useful
Malformed metadata raises an exception. A well-formed price that fails a known rule returns an explanation. Neither case automatically rewrites the user's number. A UI can offer a separately labelled edit, but it should display the proposed value and require the normal confirmation flow before submission.
Test the distinction at the adapter boundary. Preserve the original request text and snapshot identifier so a rejected request can be replayed offline. Add fixtures for disabled bounds, exact endpoints, tiny increments, malformed strings and metadata changes between two validations. Use synthetic fixtures for development; do not place real orders to test a parser.
This function covers only the three static PRICE_FILTER fields plus the application's positive-price requirement. It leaves quantity, notional, dynamic price ranges, available balances, account eligibility and order type to their own checks. A passing result is therefore a partial validation result, never an instruction to send an order. The server remains authoritative when metadata changes after collection.
Keep validation separate from cost estimates
A price that fits an increment says nothing about the final fee, spread or withdrawal cost. The earlier article on testing a fee model's flat component covers a different part of that calculation. Keeping these checks separate gives each test a clear purpose.
For the surrounding record checks, the first-trade cost and reconciliation checklist prompts a comparison between assumptions, quoted charges and the resulting account record. Disclosure: LedDLP is maintained by this publication's operator. The checklist is context for checking records, not evidence that the parser implements every venue rule or that a transaction is suitable.
