pub struct WebSocketClient<T: Handler> {
pub server: DataServer,
pub auth_token: Arc<RwLock<Ustr>>,
/* private fields */
}Expand description
The primary WebSocket client for TradingView real-time data.
Connects to a TradingView data server, authenticates with the provided token, and streams chart data, quotes, and study results via the handler trait.
§Architecture
The client uses a channel-based write path (no lock contention on sends) and a dedicated reader task that dispatches parsed messages to the handler.
§Example
let ws = WebSocketClient::builder()
.auth_token("your_token")
.server(DataServer::ProData)
.handler(my_handler)
.build()
.await?;Fields§
§server: DataServer§auth_token: Arc<RwLock<Ustr>>Implementations§
Source§impl<T: Handler> WebSocketClient<T>
impl<T: Handler> WebSocketClient<T>
pub fn spawn_reader_task(self: Arc<Self>)
pub fn is_closed(&self) -> bool
pub async fn reconnect(&self) -> Result<()>
pub async fn send_raw_message(&self, message: &str) -> Result<()>
pub async fn send(&self, m: &str, p: &[Value]) -> Result<()>
pub async fn ping(&self, ping: &Message) -> Result<()>
pub async fn close(&self) -> Result<()>
pub async fn fast_symbols( &self, quote_session: &str, symbols: &[&str], ) -> Result<()>
pub async fn create_quote_session(&self, quote_session: &str) -> Result<()>
pub async fn delete_quote_session(&self, quote_session: &str) -> Result<()>
pub async fn set_fields(&self, quote_session: &str) -> Result<()>
pub async fn add_symbols( &self, quote_session: &str, symbols: &[&str], ) -> Result<()>
pub async fn remove_symbols( &self, quote_session: &str, symbols: &[&str], ) -> Result<()>
pub async fn set_auth_token(&self, auth_token: &str) -> Result<()>
Sourcepub async fn set_locale(&self, language_code: &str, country: &str) -> Result<()>
pub async fn set_locale(&self, language_code: &str, country: &str) -> Result<()>
Example: locale = (“en”, “US”)
pub async fn set_data_quality(&self, data_quality: &str) -> Result<()>
pub async fn set_timezone( &self, chart_session: &str, timezone: Timezone, ) -> Result<()>
pub async fn create_chart_session(&self, session: &str) -> Result<()>
pub async fn remove_series( &self, chart_session: &str, series_identifier: &str, ) -> Result<()>
pub async fn delete_chart_session(&self, session: &str) -> Result<()>
pub async fn request_more_data( &self, chart_session: &str, series_id: &str, num: u64, ) -> Result<()>
pub async fn request_more_tickmarks( &self, chart_session: &str, series_id: &str, num: u64, ) -> Result<()>
pub async fn create_replay_session(&self, replay_session: &str) -> Result<()>
pub async fn delete_replay_session(&self, replay_session: &str) -> Result<()>
pub async fn replay_step( &self, replay_session: &str, request_id: &str, step: u64, ) -> Result<()>
pub async fn replay_start( &self, replay_session: &str, request_id: &str, interval: u64, ) -> Result<()>
pub async fn replay_stop( &self, replay_session: &str, request_id: &str, ) -> Result<()>
pub async fn replay_reset( &self, replay_session: &str, request_id: &str, timestamp: i64, ) -> Result<()>
pub async fn remove_study( &self, chart_session: &str, study_id: &str, ) -> Result<()>
pub async fn delete(&self) -> Result<()>
pub async fn subscribe(&self) -> Result<()>
pub async fn closed_notifier(&self)
Sourcepub async fn try_ping(&self) -> Result<()>
pub async fn try_ping(&self) -> Result<()>
Fire-and-forget ping. Ignores WouldBlock when write buffer is full.
pub async fn get_connection_stats(&self) -> Value
pub fn builder<'f1>() -> WebSocketClientBuilder<'f1, T>
Sourcepub fn create_series<'f1, 'f2, 'f3, 'f4, 'f5>(
&'f1 self,
) -> WebSocketClientCreateSeriesBuilder<'f1, 'f2, 'f3, 'f4, 'f5, T>
pub fn create_series<'f1, 'f2, 'f3, 'f4, 'f5>( &'f1 self, ) -> WebSocketClientCreateSeriesBuilder<'f1, 'f2, 'f3, 'f4, 'f5, T>
Create a chart data series.
§Protocol (corrected)
TradingView uses two mutually exclusive modes:
Count mode — 6 args, for live streaming and N-bar lookback:
["cs_xxx", "sds_1", "s1", "sds_sym_1", "1D", 300]
Range mode — 7 args, for historical date-range fetch:
["cs_xxx", "sds_1", "s1", "sds_sym_1", "1D", 0, "r,from_unix:to_unix"]
FIX: The old code always sent 7 args, passing an empty string
"" for the 7th in count mode. The server interprets 7 args as
range mode, fails on the empty range, and emits
critical_error: "unsupported method: du".
Sourcepub fn modify_series<'f1, 'f2, 'f3, 'f4, 'f5>(
&'f1 self,
) -> WebSocketClientModifySeriesBuilder<'f1, 'f2, 'f3, 'f4, 'f5, T>
pub fn modify_series<'f1, 'f2, 'f3, 'f4, 'f5>( &'f1 self, ) -> WebSocketClientModifySeriesBuilder<'f1, 'f2, 'f3, 'f4, 'f5, T>
Modify an existing chart series (e.g., change timeframe).
Same count/range mode distinction as Self::create_series.