Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub base_url: String,
    pub api_key: Option<SensitiveString>,
    pub api_secret: Option<SensitiveString>,
    pub recv_window: Timestamp,
    pub referer: Option<String>,
    pub rate_limiter: Option<RateLimiterConfig>,
    pub timeout: Option<Duration>,
    pub connect_timeout: Option<Duration>,
    pub proxy: Option<String>,
    pub resync_time_on_timestamp_error: bool,
}
Expand description

Configuration of a Client; start with Config::new or Config::for_env.

Fields§

§base_url: String

REST base URL, e.g. https://api.bybit.com.

§api_key: Option<SensitiveString>

API key for private endpoints (see Config::credentials).

§api_secret: Option<SensitiveString>

API secret for private endpoints (see Config::credentials).

§recv_window: Timestamp

Milliseconds.

§referer: Option<String>

HTTP the header for broker users only.

§rate_limiter: Option<RateLimiterConfig>

Optional rate limiter. When Some, every request is pre-flight-checked against a local token bucket and the last server-reported limit status. Set to None to disable rate limiting entirely.

§timeout: Option<Duration>

Total timeout of one request (connect + send + receive). None disables it, which is not recommended: a hung request would then wait forever.

§connect_timeout: Option<Duration>

Timeout of establishing a connection. None disables it.

§proxy: Option<String>

HTTP(S) proxy for REST requests, e.g. http://127.0.0.1:8080. None uses the system proxy settings (HTTP(S)_PROXY). WebSocket streams do not use it.

§resync_time_on_timestamp_error: bool

When Bybit rejects a signed request’s timestamp (retCode 10002), call Client::sync_time and send the request once more, signed with the server time. Safe: the rejected request was not executed. Enabled by default.

Implementations§

Source§

impl Config

Source

pub fn new(base_url: impl Into<String>) -> Self

Config for public endpoints with default timeouts and no rate limiter.

Source

pub fn for_env(env: Environment) -> Self

Config for the REST API of env, e.g. Config::for_env(Environment::Demo).

Source

pub fn credentials( self, api_key: impl Into<SensitiveString>, api_secret: impl Into<SensitiveString>, ) -> Self

Credentials required by private endpoints.

Source

pub fn recv_window(self, recv_window: Timestamp) -> Self

Milliseconds.

Source

pub fn referer(self, referer: impl Into<String>) -> Self

Broker referer header (X-Referer).

Source

pub fn rate_limiter(self, rate_limiter: RateLimiterConfig) -> Self

Enable the local rate limiter.

Source

pub fn timeout(self, timeout: Option<Duration>) -> Self

Total timeout of one request; None disables it.

Source

pub fn connect_timeout(self, connect_timeout: Option<Duration>) -> Self

Timeout of establishing a connection; None disables it.

Source

pub fn proxy(self, url: impl Into<String>) -> Self

HTTP(S) proxy for REST requests, e.g. http://127.0.0.1:8080.

Source

pub fn resync_time_on_timestamp_error(self, enabled: bool) -> Self

Re-synchronize the clock and retry once when Bybit rejects a request timestamp (retCode 10002). Enabled by default.

Auto Trait Implementations§

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