Traderion Framework Overview¶
The Traderion framework provides a robust foundation for developing and executing trading strategies. It follows an event-driven architecture that reacts to market changes and executes trades through a well-defined component hierarchy. This guide provides an overview of the framework's core components and how they interact.
Core Architecture¶
Class Diagram¶
classDiagram
TraderionBot <|-- CustomBot
TraderionBot <|-- StrategyBot
StrategyBot o-- Strategy
Strategy <|-- TechnicalAnalysis
TechnicalAnalysis <|-- CrossingEMAs
TechnicalAnalysis <|-- Macd
TechnicalAnalysis <|-- Rsi
Strategy <|-- Clients
Strategy <|-- Cover
class TraderionBot {
+TraderionClient api
+Queue queue
+float loop_sleep
+Dashboard dashboard
+on_market_price_change()
+on_price_curve_change()
+on_new_client_call()
+on_client_deal()
+on_client_reject()
+on_eb_depth_change()
+on_orders_change()
+on_position_change()
+on_room_status_change()
+main_loop()
+log_info()
+run()
}
class Dashboard {
+dict core_data
+deque market_history
+deque event_history
+deque performance_history
+list custom_panels
+update_core_data()
+add_market_event()
+add_bot_event()
+add_performance_metric()
+add_custom_panel()
+draw_dashboard()
+run_dashboard()
}
class TechnicalAnalysis {
+int target_amount
+list depth
+list price_curve
+on_eb_depth_change()
+on_price_curve_change()
}
class CrossingEMAs {
+int small_ema_period
+int big_ema_period
+float small_ema
+float big_ema
+compute_emas()
+get_new_cross_direction()
}
class Macd {
+int small_ema_period
+int big_ema_period
+int signal_ema_period
+float macd
+float signal_line
+compute_macd()
}
class Rsi {
+int period
+int overbought_threshold
+int oversold_threshold
+float rsi
+compute_rsi()
}
class Clients {
+function get_client_quote_spread
+function get_own_quote_spread
+check_for_arbitrage()
+quote_to_client_call()
}
class Cover {
+int position_limit
+get_cover_amount()
}
The class diagram shows the inheritance hierarchy and relationships between core components. The TraderionBot class serves as the foundation, with specialized strategy classes extending either TechnicalAnalysis or directly TraderionBot.
Entity-Relationship Diagram¶
erDiagram
TRADERION-BOT ||--o{ STRATEGY : "optionally uses"
STRATEGY ||--|{ TECHNICAL-ANALYSIS : extends
STRATEGY ||--|{ CLIENTS : extends
STRATEGY ||--|{ COVER : extends
TECHNICAL-ANALYSIS ||--|{ EMA : extends
TECHNICAL-ANALYSIS ||--|{ MACD : extends
TECHNICAL-ANALYSIS ||--|{ RSI : extends
TRADERION-BOT {
int loop_sleep
Queue event_queue
TraderionClient api
Dashboard dashboard
}
STRATEGY {
int target_amount
TraderionClient api
}
TECHNICAL-ANALYSIS {
list price_curve
list depth
}
This diagram illustrates how different components relate to each other. The TraderionBot can optionally use multiple strategies, which can be either technical analysis-based or specialized implementations like client interaction or position covering. Strategies are modular components that help organize trading logic, but they are not required - you can implement trading logic directly in your bot class.
Dashboard System¶
The Traderion framework includes a centralized dashboard system that provides real-time monitoring and visualization of trading activities. Key features include:
- Real-time Data Updates: Position, market prices, and status are updated in real-time
- Event Logging: Comprehensive logging of market events, bot events, and performance metrics
- Custom Panels: Each bot type can define custom panels for strategy-specific data display
- Historical Context: Maintains history of events and metrics for analysis
- Error Handling: Graceful error recovery with detailed error logging and status updates
- Extensibility: Easy addition of new panels and data types
- Thread Safety: Thread-safe data management for consistent updates
Component Details¶
The Traderion framework is built upon a few key components:
- TraderionBot: The base class for creating custom trading bots. It provides an event-driven architecture, thread management, a main loop for custom logic, and integration with the
TraderionClient. - TraderionClient: The API interface for interacting with the trading system. It handles authentication, session management, market data polling, trade execution, and event callbacks.
- Strategy: The foundation for implementing trading strategies. Strategies can be used to encapsulate trading logic, and can include event handlers for market changes, main execution logic, logging capabilities, and API integration.
TraderionBot Example¶
class MyBot(TraderionBot):
def __init__(self, username, password, room_id):
super().__init__(username, password, room_id)
def on_market_price_change(self, old_prices, new_prices):
# React to price changes
print(f"Price changed from {old_prices} to {new_prices}")
TraderionClient Example¶
# Get market prices
prices = client.get_market_prices()
# Place an order
client.add_order(direction, amount, price)
Base Strategy Example¶
class MyStrategy(Base):
def __init__(self, api, options):
super().__init__(api, options)
def run(self):
# Implement trading logic
pass
Execution Flow¶
With Strategies (Optional)¶
sequenceDiagram
autonumber
Market->>+TraderionClient: Market Update
TraderionClient->>+TraderionBot: Event Notification
TraderionBot->>+Strategy: Callback Execution
Strategy->>TraderionClient: Trade Execution
TraderionClient->>Market: Trade Request
Note right of Strategy: Strategy analyzes market data
Strategy-->>TraderionBot: Trade Decision
TraderionBot-->>TraderionClient: Execute Trade
TraderionBot->>Dashboard: Update Data
Dashboard-->>User: Display Updates
Direct Implementation (Without Strategies)¶
sequenceDiagram
autonumber
Market->>+TraderionClient: Market Update
TraderionClient->>+TraderionBot: Event Notification
Note right of TraderionBot: Bot analyzes market data directly
TraderionBot->>TraderionClient: Trade Execution
TraderionClient->>Market: Trade Request
These sequence diagrams demonstrate the flow of events during execution. Market updates trigger callbacks that lead to trade decisions and executions. You can either use strategies as modular components or implement trading logic directly in your bot class.