pub struct BinanceWebSocketTrader { /* private fields */ }Expand description
High-performance WebSocket-only trading client for Binance
Provides ultra-low latency order execution using WebSocket API exclusively. Includes connection management, authentication, rate limiting, and comprehensive metrics.
Implementations§
Source§impl BinanceWebSocketTrader
impl BinanceWebSocketTrader
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if authenticated and ready for operations
Sourcepub const fn metrics(&self) -> &Arc<ConnectionMetrics>
pub const fn metrics(&self) -> &Arc<ConnectionMetrics>
Get connection metrics
Sourcepub fn get_connection_health(&self) -> ConnectionHealth
pub fn get_connection_health(&self) -> ConnectionHealth
Get detailed connection health information Returns a struct with current connection status, timing information, and metrics
Sourcepub fn new(
auth: Arc<BinanceAuth>,
position_manager: Arc<dyn PositionManager>,
) -> Self
pub fn new( auth: Arc<BinanceAuth>, position_manager: Arc<dyn PositionManager>, ) -> Self
Create a new WebSocket-only trading client
Sourcepub fn new_testnet(
auth: Arc<BinanceAuth>,
position_manager: Arc<dyn PositionManager>,
) -> Self
pub fn new_testnet( auth: Arc<BinanceAuth>, position_manager: Arc<dyn PositionManager>, ) -> Self
Create a new WebSocket-only trading client for testnet
Sourcepub async fn connect(&self, report_tx: Sender<ExecutionReport>) -> Result<()>
pub async fn connect(&self, report_tx: Sender<ExecutionReport>) -> Result<()>
Connect to Binance WebSocket API
Sourcepub async fn handle_account_update(
json: &JsonValue,
position_manager: &Arc<dyn PositionManager>,
)
pub async fn handle_account_update( json: &JsonValue, position_manager: &Arc<dyn PositionManager>, )
Handle account update events from user data stream
Sourcepub fn parse_position_update(
position_json: &JsonValue,
event_time: u64,
_transaction_time: u64,
) -> Option<PositionUpdate>
pub fn parse_position_update( position_json: &JsonValue, event_time: u64, _transaction_time: u64, ) -> Option<PositionUpdate>
Parse position update from ACCOUNT_UPDATE event
Sourcepub async fn place_batch_orders(
&self,
orders: Vec<Order>,
report_tx: Sender<ExecutionReport>,
) -> Result<()>
pub async fn place_batch_orders( &self, orders: Vec<Order>, report_tx: Sender<ExecutionReport>, ) -> Result<()>
Place batch orders via WebSocket API (up to 50 orders)
This method ensures rate limiting compliance (300 orders/10 seconds) and uses concurrent execution for optimal performance.
Returns Ok(()) if all orders succeed, or an error with details about failed orders
Sourcepub async fn place_order(
&self,
order: Order,
report_tx: Sender<ExecutionReport>,
) -> Result<()>
pub async fn place_order( &self, order: Order, report_tx: Sender<ExecutionReport>, ) -> Result<()>
Place order via WebSocket API
Sourcepub fn get_rate_limit_status(&self) -> (usize, usize)
pub fn get_rate_limit_status(&self) -> (usize, usize)
Get current rate limit status
Sourcepub async fn cancel_order(
&self,
order_id: SmartString,
report_tx: Sender<ExecutionReport>,
) -> Result<()>
pub async fn cancel_order( &self, order_id: SmartString, report_tx: Sender<ExecutionReport>, ) -> Result<()>
Cancel order via WebSocket API
Sourcepub async fn modify_order(
&self,
params: ModifyOrderParams,
report_tx: Sender<ExecutionReport>,
) -> Result<()>
pub async fn modify_order( &self, params: ModifyOrderParams, report_tx: Sender<ExecutionReport>, ) -> Result<()>
Modify order via WebSocket API (cancel and replace)
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected
Sourcepub async fn reconnect(&self, report_tx: Sender<ExecutionReport>) -> Result<()>
pub async fn reconnect(&self, report_tx: Sender<ExecutionReport>) -> Result<()>
Attempt to reconnect WebSocket (can be called by external monitoring tasks) Note: This will start a new auto-reconnection monitor, so use sparingly
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Gracefully disconnect from WebSocket