Skip to main content

AdapterContext

Struct AdapterContext 

Source
pub struct AdapterContext {
    pub config: Arc<Config>,
    pub http: DeribitHttpClient,
    /* private fields */
}
Expand description

Shared adapter context.

Cheap to clone via Arc; safe to share across tokio tasks. The upstream HTTP client is constructed eagerly so a misconfiguration surfaces at startup. The WebSocket client is lazy — most v0.1 tools are HTTP-only.

Debug is implemented manually below so the upstream DeribitFixClient (which does not derive Debug) doesn’t leak into the bound; the FIX field is rendered as a redacted <fix client> placeholder.

Fields§

§config: Arc<Config>

Resolved configuration. Frozen for the lifetime of the process.

§http: DeribitHttpClient

Upstream HTTP client used by every Read / Account / Trading tool.

Implementations§

Source§

impl AdapterContext

Source

pub fn new(config: Arc<Config>) -> Result<Self, AdapterError>

Build the adapter context from a resolved Config.

§Errors

Returns AdapterError::Validation when the configured Deribit endpoint is not a valid URL. The upstream HTTP client itself is infallible to construct.

Source

pub fn has_credentials(&self) -> bool

Whether the configuration carries both an OAuth client id and secret. The tool registry uses this to gate the Account and Trading families (ADR-0003 / ADR-0010).

Source

pub fn auth_state(&self) -> AuthState

Snapshot of the OAuth state. Drives registry decisions (whether Account / Trading tools register at all) and gives downstream callers a stable enum to match on instead of a free-form bool.

Auth is lazyConfigured does not imply that deribit-http has yet issued a public/auth call. The upstream AuthManager triggers OAuth on the first private endpoint hit and refreshes ~30 s before expires_in (handled inside deribit-http).

Source

pub async fn websocket(&self) -> Result<&DeribitWebSocketClient, AdapterError>

Lazily construct (or return) the WebSocket client.

§Errors

Returns AdapterError::Upstream (with UpstreamErrorKind::Websocket) when the upstream WebSocket crate refuses the configuration — typically a transport failure on the very first connect attempt.

Source

pub async fn ensure_fix( &self, ) -> Result<Arc<Mutex<DeribitFixClient>>, AdapterError>

Lazily construct, log on, and return a shared handle to the FIX 4.4 client.

First call drives DeribitFixClient::new + connect(), which performs the FIX Logon (A) and starts the heartbeat task. Subsequent calls return the same Arc<Mutex<…>> so callers reuse a single session across the process lifetime. SIGTERM should drive shutdown_fix so the session ends with a proper FIX Logout (5).

§Errors
Source

pub async fn shutdown_fix(&self) -> Result<(), AdapterError>

Issue a FIX Logout (5) and tear down the session, if one has been established. No-op when the FIX session was never opened. Called from the SIGTERM handler at process shutdown.

§Errors

Surfaces any AdapterError that the upstream disconnect call produces. Best-effort — callers should log the error rather than abort the shutdown.

Trait Implementations§

Source§

impl Debug for AdapterContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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<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: 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: 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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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