This document provides a technical reference for the key classes and methods in the Trade Simulator application.
class OrderBookManager:
"""Manages the connection to WebSocket and processes orderbook data."""
def connect(self, exchange: str, symbol: str) -> bool:
"""
Establish connection to the WebSocket endpoint for the specified exchange and symbol.
Args:
exchange: Exchange name (e.g., 'OKX')
symbol: Trading pair symbol (e.g., 'BTC-USDT-SWAP')
Returns:
True if connection was successful, False otherwise
"""class WebSocketClient:
"""Client for WebSocket connections to exchange endpoints."""
def connect(self) -> None:
"""Establish connection to the WebSocket endpoint."""
def disconnect(self) -> None:
"""Close the WebSocket connection."""
def register_callback(self, callback: Callable[[Dict], None]) -> None:
"""
Register a callback function to handle incoming data.
Args:
callback: Function that takes a dictionary with orderbook data
"""class SlippageModel:
"""Model for estimating trade slippage based on orderbook data."""
def train_initial_model(self, orderbooks: List[Dict] = None) -> None:
"""
Train model with either real orderbook data or realistic market simulations.
Args:
orderbooks: Optional list of orderbook snapshots for training
"""
def estimate_slippage(self, orderbook: Dict, quantity: float, is_buy: bool = True) -> Tuple[float, float]:
"""
Estimate slippage for a given trade.
Args:
orderbook: L2 orderbook data
quantity: Trade quantity in quote currency
is_buy: Whether this is a buy (True) or sell (False) order
Returns:
Tuple of (slippage_amount, slippage_percentage)
"""class AlmgrenChrissModel:
"""Market impact model based on Almgren-Chriss framework."""
def update_parameters(self, sigma: float = None, eta: float = None,
epsilon: float = None, gamma: float = None) -> None:
"""
Update model parameters.
Args:
sigma: Market volatility
eta: Temporary impact factor
epsilon: Minimum impact threshold
gamma: Permanent impact factor
"""
def calculate_market_impact(self, orderbook: Dict, quantity: float,
market_cap: float, avg_daily_volume: float) -> Dict:
"""
Calculate market impact for a trade.
Args:
orderbook: L2 orderbook data
quantity: Trade quantity in base currency
market_cap: Market capitalization of the asset
avg_daily_volume: Average daily trading volume
Returns:
Dictionary with impact results including amount and percentage
"""class MakerTakerModel:
"""Model for predicting the maker/taker proportion of a trade."""
def train_initial_model(self, orderbooks: List[Dict] = None) -> None:
"""
Train model with either real orderbook data or realistic market simulations.
Args:
orderbooks: Optional list of orderbook snapshots for training
"""
def predict_maker_taker_proportion(self, orderbook: Dict, quantity: float) -> Tuple[float, float]:
"""
Predict the maker/taker proportion for a given trade.
Args:
orderbook: L2 orderbook data
quantity: Trade quantity
Returns:
Tuple of (maker_proportion, taker_proportion)
"""class TradeSimulatorApp(QMainWindow):
"""Main application window for the trade simulator."""
def run_simulation(self) -> None:
"""Run the simulation with current parameters."""
def update_simulation(self, force: bool = False) -> None:
"""
Update simulation results.
Args:
force: If True, force update even if parameters haven't changed
"""
def update_orderbook(self, orderbook: Dict) -> None:
"""
Update orderbook data.
Args:
orderbook: New orderbook data
"""class OrderBookWidget(QWidget):
"""Widget for displaying the L2 orderbook."""
def update_orderbook(self, orderbook: Dict) -> None:
"""
Update with new orderbook data.
Args:
orderbook: New orderbook data
"""class FeeCalculator:
"""Calculator for trading fees based on exchange fee structure."""
def calculate_fee(self, exchange: str, fee_tier: str,
quantity: float, price: float, is_maker: bool = False) -> float:
"""
Calculate trading fee for a trade.
Args:
exchange: Exchange name
fee_tier: Fee tier (e.g., 'VIP-0')
quantity: Trade quantity
price: Execution price
is_maker: Whether trade executed as maker
Returns:
Fee amount in quote currency
"""