Published on October 17, 2025 · by Brijesh Yadav
When building algorithmic trading systems, the hardest part to test reliably is the real-time market feed. Live markets are unpredictable, noisy, and expensive to test against. A lightweight, deterministic market data generator that simulates realistic tick-level patterns lets you validate strategies, risk controls, and order routing without paying exchange fees or risking real money.
The generator consists of five lightweight components:
WebSocket or Server-Sent Events (SSE).
A simple yet realistic price evolution model is a stochastic random walk with drift and volatility. Each tick is computed as:
p_next = p_prev * (1 + drift*dt + sigma * sqrt(dt) * N(0,1) + jump)
drift — directional bias representing market sentiment.
sigma — volatility factor controlling randomness.jump — a sudden change drawn from a Poisson process (for
“news” events).
You can further enhance realism by rounding prices to tick size, generating heavy-tailed trade volumes, and simulating spreads between bid and ask quotes.
import asyncio, random, math, json, datetime
async def tick_generator(symbol, base_price=100.0, drift=0.0001, sigma=0.001):
p = base_price
while True:
dt = 1/100 # seconds between ticks
jump = 0
if random.random() < 0.0005: # rare news event
jump = random.uniform(-0.03, 0.05)
p *= (1 + drift*dt + sigma*math.sqrt(dt)*random.gauss(0,1) + jump)
yield {
"symbol": symbol,
"price": round(p, 2),
"volume": random.randint(10, 1000),
"timestamp": datetime.datetime.utcnow().isoformat() + "Z"
}
await asyncio.sleep(dt)
This coroutine continuously yields ticks that you can broadcast via
FastAPI using WebSockets or
Server-Sent Events.
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
import asyncio, json
app = FastAPI()
async def event_stream():
gen = tick_generator("RELIANCE")
async for tick in gen:
yield f"data: {json.dumps(tick)}\n\n"
@app.get("/stream")
async def stream():
return StreamingResponse(event_stream(), media_type="text/event-stream")
Your frontend can connect using JavaScript’s EventSource:
const es = new EventSource("/stream");
es.onmessage = (e) => {
const tick = JSON.parse(e.data);
console.log("Tick:", tick.symbol, tick.price);
};
To make simulations meaningful, add a “scenario engine” that manipulates volatility and drift. For instance:
sigma by 5×
for 2 minutes.
You can embed the generator into automated test pipelines:
Here’s a simplified flow of the generator setup:
[Generator] → [FastAPI / Redis Stream] → [Trading Engine] → [Frontend Dashboard]
Each stage consumes real-time data just like a production setup, but under full developer control.
A reliable market data generator is an indispensable tool for any algorithmic trading system. It bridges the gap between theory and production by providing controlled realism. Start with a single-symbol generator and incrementally add features — volatility modeling, bursts, option greeks, or multi-exchange feeds.
For Growth Quantix, my goal is to use this generator to validate latency, signal accuracy, and trade execution logic before connecting to the real Upstox live feed. The same system can even run on weekends for regression testing or strategy dry-runs.
— Brijesh Yadav