pub struct LiveTradingEngine {Show 16 fields
pub positions: HashMap<String, Position>,
pub emergency_stop: Arc<AtomicBool>,
pub account_balance: f64,
pub retry_policy: RetryPolicy,
pub pending_retries: HashMap<String, OrderRetryState>,
pub retry_task: Option<JoinHandle<()>>,
pub alert_sender: Option<Sender<AlertMessage>>,
pub alert_receiver: Option<Receiver<AlertMessage>>,
pub alert_task: Option<JoinHandle<()>>,
pub safety_circuit_breaker_config: SafetyCircuitBreakerConfig,
pub consecutive_failed_orders: u32,
pub order_result_history: VecDeque<bool>,
pub highest_account_value: f64,
pub monitoring_task: Option<JoinHandle<()>>,
pub detailed_logging: bool,
pub monitoring_manager: Option<MonitoringManager>,
/* private fields */
}
Expand description
Live trading engine for executing trades on Hyperliquid exchange
Fields§
§positions: HashMap<String, Position>
Current positions
emergency_stop: Arc<AtomicBool>
Emergency stop flag
account_balance: f64
Account balance
retry_policy: RetryPolicy
Order retry policy
pending_retries: HashMap<String, OrderRetryState>
Orders pending retry
retry_task: Option<JoinHandle<()>>
Retry task
alert_sender: Option<Sender<AlertMessage>>
Alert channel sender
alert_receiver: Option<Receiver<AlertMessage>>
Alert channel receiver
alert_task: Option<JoinHandle<()>>
Alert processing task
safety_circuit_breaker_config: SafetyCircuitBreakerConfig
Safety circuit breaker configuration
consecutive_failed_orders: u32
Consecutive failed orders count
order_result_history: VecDeque<bool>
Recent order success/failure history
highest_account_value: f64
Highest account value for drawdown calculation
monitoring_task: Option<JoinHandle<()>>
Monitoring task
detailed_logging: bool
Detailed logging enabled flag
monitoring_manager: Option<MonitoringManager>
Monitoring manager
Implementations§
Source§impl LiveTradingEngine
Integration with LiveTradingEngine
impl LiveTradingEngine
Integration with LiveTradingEngine
Sourcepub fn init_real_time_monitoring(
&mut self,
port: Option<u16>,
) -> Result<(), MonitoringError>
pub fn init_real_time_monitoring( &mut self, port: Option<u16>, ) -> Result<(), MonitoringError>
Initialize real-time monitoring
Sourcepub fn send_monitoring_alert(
&mut self,
level: AlertLevel,
message: &str,
symbol: Option<&str>,
order_id: Option<&str>,
) -> Result<(), MonitoringError>
pub fn send_monitoring_alert( &mut self, level: AlertLevel, message: &str, symbol: Option<&str>, order_id: Option<&str>, ) -> Result<(), MonitoringError>
Send monitoring alert
Sourcepub fn record_trade_execution(
&mut self,
order_request: &OrderRequest,
order_result: &OrderResult,
execution_latency_ms: u64,
) -> Result<(), MonitoringError>
pub fn record_trade_execution( &mut self, order_request: &OrderRequest, order_result: &OrderResult, execution_latency_ms: u64, ) -> Result<(), MonitoringError>
Record trade execution for monitoring
Sourcepub fn update_performance_metrics(&mut self) -> Result<(), MonitoringError>
pub fn update_performance_metrics(&mut self) -> Result<(), MonitoringError>
Update performance metrics for monitoring
Sourcepub fn update_connection_metrics(
&mut self,
uptime_pct: f64,
disconnection_count: usize,
avg_reconnection_time_ms: f64,
api_latency_ms: f64,
ws_latency_ms: f64,
) -> Result<(), MonitoringError>
pub fn update_connection_metrics( &mut self, uptime_pct: f64, disconnection_count: usize, avg_reconnection_time_ms: f64, api_latency_ms: f64, ws_latency_ms: f64, ) -> Result<(), MonitoringError>
Update connection metrics for monitoring
Sourcepub fn update_monitoring_dashboard(&mut self) -> Result<(), MonitoringError>
pub fn update_monitoring_dashboard(&mut self) -> Result<(), MonitoringError>
Update monitoring dashboard
Source§impl LiveTradingEngine
impl LiveTradingEngine
Sourcepub async fn new(
wallet: LocalWallet,
risk_config: RiskConfig,
api_config: ApiConfig,
) -> Result<Self, LiveTradingError>
pub async fn new( wallet: LocalWallet, risk_config: RiskConfig, api_config: ApiConfig, ) -> Result<Self, LiveTradingError>
Create a new live trading engine with the specified wallet and risk configuration
Sourcepub async fn connect(&mut self) -> Result<(), LiveTradingError>
pub async fn connect(&mut self) -> Result<(), LiveTradingError>
Connect to the exchange
Sourcepub async fn disconnect(&mut self) -> Result<(), LiveTradingError>
pub async fn disconnect(&mut self) -> Result<(), LiveTradingError>
Disconnect from the exchange
Sourcepub async fn execute_order(
&mut self,
order: OrderRequest,
) -> Result<OrderResult, LiveTradingError>
pub async fn execute_order( &mut self, order: OrderRequest, ) -> Result<OrderResult, LiveTradingError>
Execute an order with safety mechanisms
Sourcepub async fn cancel_order(
&mut self,
order_id: &str,
) -> Result<OrderResult, LiveTradingError>
pub async fn cancel_order( &mut self, order_id: &str, ) -> Result<OrderResult, LiveTradingError>
Cancel an order
Sourcepub fn get_positions(&self) -> &HashMap<String, Position>
pub fn get_positions(&self) -> &HashMap<String, Position>
Get current positions
Sourcepub fn get_order_history(&self) -> &Vec<LiveOrder>
pub fn get_order_history(&self) -> &Vec<LiveOrder>
Get order history
Sourcepub fn get_active_orders(&self) -> &HashMap<String, LiveOrder>
pub fn get_active_orders(&self) -> &HashMap<String, LiveOrder>
Get active orders
Sourcepub fn get_account_balance(&self) -> f64
pub fn get_account_balance(&self) -> f64
Get account balance
Sourcepub fn get_portfolio_value(&self) -> f64
pub fn get_portfolio_value(&self) -> f64
Get portfolio value (balance + position values)
Sourcepub async fn emergency_stop(&mut self) -> Result<(), LiveTradingError>
pub async fn emergency_stop(&mut self) -> Result<(), LiveTradingError>
Activate emergency stop with immediate order cancellation
Sourcepub fn deactivate_emergency_stop(&self)
pub fn deactivate_emergency_stop(&self)
Deactivate emergency stop
Sourcepub fn is_emergency_stop_active(&self) -> bool
pub fn is_emergency_stop_active(&self) -> bool
Check if emergency stop is active
Sourcepub async fn start_trading(
&mut self,
strategy: Box<dyn TradingStrategy>,
) -> Result<(), LiveTradingError>
pub async fn start_trading( &mut self, strategy: Box<dyn TradingStrategy>, ) -> Result<(), LiveTradingError>
Start trading with the given strategy
Sourcepub fn stop_trading(&mut self)
pub fn stop_trading(&mut self)
Stop trading
Sourcepub fn active_orders_count(&self) -> usize
pub fn active_orders_count(&self) -> usize
Get active orders count
Sourcepub fn active_order_ids(&self) -> Vec<String>
pub fn active_order_ids(&self) -> Vec<String>
Get active order IDs
Sourcepub fn monitoring_manager(&mut self) -> Option<&mut MonitoringManager>
pub fn monitoring_manager(&mut self) -> Option<&mut MonitoringManager>
Get monitoring manager
Sourcepub async fn update_positions(&mut self) -> Result<(), LiveTradingError>
pub async fn update_positions(&mut self) -> Result<(), LiveTradingError>
Update positions from exchange
Sourcepub fn generate_account_summary(&self) -> AccountSummary
pub fn generate_account_summary(&self) -> AccountSummary
Generate account summary for monitoring
Sourcepub fn generate_position_summary(&self) -> PositionSummary
pub fn generate_position_summary(&self) -> PositionSummary
Generate position summary for monitoring
Sourcepub fn generate_order_summary(&self) -> OrderSummary
pub fn generate_order_summary(&self) -> OrderSummary
Generate order summary for monitoring
Sourcepub fn generate_risk_summary(&self) -> RiskSummary
pub fn generate_risk_summary(&self) -> RiskSummary
Generate risk summary for monitoring
Sourcepub fn generate_system_status(&self) -> SystemStatus
pub fn generate_system_status(&self) -> SystemStatus
Generate system status for monitoring
Sourcepub fn get_recent_alerts(&self, limit: usize) -> Vec<AlertEntry>
pub fn get_recent_alerts(&self, limit: usize) -> Vec<AlertEntry>
Get recent alerts for monitoring
Sourcepub fn generate_performance_snapshot(&self) -> PerformanceSnapshot
pub fn generate_performance_snapshot(&self) -> PerformanceSnapshot
Generate performance snapshot for monitoring
Sourcepub fn get_monitoring_manager(&mut self) -> &mut Option<MonitoringManager>
pub fn get_monitoring_manager(&mut self) -> &mut Option<MonitoringManager>
Get monitoring manager reference (accessor method)
Sourcepub fn get_emergency_stop(&self) -> Arc<AtomicBool>
pub fn get_emergency_stop(&self) -> Arc<AtomicBool>
Get emergency stop flag (accessor)
Source§impl LiveTradingEngine
impl LiveTradingEngine
Sourcepub async fn init_safety_mechanisms(&mut self) -> Result<(), LiveTradingError>
pub async fn init_safety_mechanisms(&mut self) -> Result<(), LiveTradingError>
Initialize safety mechanisms
Sourcepub fn send_alert(
&self,
level: AlertLevel,
message: &str,
symbol: Option<&str>,
order_id: Option<&str>,
)
pub fn send_alert( &self, level: AlertLevel, message: &str, symbol: Option<&str>, order_id: Option<&str>, )
Send an alert message
Sourcepub fn schedule_retry(
&mut self,
order_request: OrderRequest,
error: &str,
) -> Result<(), LiveTradingError>
pub fn schedule_retry( &mut self, order_request: OrderRequest, error: &str, ) -> Result<(), LiveTradingError>
Schedule an order for retry
Sourcepub async fn cancel_all_orders(&mut self) -> Result<(), LiveTradingError>
pub async fn cancel_all_orders(&mut self) -> Result<(), LiveTradingError>
Cancel all active orders
Sourcepub fn check_safety_circuit_breakers(&mut self) -> Result<(), LiveTradingError>
pub fn check_safety_circuit_breakers(&mut self) -> Result<(), LiveTradingError>
Check safety circuit breakers
Sourcepub fn update_order_result(&mut self, success: bool)
pub fn update_order_result(&mut self, success: bool)
Update order result history
Sourcepub fn log_order_details(
&self,
order_request: &OrderRequest,
order_result: &OrderResult,
)
pub fn log_order_details( &self, order_request: &OrderRequest, order_result: &OrderResult, )
Log detailed order information
Auto Trait Implementations§
impl Freeze for LiveTradingEngine
impl !RefUnwindSafe for LiveTradingEngine
impl Send for LiveTradingEngine
impl Sync for LiveTradingEngine
impl Unpin for LiveTradingEngine
impl !UnwindSafe for LiveTradingEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.