Live Crypto Data in 15 Lines of Python
No account, no API key, no cost. Just an open socket and Python.
You want live crypto data. No account, no key, no cost. Binance gives it away through a WebSocket, and the whole thing fits in 15 lines of Python.
Here is the minimum that works.
This is a quick tutorial. If you want the full stack (ingestion, storage, time travel, alt-data, meteo, satellite images…), QuantLake is live: https://www.quantreo.com/quantlake-program/
1. What you need
One library.
pip install websocketsThat’s it. No Binance account. No API key. Public market streams are open.
2. The connection
Binance exposes one URL per stream. Format is simple:
wss://stream.binance.com:9443/ws/<symbol>@<stream>symbol in lowercase (btcusdt, ethusdt), stream is what you want to receive (trade, kline_1m, depth, aggTrade).
Open the socket, read messages, parse JSON. Done.
import json
import asyncio
import websockets
async def stream_trades(symbol="btcusdt"):
url = f"wss://stream.binance.com:9443/ws/{symbol}@trade"
async with websockets.connect(url) as ws:
async for msg in ws:
trade = json.loads(msg)
price = float(trade["p"])
qty = float(trade["q"])
ts = trade["T"]
print(f"{ts} {price:.2f} {qty:.4f}")
asyncio.run(stream_trades())Run it. Every trade on BTC/USDT prints in your terminal, the moment it happens.
3. What the fields mean
The JSON payload for @trade looks like this:
{
"e": "trade",
"E": 1716384000000,
"s": "BTCUSDT",
"p": "67432.10",
"q": "0.00125",
"T": 1716383999998,
"m": false
}4. Want 1-minute bars instead?
Same code, one line changes. Replace @trade with @kline_1m:
url = f”wss://stream.binance.com:9443/ws/{symbol}@kline_1m”Binance pushes the current bar on every update, and marks it closed when it’s done. The field k.x is true only on the final tick of the bar. That’s your signal to persist it.`
kline = json.loads(msg)["k"]
if kline["x"]:
print("closed bar:", kline["t"], kline["o"], kline["h"], kline["l"], kline["c"])Other useful streams, same pattern: @aggTrade for aggregated trades, @depth for order book diffs, @kline_5m, @kline_1h, etc.
5. The practical rule
This script will run, and it will fail. Sockets disconnect. Binance forces a reset every 24 hours, your network drops, your laptop sleeps. The 15-line version is for learning, not for production.
The real stack needs three things on top: auto-reconnect, persistence to a proper database, and a schema that doesn’t get corrupted on every restart.
Open the socket today. Watch the data come in. Then think about where it goes next.


