Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Market Data & Market Making

Live BTC/USD market data feed with a simulated market making engine, built on Binance WebSocket streams.

Setup

pip install -r requirements.txt

Python 3.11+ required.


Streamlit Dashboard

Interactive web UI with live charts, configurable strategy parameters, and CSV export.

Live demo: https://mm-dashboard-microstructure.streamlit.app/

The demo runs on Binance US (spot only). For Binance spot/futures, run locally. Set the theme to Dark in the Streamlit settings (top-right menu → Settings) for the best experience.

streamlit run streamlit_app.py

Opens at http://localhost:8501. All parameters are adjustable from the sidebar without restarting.


Console

Runs in the terminal. Displays order book, recent trades, spread statistics, simulated fills, markout analytics, and queue diagnostics — all refreshed in real time.

python app.py

Options:

Flag Default Description
--symbol BTCUSDT Symbol to stream, e.g. SOLUSDT, ETHUSDT
--exchange binance binance or binance_us
--mm-quote-mode top Quote placement mode (see below)
--mm-spread-pct 0.002 Total bid/ask spread in %, e.g. 0.01
--mm-bid-level 1 Book level for level mode
--mm-ask-level 1 Book level for level mode
--mm-queue-ahead-multiple 3.0 Max queue ahead multiplier for queue_aware mode
--depth 5 Number of order book levels to display
--refresh-seconds 1.0 Terminal refresh interval

Examples:

# SOL/USDT with a 0.01% spread, top-of-book mode
python app.py --symbol SOLUSDT --mm-spread-pct 0.01 --mm-quote-mode top

# BTC with queue-aware mode, max 5x queue ahead
python app.py --mm-quote-mode queue_aware --mm-queue-ahead-multiple 5.0

# Level 2 on both sides
python app.py --mm-quote-mode level --mm-bid-level 2 --mm-ask-level 2

Quote Modes

Mode How it works
mid Posts bid/ask symmetrically around the mid-price. Spread parameter controls the distance.
top Joins the current best bid and best ask. Tightest possible quotes.
level Joins a specific book level (e.g. L2, L3). Controlled by --mm-bid-level / --mm-ask-level.
microprice Like mid but centers on the volume-weighted mid (accounts for bid/ask size imbalance).
queue_aware Finds the most aggressive level where estimated queue ahead ≤ N × quote size. Balances fill probability vs. adverse selection.

Strategy Parameters

Inventory skew — shifts quotes away from the current position to reduce exposure. Long → quotes move lower to sell; short → quotes move higher to buy.

Imbalance skew — shifts quotes based on top-of-book bid/ask size imbalance. More bids than asks → quote slightly higher.

Volatility spread coeff — widens the quoted spread dynamically during fast markets: effective_spread = base_spread + coeff × short_term_move_bps. Only active in mid and microprice modes.

Volatility gate — suspends quoting entirely when the mid-price moves more than N bps within the volatility window. Set to 0 to disable.


Risk Management

  • Max notional exposure: stops quoting if |position| × mark_price exceeds the limit (default $1,000,000)
  • Max loss: halts all trading if total P&L drops below −$100,000 (10% of initial $1M deposit)

What is displayed

Order book — top N bid/ask levels with your simulated quotes highlighted.

Spread statistics — cost of crossing the spread for sizes of 0.1, 1, 5, 10 BTC. Includes current, average, median, min, max, and rolling averages over 1m / 5m / 15m.

Simulated fills — each fill shows side, price, size, and markout at 1s / 5s / 10s after fill. Negative markout = adverse selection (price moved against you after the fill).

Queue diagnostics — tracks how much volume was ahead of your quote in the book and how that correlates with fill probability.

P&L — realized, unrealized, and total. Unrealized uses current mid-price as mark.

CSV export (Streamlit only) — trade log with markout, and full P&L history tick by tick.

About

Real-time BTC/USDT market data dashboard with a simulated market making engine, live order book visualization, queue-aware quoting, markout analytics, volatility controls, and P&L tracking.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages