Python Iceberg Buying with Randomized Order Sizing and Price Limits
Summary
This Python example implements a staged buy intended to spread a target purchase across multiple smaller limit orders. It records the starting account balance and holdings, then repeatedly places a buy below the current bid by a configurable percentage. Each order's notional size varies randomly around a chosen average, subject to available funds, the remaining purchase budget, a maximum buy price, and a minimum tradable quantity.
While an order remains open, the routine waits unless the last traded price moves sufficiently above its limit price, in which case it cancels pending orders and resumes the process. It checks balances to track spending and reports the average purchase price after fills; polling and retry delays are configurable. The document provides implementation logic, not execution evidence or measured trading results. It does not quantify market impact, fill rates, adverse selection, or exchange-specific behavior, so the approach's effectiveness depends on venue mechanics and live order handling.
Key ideas
- The routine divides a total buy budget into smaller limit orders with randomized notional sizes.
- It places orders below the current bid by a configurable percentage and enforces a maximum purchase price.
- A sufficiently adverse move in the last traded price triggers cancellation of pending orders before the process resumes.
- Account balances track spending and estimate the average purchase price after fills.
- The document gives no evidence on fill quality, market impact, or performance across exchanges.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.