research
Trading Agents: Sanity for f64 Prices
A practical dispatch on the price-handling skill for trading systems: avoid float pitfalls, format correctly, and keep agents correct.
Where this fits
You're building a trading agent that consumes a live market feed, computes prices, and places orders with a broker. You quickly realize f64 equality is a trap: two prices that look identical on screen differ by a billionth of a cent. Rounding to the exchange's tick size becomes a manual chore, and your order payloads get rejected because of formatting drift. The price-handling skill packages the patterns that production trading systems use to keep prices correct across parsing, comparison, formatting, and struct design. It's a ready-made reference for the next time you touch a price type.
Why agents benefit
- Correct price comparisons: uses an epsilon margin instead of
==, so your agent doesn't fire duplicate orders or miss valid fills due to float noise. - Broker‑ready formatting: knows how to round to tick size and print prices exactly as your broker API expects, eliminating rejected orders.
- Robust feed parsing: handles the string formats that real exchanges return, including decimal and exponential forms, without throwing.
- Struct design guidance: shows when to use
f64vsi64fixed‑point, so you can choose the right representation for your hot path and settlement logic. - Consistent convention: agents using the skill share a unified price‑handling vocabulary, making cross‑team code review and maintenance simpler.
For more context on how this skill fits into a larger agent toolkit, see the OpenAgentSkill listing.
Practical scenarios
Rounding to tick size for order placement
Your agent wants to buy BTC at the current ask. The ask is 12345.6789, but the exchange only accepts two decimal places. The skill provides a round_to_tick helper that takes the tick size and returns 12345.68 – no more manual f64::round mistakes.
Parsing price strings from a market feed
A feed sends "123.45" for one venue and "1.2345e2" for another. The skill's parser handles both, converting them into f64 with a consistent internal representation. Your agent can now compare prices from multiple sources without pre‑processing each format.
Comparing bid/ask across venues
You're simulating arbitrage. Two venues quote nearly identical prices, but a naive == would declare them different. Using the skill's prices_equal with a realistic epsilon, your agent correctly identifies that the difference is below the cost of execution and doesn't trigger a trade.
Add it to your agent workflow
Install the skill via npx:
npx skills add vanillagreencom/kendex --skill price-handling
Then reference it in your prompt or agent logic when you need price logic. For example:
You are a trading agent. When comparing prices, use the `prices_equal` function from the price-handling skill. Round all outgoing order prices to the exchange tick size using `round_to_tick`.
This keeps your agent's price handling consistent and avoids re‑implementing floating‑point edge cases on every run.
Compare before adopting
Before pulling this skill in, check the repo's health: does it have recent commits, open issues, and a responsive maintainer? (64 stars is a starting signal, but activity matters more.) Compare it with alternatives like decimal libraries or fixed‑point crates – the skill's guidance may be enough for your use case, but if you need bit‑exact arithmetic, you'll still want an i64 approach. Also verify it fits your agent's workflow: the skill is a pattern reference, not a runtime dependency, so it works with any agent framework.
Why it is worth tracking
The skill directly addresses a class of bugs that plague trading agents (float precision, format drift) and packages battle‑tested conventions from the kendex trading engine. The fact that it's versioned, MIT‑licensed, and tied to a real repo with issue tracking suggests it will remain maintained. Track it if you're building any system that touches prices – it's a low‑effort way to sidestep weeks of debugging. As the ecosystem evolves, expect updates to cover new exchange formats and additional edge cases.
Featured Skill
price-handling
Skill by vanillagreencom