惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
小众软件
小众软件
Last Week in AI
Last Week in AI
月光博客
月光博客
博客园 - 聂微东
Recent Announcements
Recent Announcements
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
博客园 - Franky
云风的 BLOG
云风的 BLOG
量子位
N
Netflix TechBlog - Medium
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
博客园 - 司徒正美
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I built a fake market data generator for trading UIs,...
Love Pareek · 2026-05-07 · via DEV Community

Love Pareek

Every time I built a trading UI, I hit the same wall - real data feeds cost thousands per month.
Free APIs have strict rate limits. And I just wanted to test my UI.

So I built trade-data-generator, an npm library that generates realistic synthetic market data for equity, forex, and crypto.

The Problem

Building a trading UI requires live market data.
Your options are:

  • Bloomberg/Refinitiv — $2,000+/month
  • Free APIs — rate limited, unreliable
  • Hardcoded fake data — not realistic, The charts look broken None of these works well for development and testing.

The Solution

npm install trade-data-generator

Enter fullscreen mode Exit fullscreen mode

Zero dependencies. Zero API keys. Works offline.

How It Works

const { MarketFeed } = require('trade-data-generator')

const feed = new MarketFeed({
  type: 'crypto',
  pairs: [
    { symbol: 'BTC/USDT', startPrice: 45000, 
      volatility: 0.004 },
    { symbol: 'ETH/USDT', startPrice: 2800,  
      volatility: 0.005 },
  ]
})

feed.on('tick',   (data) => console.log(data))
feed.on('candle', (data) => console.log(data))
feed.on('depth',  (data) => console.log(data))

feed.start()

Enter fullscreen mode Exit fullscreen mode

What You Get

Every tick emits realistic data:

{
  "symbol": "BTC/USDT",
  "price": 45016.14,
  "bid": 44993.63,
  "ask": 45038.65,
  "volume": 4,
  "changePct": 0.04,
  "high24h": 45200.00,
  "low24h": 44800.00
}

Enter fullscreen mode Exit fullscreen mode

Price Simulation

The price engine uses three forces:
1. Random walk - Box-Muller normal distribution. Small moves most of the time, occasional spikes. More realistic than
flat Math.random().
2. Mean reversion - Price always pulls back toward the start price. Prevents
infinite drift.
3. Trend bias - Optional slight upward or downward drift per symbol.

Order Book

Every depth event has a realistic order book:

  • Best bid is always below best ask
  • Volume tapers with depth (more liquidity near mid price)
  • Spread is configurable per symbol

Market Hours

Equity and forex respect real market hours:

const feed = new MarketFeed({
  type: 'equity',
  marketHours: {
    open:     '09:30',
    close:    '16:00',
    timezone: 'America/New_York',
    days:     [1, 2, 3, 4, 5],
  },
  pairs: [
    { symbol: 'AAPL', startPrice: 175.50 }
  ]
})

feed.on('open',   (info) => console.log('Market opened'))
feed.on('closed', (info) => console.log('Market closed'))

Enter fullscreen mode Exit fullscreen mode

Crypto is always open — no market hours needed.

WebSocket Integration

The library uses EventEmitter, you own
the WebSocket server. Works with Socket.io,
ws, Pusher, Ably, or anything else:

const { Server } = require('socket.io')
const io = new Server(3001)

feed.on('tick', (data) => {
  io.to(data.symbol).emit('ticker_update', data)
})

feed.on('depth', (data) => {
  io.to(data.symbol).emit('orderbook_update', data)
})

io.on('connection', (socket) => {
  socket.on('subscribe', ({ symbol }) => {
    socket.join(symbol)
    socket.emit('snapshot', feed.getState(symbol))
  })
})

feed.start()

Enter fullscreen mode Exit fullscreen mode

Supported Markets

Type Always Open Market Hours Precision
Crypto Not needed 2-8 dp
Forex Configurable 5 dp
Equity Configurable 2 dp

Install

npm install trade-data-generator

Enter fullscreen mode Exit fullscreen mode

  • Zero dependencies
  • TypeScript support
  • Node.js 14+

Links


Would love feedback — what would make this
more useful for your workflow?