Overview
ClyptQ uses TradingSpec to manage all configuration in a unified manner. A single spec file defines strategy, data, and execution environment, providing reproducible and shareable configuration.TradingSpec Structure
Copy
from clyptq.apps.trading.spec import TradingSpec
spec = TradingSpec(
# 1. Strategy definition
strategy=StrategySpec(...),
# 2. Data configuration
data=TradingDataSpec(...),
# 3. Execution configuration
execution=TradingExecutionSpec(...),
# 4. Account configuration
accounts=[AccountSpec(...)],
# 5. Symbol mapping
symbol_source_map=SymbolSourceMap(...)
)
Strategy Configuration
ComputeGraph Definition:Copy
from clyptq.system.graph import ComputeGraph, Input
graph = ComputeGraph()
# Nodes
close = graph.add_node("close", FieldExtractor("close"))
sma_fast = graph.add_node("sma_fast", SMA(Input("close", lookback=10), span=10))
sma_slow = graph.add_node("sma_slow", SMA(Input("close", lookback=50), span=50))
signal = graph.add_node("signal",
CrossoverAlpha(Input("sma_fast", lookback=1), Input("sma_slow", lookback=1))
)
# StrategySpec
strategy_spec = StrategySpec(
graph=graph,
signal_node="signal", # Alpha signal node
output_nodes=["signal", "sma_fast", "sma_slow"] # Nodes to save
)
Copy
# Save to YAML
spec.to_yaml("my_strategy.yaml")
# Load from YAML
spec = TradingSpec.from_yaml("my_strategy.yaml")
Data Configuration
Observation Specs:Copy
from clyptq.apps.trading.spec.observation import OHLCVSpec
data_spec = TradingDataSpec(
observations=[
OHLCVSpec(
identifier="ohlcv_1m",
venue="binance",
market_type="futures",
timeframe="1m",
fields=["open", "high", "low", "close", "volume"]
),
OHLCVSpec(
identifier="ohlcv_1h",
venue="binance",
market_type="futures",
timeframe="1h",
fields=["open", "high", "low", "close", "volume"]
)
],
# Redis (optional)
redis_mode=False,
redis_url="redis://localhost:6379/0",
redis_channel_prefix="live"
)
Copy
symbol_map = SymbolSourceMap(
mappings={
"BTC/USDT:USDT": ["ohlcv_1m", "ohlcv_1h"],
"ETH/USDT:USDT": ["ohlcv_1m"]
}
)
Execution Configuration
Backtest:Copy
execution_spec = TradingExecutionSpec(
mode="backtest",
venue="binance",
market_type="futures",
# Latency mode
latency_mode="INSTANT", # or "LATENT"
# Fill model (LATENT only)
fill_model="aggressive", # or "passive"
# Clock
clock_freq="1m", # Execution frequency
clock_offset=0 # Offset (seconds)
)
Copy
execution_spec = TradingExecutionSpec(
mode="paper", # or "live"
venue="binance",
market_type="futures",
# API credentials (live only)
api_key=os.getenv("BINANCE_API_KEY"),
api_secret=os.getenv("BINANCE_API_SECRET"),
# Risk limits
max_position_size={"BTC/USDT:USDT": 10.0},
max_position_pct=0.3,
max_leverage=5.0,
max_drawdown=0.20,
# Order config
default_order_type="market", # or "limit"
time_in_force="GTC"
)
Account Configuration
Spot Account:Copy
account = AccountSpec(
type="spot",
venue="binance",
initial_balance={"USDT": 10000.0},
# Cost model
maker_fee=0.001,
taker_fee=0.001,
min_notional=10.0
)
Copy
account = AccountSpec(
type="futures",
venue="binance",
initial_balance={"USDT": 10000.0},
# Margin config
margin_type="CROSS", # or "ISOLATED"
default_leverage=3.0,
max_leverage=10.0,
# Cost model
maker_fee=0.0002,
taker_fee=0.0004,
funding_interval=28800 # 8 hours
)
Environment Variables
Required Settings:Copy
# Environment mode
export CLYPTQ_ENV=dev # dev | prod | collector | kernel
# Storage paths
export CLYPTQ_DATA_ROOT=./data # dev
export CLYPTQ_STORAGE_ROOT=/efs/data # prod/collector
export CLYPTQ_BACKEND_URL=http://backend:8000 # kernel
# API credentials (live trading)
export BINANCE_API_KEY=your_key
export BINANCE_API_SECRET=your_secret
# Redis (optional)
export REDIS_URL=redis://localhost:6379/0
Copy
# Logging
export LOG_LEVEL=INFO # DEBUG | INFO | WARNING | ERROR
# Performance
export MAX_WORKERS=4 # Parallel execution workers
# Database (prod)
export DATABASE_URL=postgresql://user:pass@host/db
Complete Example
Backtest Configuration:Copy
from clyptq.apps.trading.spec import TradingSpec
from clyptq.apps.trading.spec.observation import OHLCVSpec
spec = TradingSpec(
# Strategy
strategy=StrategySpec(
graph=create_momentum_strategy(),
signal_node="signal"
),
# Data
data=TradingDataSpec(
observations=[
OHLCVSpec(
identifier="ohlcv_1m",
venue="binance",
market_type="futures",
timeframe="1m",
fields=["close", "volume"]
)
]
),
# Execution
execution=TradingExecutionSpec(
mode="backtest",
venue="binance",
market_type="futures",
latency_mode="LATENT",
fill_model="aggressive",
clock_freq="1m"
),
# Account
accounts=[
AccountSpec(
type="futures",
venue="binance",
initial_balance={"USDT": 10000.0},
margin_type="CROSS",
default_leverage=3.0
)
],
# Symbol mapping
symbol_source_map=SymbolSourceMap(
mappings={
"BTC/USDT:USDT": ["ohlcv_1m"],
"ETH/USDT:USDT": ["ohlcv_1m"]
}
)
)
# Save
spec.to_yaml("momentum_backtest.yaml")
Copy
spec = TradingSpec(
# Same strategy
strategy=strategy_spec,
# Same data (live mode)
data=data_spec,
# Live execution
execution=TradingExecutionSpec(
mode="live",
venue="binance",
market_type="futures",
api_key=os.getenv("BINANCE_API_KEY"),
api_secret=os.getenv("BINANCE_API_SECRET"),
# Risk management
max_position_pct=0.2,
max_leverage=3.0,
max_drawdown=0.15
),
# Live account
accounts=[
AccountSpec(
type="futures",
venue="binance",
# No initial_balance (use actual balance)
margin_type="CROSS",
default_leverage=3.0
)
],
symbol_source_map=symbol_map
)
spec.to_yaml("momentum_live.yaml")
Best Practices
1. Manage All Config with SpecCopy
# Good: Single spec file
spec = TradingSpec.from_yaml("strategy.yaml")
driver = TradingDriver.from_spec(spec)
# Bad: Hardcode in code
driver = TradingDriver(venue="binance", ...)
Copy
configs/
├── momentum_backtest.yaml
├── momentum_paper.yaml
└── momentum_live.yaml
Copy
spec = TradingSpec(
version="1.0.0", # Spec version
description="Momentum crossover strategy",
...
)
Copy
# Spec validation
spec.validate() # Check required fields, verify logic
# Pre-execution validation
driver = TradingDriver.from_spec(spec)
driver.validate_before_run() # Data availability, etc.
Copy
# Good: Environment variables
api_key=os.getenv("BINANCE_API_KEY")
# Bad: Hardcode
api_key="my_secret_key" # Never commit!
Copy
# Always configure
execution_spec = TradingExecutionSpec(
max_position_pct=0.3, # Max 30% of portfolio
max_leverage=5.0, # Max 5x
max_drawdown=0.20, # Stop at 20% loss
...
)
Migration
Backtest → Paper:Copy
# 1. Load backtest spec
backtest_spec = TradingSpec.from_yaml("backtest.yaml")
# 2. Change execution mode only
paper_spec = backtest_spec.copy()
paper_spec.execution.mode = "paper"
# 3. Save
paper_spec.to_yaml("paper.yaml")
Copy
# 1. Load paper spec
paper_spec = TradingSpec.from_yaml("paper.yaml")
# 2. Convert to live
live_spec = paper_spec.copy()
live_spec.execution.mode = "live"
live_spec.execution.api_key = os.getenv("BINANCE_API_KEY")
live_spec.execution.api_secret = os.getenv("BINANCE_API_SECRET")
# 3. Tighten risk limits
live_spec.execution.max_position_pct = 0.1 # More conservative
live_spec.execution.max_drawdown = 0.10
# 4. Save
live_spec.to_yaml("live.yaml")
Ecosystem Integration
For Builders:- Share strategies via spec files
- Reproducible configuration
- Easy version control
- Transparent strategy configuration
- Verify risk parameters
- Guarantee identical settings
