Trading Bot Rounding Bug Can Risk 10x Your Intended Position Size
A common one-line rounding pattern in trading bots — using max(1, int(theoretical_quantity / contract_size)) — can silently open positions ten times larger than intended. The bug occurs because int() truncates small values to zero, and max(1, ...) then forces the position to a minimum of one full contract. For example, a $500 account risking 1% ($5) could end up with a $50 notional position without any error or warning from the exchange. The author identified this flaw in their own bot and released an open-source Python library called position-sizing (Apache-2.0) that uses Decimal arithmetic, always rounds down, and returns a structured result explaining why a trade was skipped when minimum market size exceeds the risk budget. Developers are advised to audit any bot containing that rounding pattern and replace it with logic that explicitly handles exchange constraints and commission costs.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in