Phân Tích Dữ Liệu Tần Suất Cao — Xử lý dữ liệu thị trường cấp Tick

Giao dịch tần suất cao trong crypto hoạt động ở quy mô thời gian mili giây/micro giây. Xử lý hàng triệu tick mỗi ngày, xử lý luồng dữ liệu bùng nổ và trích xuất tín hiệu vi cấu trúc phân biệt các nhà giao dịch chuyên nghiệp với phần còn lại. Hướng dẫn này trình bày qua quản lý dữ liệu cấp tick và phân tích thời gian thực giúp Smart Money API có chu kỳ làm mới 5 phút.

Thông tin chính: Cá voi không di chuyển thị trường ngay lập tức. Các giao dịch khối của họ tạo ra chữ ký có thể phát hiện trong mất cân bằng sổ lệnh, chênh lệch giá mua-bán và tỷ lệ khối lượng taker. Smart Money API nắm bắt các chữ ký này trong thời gian thực.

Thu Thập và Lưu Trữ Dữ Liệu Tick

Nguồn Dữ Liệu

Đối với crypto, dữ liệu tick đến từ:

Lưu Trữ Tick Hiệu Quả với Parquet

Lưu trữ dữ liệu cột nén để truy vấn nhanh:

Python — Quy trình dữ liệu Tick
import pandas as pd
import pyarrow.parquet as pq
# Bộ đệm tick thời gian thực (tích lũy trong 1h, sau đó lưu)
tick_buffer = []
def on_tick(exchange, symbol, price, size, side, timestamp):
tick_buffer.append({
"timestamp": timestamp,
"exchange": exchange,
"symbol": symbol,
"price": price,
"size": size,
"side": side # "buy" hoặc "sell"
})
# Mỗi giờ, nén và lưu
if len(tick_buffer) > 1_000_000:
df = pd.DataFrame(tick_buffer)
pq.write_table(
pa.Table.from_pandas(df),
f"ticks/{symbol}_{timestamp:%Y%m%d_%H}.parquet",
compression="snappy"
)
tick_buffer = []

Phân Tích Sổ Lệnh

Ảnh Chụp Sổ Lệnh Cấp 2

Chụp toàn bộ sổ lệnh mỗi 100-500ms:

Python — Xử lý sổ lệnh
class OrderBook:
def __init__(self):
self.bids = {} # giá -> kích thước
self.asks = {} # giá -> kích thước
def update(self, side, price, size):
if side == "bid":
if size == 0: del self.bids[price]
else: self.bids[price] = size
else:
if size == 0: del self.asks[price]
else: self.asks[price] = size
def get_imbalance(self, depth=10):
# Lấy 10 giá bid và ask tốt nhất
top_bids = sorted(self.bids.items(), reverse=True)[:depth]
top_asks = sorted(self.asks.items())[:depth]
bid_volume = sum(size for _, size in top_bids)
ask_volume = sum(size for _, size in top_asks)
# Imbalance: >1 = bullish (áp lực mua nhiều hơn)
return bid_volume / ask_volume if ask_volume > 0 else 1.0
def get_spread(self):
best_bid = max(self.bids.keys())
best_ask = min(self.asks.keys())
return (best_ask - best_bid) / best_bid # chênh lệch phần trăm

Tín Hiệu Vi Cấu Trúc

Trích xuất tín hiệu hành động từ cấu trúc sổ lệnh:

Chỉ Số Vi Cấu Trúc Thị Trường

Giá Trung Bình Gia Quyền Theo Khối Lượng (VWAP)

Chỉ số thực thi tốt hơn giá đóng cửa đơn thuần:

Python — Tính toán VWAP
def calculate_vwap(ticks):
# ticks: danh sách các cặp (price, volume)
numerator = sum(price * volume for price, volume in ticks)
denominator = sum(volume for _, volume in ticks)
return numerator / denominator

Tỷ Lệ Mua/Bán Taker

Xác định phe nào đang chủ động:

Python — Phân tích Taker
def get_taker_direction(tick):
# Nếu giá giao dịch = bid, người bán chủ động (cung)
# Nếu giá giao dịch = ask, người mua chủ động (cầu)
if abs(tick.price - best_bid) < tick.price_step:
return "sell"
elif abs(tick.price - best_ask) < tick.price_step:
return "buy"
else:
return "mid" # Bên trong spread, có thể là dark pool
buy_volume = sum(t.size for t in ticks if get_taker_direction(t) == "buy")
sell_volume = sum(t.size for t in ticks if get_taker_direction(t) == "sell")
return buy_volume / (buy_volume + sell_volume) # % mua

Kiến trúc Pipeline Thời Gian Thực

Xử lý luồng WebSocket

Kết nối đến WebSocket của Bybit/Binance/Hyperliquid để nhận dữ liệu trực tiếp:

Python — Bộ xử lý luồng trực tiếp
import asyncio
import websockets
async def connect_bybit_ticks(symbol):
url = f"wss://stream.bybit.com/v5/public/spot"
async with websockets.connect(url) as ws:
# Đăng ký luồng giao dịch
await ws.send(json.dumps({
"op": "subscribe",
"args": [f"publicTrade.{symbol}"]
}))
async for message in ws:
data = json.loads(message)
for trade trong dữ liệu["data"]:
on_tick(
exchange="bybit",
symbol=symbol,
price=float(trade["price"]),
size=float(trade["size"]),
side=trade["side"],
timestamp=int(trade["time"])
)

Xử lý phân tán với Redis Streams

Xử lý hàng triệu tick mỗi ngày với hàng đợi tin nhắn:

Python — Xử lý luồng Redis
import redis
r = redis.Redis(host='localhost', port=6379)
# Producer: đẩy tick vào luồng
def publish_tick(exchange, symbol, tick):
stream_key = f"ticks:{exchange}:{symbol}"
r.xadd(stream_key, {
"price": tick.price,
"size": tick.size,
"side": tick.side,
"ts": tick.timestamp
})
# Nhóm Consumer đọc với theo dõi độ trễ
r.xgroup_create(stream_key, "analytics", id="$", mkstream=True)

Thêm tín hiệu thời gian thực vào phân tích của bạn

Smart Money API tổng hợp dữ liệu tick từ 3 sàn giao dịch và 250+ ví cá voi. Sử dụng các tín hiệu vi cấu trúc được tính toán sẵn của chúng tôi để nâng cao phân tích thời gian thực của riêng bạn.

Bắt đầu Miễn Phí Hôm Nay →