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: DeribitHttpClientUpstream HTTP client used by every Read / Account / Trading
tool.
Implementations§
Source§impl AdapterContext
impl AdapterContext
Sourcepub fn new(config: Arc<Config>) -> Result<Self, AdapterError>
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.
Sourcepub fn has_credentials(&self) -> bool
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).
Sourcepub fn auth_state(&self) -> AuthState
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 lazy — Configured 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).
Sourcepub async fn websocket(&self) -> Result<&DeribitWebSocketClient, AdapterError>
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.
Sourcepub async fn ensure_fix(
&self,
) -> Result<Arc<Mutex<DeribitFixClient>>, AdapterError>
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
AdapterError::Validationwithfield = "order_transport"when the configuration does not select the FIX transport (OrderTransport::Http); callingensure_fixin that state is a programmer error.AdapterError::Authwith the upstream FIX rejection reason whenLogon (A)is rejected.AdapterError::UpstreamwithUpstreamErrorKind::Fixfor transport, session, config, and protocol errors.
Sourcepub async fn shutdown_fix(&self) -> Result<(), AdapterError>
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.