pub struct Session { /* private fields */ }Expand description
One connection to one network’s websocket.
Implementations§
Source§impl Session
impl Session
Sourcepub fn tick(&mut self, now: u64) -> Tick
pub fn tick(&mut self, now: u64) -> Tick
What the socket needs at now: a ping every Timing::ping_after_ms, busy or not, or a
reconnect after Timing::silent_ms of nothing at all.
Sourcepub fn closed(&mut self, now: u64, random: u64) -> Retry
pub fn closed(&mut self, now: u64, random: u64) -> Retry
The socket closed at now, or a connect failed. Gives how long to wait before the next
connect, and the transactions left unanswered. The wait doubles from
Timing::first_retry_ms to Timing::last_retry_ms and random adds up to a quarter
more, so many clients dropped at once do not return at once. It starts over after a
socket that held (Timing::steady_ms). There is no last attempt.
Source§impl Session
impl Session
Sourcepub fn new(network: Network) -> Self
pub fn new(network: Network) -> Self
A closed session on network’s socket, with the venue’s limits and the default timing.
Sourcepub const fn read_only(self) -> Self
pub const fn read_only(self) -> Self
On the read-only socket (?readonly=true), which serves every channel, private ones with
their token included, from restricted regions too, and takes no transactions.
Sourcepub const fn with_limits(self, limits: Limits) -> Self
pub const fn with_limits(self, limits: Limits) -> Self
A connection’s share of the limits; sessions sharing an IP split its accounts.
pub const fn with_timing(self, timing: Timing) -> Self
Sourcepub fn with_auth(self, token: impl Into<String>) -> Self
pub fn with_auth(self, token: impl Into<String>) -> Self
With the account’s auth token (crate::Client::auth_token) for the channels that take
it. A token reads one account and lapses (eight hours at most): set a fresh one before it
does with Session::set_auth.
Sourcepub fn set_auth(&mut self, token: Option<String>)
pub fn set_auth(&mut self, token: Option<String>)
A fresh token, or none. The venue reads a token when a channel is subscribed: what is already subscribed goes on, and the new one goes out with the next subscribe, resubscribe or reconnect.
pub const fn network(&self) -> Network
pub const fn is_read_only(&self) -> bool
Sourcepub const fn url(&self) -> &'static str
pub const fn url(&self) -> &'static str
Where to connect: the network’s socket, or its read-only one.
pub const fn is_open(&self) -> bool
Sourcepub fn wanted(&self) -> &[Subscription]
pub fn wanted(&self) -> &[Subscription]
What this session subscribes to on every socket, in the order it was asked for.
Sourcepub fn waiting(&self) -> &[u64]
pub fn waiting(&self) -> &[u64]
The ids of transactions sent on this socket and not yet answered.
Sourcepub fn subscribe(
&mut self,
subscription: Subscription,
) -> Result<Option<String>, Refused>
pub fn subscribe( &mut self, subscription: Subscription, ) -> Result<Option<String>, Refused>
Wants subscription from now on, on this socket and every later one. Gives the frame to
send when the socket is open and it is new; nothing when it was already wanted (the venue
refuses a second subscribe). Past the limits, without the token it needs, or on a network
that does not serve it, it is refused and not kept.
Sourcepub fn unsubscribe(&mut self, subscription: &Subscription) -> Option<String>
pub fn unsubscribe(&mut self, subscription: &Subscription) -> Option<String>
Stops wanting subscription. Gives the frame to send when the socket is open and it was
wanted.
Sourcepub fn resubscribe(&mut self, subscription: &Subscription) -> Vec<String>
pub fn resubscribe(&mut self, subscription: &Subscription) -> Vec<String>
An unsubscribe and a subscribe for a fresh snapshot of what is wanted, on an open socket; nothing otherwise. A second subscribe alone the venue refuses.
Sourcepub fn send_tx(&mut self, signed: &Signed) -> Result<(u64, String), Refused>
pub fn send_tx(&mut self, signed: &Signed) -> Result<(u64, String), Refused>
A signed transaction’s frame (jsonapi/sendtx) and the id its answer will name. Only on
an open socket that is not read-only, and only while fewer than the limit wait for an
answer. One with the owner’s signature: Session::send_tx_info with
Signed::tx_info_with_l1.
Sourcepub fn send_tx_info(
&mut self,
tx_type: u8,
tx_info: &str,
) -> Result<(u64, String), Refused>
pub fn send_tx_info( &mut self, tx_type: u8, tx_info: &str, ) -> Result<(u64, String), Refused>
Session::send_tx for a type and tx_info as signed.
Sourcepub fn send_tx_batch(
&mut self,
signed: &[Signed],
) -> Result<(u64, String), Refused>
pub fn send_tx_batch( &mut self, signed: &[Signed], ) -> Result<(u64, String), Refused>
Up to fifty signed transactions as one batch (jsonapi/sendtxbatch): one account and API
key, consecutive nonces. None may need the owner’s signature.
Sourcepub fn send_tx_batch_infos(
&mut self,
txs: &[(u8, String)],
) -> Result<(u64, String), Refused>
pub fn send_tx_batch_infos( &mut self, txs: &[(u8, String)], ) -> Result<(u64, String), Refused>
Session::send_tx_batch for types and tx_infos as signed.
Sourcepub fn opened(&mut self, now: u64) -> Vec<String>
pub fn opened(&mut self, now: u64) -> Vec<String>
The socket opened at now. Gives the frames that subscribe to everything wanted, in
order. Each book’s chain starts again from its snapshot.
Sourcepub fn received(&mut self, now: u64, text: &str) -> Result<Frame, BadFrame>
pub fn received(&mut self, now: u64, text: &str) -> Result<Frame, BadFrame>
A text frame arrived at now. Anything that arrives shows the socket is alive, whether it
reads or not. A transaction’s answer or refusal stops it waiting; a ping is owed a pong;
an order book update that does not follow its book comes back as Frame::Gap, and the
resubscribe that brings a fresh snapshot is owed (Session::owed).