Skip to main content

WebSocketClient

Struct WebSocketClient 

Source
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>

Source

pub fn spawn_reader_task(self: Arc<Self>)

Source

pub fn is_closed(&self) -> bool

Source

pub async fn reconnect(&self) -> Result<()>

Source

pub async fn send_raw_message(&self, message: &str) -> Result<()>

Source

pub async fn send(&self, m: &str, p: &[Value]) -> Result<()>

Source

pub async fn ping(&self, ping: &Message) -> Result<()>

Source

pub async fn close(&self) -> Result<()>

Source

pub async fn fast_symbols( &self, quote_session: &str, symbols: &[&str], ) -> Result<()>

Source

pub async fn create_quote_session(&self, quote_session: &str) -> Result<()>

Source

pub async fn delete_quote_session(&self, quote_session: &str) -> Result<()>

Source

pub async fn set_fields(&self, quote_session: &str) -> Result<()>

Source

pub async fn add_symbols( &self, quote_session: &str, symbols: &[&str], ) -> Result<()>

Source

pub async fn remove_symbols( &self, quote_session: &str, symbols: &[&str], ) -> Result<()>

Source

pub async fn set_auth_token(&self, auth_token: &str) -> Result<()>

Source

pub async fn set_locale(&self, language_code: &str, country: &str) -> Result<()>

Example: locale = (“en”, “US”)

Source

pub async fn set_data_quality(&self, data_quality: &str) -> Result<()>

Source

pub async fn set_timezone( &self, chart_session: &str, timezone: Timezone, ) -> Result<()>

Source

pub async fn create_chart_session(&self, session: &str) -> Result<()>

Source

pub async fn remove_series( &self, chart_session: &str, series_identifier: &str, ) -> Result<()>

Source

pub async fn delete_chart_session(&self, session: &str) -> Result<()>

Source

pub async fn request_more_data( &self, chart_session: &str, series_id: &str, num: u64, ) -> Result<()>

Source

pub async fn request_more_tickmarks( &self, chart_session: &str, series_id: &str, num: u64, ) -> Result<()>

Source

pub async fn create_replay_session(&self, replay_session: &str) -> Result<()>

Source

pub async fn delete_replay_session(&self, replay_session: &str) -> Result<()>

Source

pub async fn replay_step( &self, replay_session: &str, request_id: &str, step: u64, ) -> Result<()>

Source

pub async fn replay_start( &self, replay_session: &str, request_id: &str, interval: u64, ) -> Result<()>

Source

pub async fn replay_stop( &self, replay_session: &str, request_id: &str, ) -> Result<()>

Source

pub async fn replay_reset( &self, replay_session: &str, request_id: &str, timestamp: i64, ) -> Result<()>

Source

pub async fn remove_study( &self, chart_session: &str, study_id: &str, ) -> Result<()>

Source

pub async fn delete(&self) -> Result<()>

Source

pub async fn subscribe(&self) -> Result<()>

Source

pub async fn closed_notifier(&self)

Source

pub async fn try_ping(&self) -> Result<()>

Fire-and-forget ping. Ignores WouldBlock when write buffer is full.

Source

pub async fn get_connection_stats(&self) -> Value

Source

pub fn builder<'f1>() -> WebSocketClientBuilder<'f1, T>

Source

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".

Source

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.

Source

pub fn resolve_symbol<'f1, 'f2, 'f3, 'f4, 'f5>( &'f1 self, ) -> WebSocketClientResolveSymbolBuilder<'f1, 'f2, 'f3, 'f4, 'f5, T>

Source

pub fn add_replay_series<'f1, 'f2, 'f3, 'f4>( &'f1 self, ) -> WebSocketClientAddReplaySeriesBuilder<'f1, 'f2, 'f3, 'f4, T>

Source

pub fn create_study<'f1, 'f2, 'f3, 'f4, 'f5>( &'f1 self, ) -> WebSocketClientCreateStudyBuilder<'f1, 'f2, 'f3, 'f4, 'f5, T>

Source

pub fn modify_study<'f1, 'f2, 'f3, 'f4>( &'f1 self, ) -> WebSocketClientModifyStudyBuilder<'f1, 'f2, 'f3, 'f4, T>

Trait Implementations§

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for WebSocketClient<T>

§

impl<T> !UnwindSafe for WebSocketClient<T>

§

impl<T> Freeze for WebSocketClient<T>
where T: Freeze,

§

impl<T> Send for WebSocketClient<T>

§

impl<T> Sync for WebSocketClient<T>

§

impl<T> Unpin for WebSocketClient<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for WebSocketClient<T>
where T: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more