Skip to main content

LighterHttpClient

Struct LighterHttpClient 

Source
pub struct LighterHttpClient { /* private fields */ }
Expand description

Domain HTTP client for Lighter REST operations.

This client wraps LighterRawHttpClient and converts selected endpoint responses into Nautilus domain data. Market metadata calls also populate the shared MarketRegistry.

Implementations§

Source§

impl LighterHttpClient

Source

pub fn new( environment: LighterEnvironment, base_url: Option<String>, timeout_secs: u64, proxy_url: Option<String>, ) -> LighterHttpResult<Self>

Creates a new LighterHttpClient.

§Errors

Returns an error if the underlying raw HTTP client cannot be created.

Source

pub fn from_raw(raw_client: LighterRawHttpClient) -> Self

Wraps an existing raw HTTP client.

Source

pub fn from_raw_with_registry( raw_client: LighterRawHttpClient, market_registry: Arc<MarketRegistry>, ) -> Self

Wraps an existing raw HTTP client and shared market registry.

Source

pub fn base_url(&self) -> &str

Returns the configured REST base URL.

Source

pub fn environment(&self) -> LighterEnvironment

Returns the configured Lighter environment.

Source

pub fn market_registry(&self) -> Arc<MarketRegistry>

Returns the shared market registry used by this client.

Source

pub fn set_base_url(&mut self, base_url: &str)

Overrides the REST base URL. Intended for mock-server tests.

§Panics

Panics if the raw client is shared by another Arc.

Source

pub async fn get_order_books( &self, query: &LighterOrderBooksQuery, ) -> LighterHttpResult<LighterOrderBooks>

Calls GET /api/v1/orderBooks and registers returned markets.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_order_book_details( &self, query: &LighterOrderBookDetailsQuery, ) -> LighterHttpResult<LighterOrderBookDetails>

Calls GET /api/v1/orderBookDetails and registers returned markets.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_order_book_orders( &self, query: &LighterOrderBookOrdersQuery, ) -> LighterHttpResult<LighterOrderBookOrders>

Calls GET /api/v1/orderBookOrders.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_recent_trades( &self, query: &LighterRecentTradesQuery, ) -> LighterHttpResult<LighterTrades>

Calls GET /api/v1/recentTrades.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_trades( &self, query: &LighterTradesQuery, ) -> LighterHttpResult<LighterTrades>

Calls GET /api/v1/trades.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_candles( &self, query: &LighterCandlesQuery, ) -> LighterHttpResult<LighterCandles>

Calls GET /api/v1/candles.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_fundings( &self, query: &LighterFundingsQuery, ) -> LighterHttpResult<LighterFundings>

Calls GET /api/v1/fundings.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_account_detail( &self, account_index: i64, ) -> LighterHttpResult<LighterAccountDetail>

Fetches the account row for account_index via GET /api/v1/account.

§Errors

Returns an error if the request fails, the response is invalid, or the venue returns no account for the index.

Source

pub async fn get_account_active_orders( &self, query: &LighterAccountActiveOrdersQuery, ) -> LighterHttpResult<LighterOrders>

Calls GET /api/v1/accountActiveOrders.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_account_inactive_orders( &self, query: &LighterAccountInactiveOrdersQuery, ) -> LighterHttpResult<LighterOrders>

Calls GET /api/v1/accountInactiveOrders.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_next_nonce( &self, account_index: i64, api_key_index: u8, ) -> LighterHttpResult<LighterNextNonce>

Calls GET /api/v1/nextNonce for (account_index, api_key_index).

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn get_maker_only_api_keys( &self, account_index: i64, auth_token: impl Into<String>, ) -> LighterHttpResult<LighterMakerOnlyApiKeys>

Calls GET /api/v1/getMakerOnlyApiKeys for account_index.

auth_token is the canonical Lighter auth string minted from the caller’s credential.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn send_tx( &self, request: &LighterSendTxRequest, ) -> LighterHttpResult<LighterSendTxResponse>

Calls POST /api/v1/sendTx.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn send_tx_batch( &self, request: &LighterSendTxBatchRequest, ) -> LighterHttpResult<LighterSendTxBatchResponse>

Calls POST /api/v1/sendTxBatch.

§Errors

Returns an error if the request fails or the response is invalid.

Source

pub async fn request_recent_trades( &self, instrument: &InstrumentAny, limit: u16, ) -> LighterHttpResult<Vec<TradeTick>>

Requests recent trades for an instrument and parses them into [TradeTick]s.

§Errors

Returns an error if the instrument has not been registered, the request fails, or a trade cannot be parsed.

Source

pub async fn request_trades( &self, instrument: &InstrumentAny, query: LighterTradesQuery, ) -> LighterHttpResult<Vec<TradeTick>>

Requests historical trades and parses them into [TradeTick]s.

If query.market_id is None, the value is resolved from the shared market registry.

§Errors

Returns an error if the instrument has not been registered, the request fails, or a trade cannot be parsed.

Source

pub async fn request_bars( &self, instrument: &InstrumentAny, bar_type: BarType, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<u32>, ) -> LighterHttpResult<Vec<Bar>>

Requests historical candles and parses them into Nautilus [Bar]s.

§Errors

Returns an error if the instrument has not been registered, the bar type is unsupported, the request fails, or a candle cannot be parsed.

Source

pub async fn request_funding_rates( &self, instrument: &InstrumentAny, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<usize>, ) -> LighterHttpResult<Vec<FundingRateUpdate>>

Requests historical funding rates and parses them into Nautilus updates.

Lighter’s public /api/v1/fundings endpoint returns settled funding rows at hourly or daily resolution. The adapter requests hourly rows and returns them in chronological order.

§Errors

Returns an error if the instrument is not a perpetual, the instrument has not been registered, the request range is invalid, or a row cannot be parsed.

Source

pub async fn request_instruments(&self) -> LighterHttpResult<Vec<InstrumentAny>>

Requests all instruments from Lighter order book metadata.

Lighter exposes market definitions through GET /api/v1/orderBookDetails.

§Errors

Returns an error if the request fails or an instrument cannot be parsed.

Source

pub async fn request_instruments_with_status( &self, ) -> LighterHttpResult<Vec<(InstrumentAny, LighterMarketStatus)>>

Requests all instruments and their market statuses from Lighter order book metadata.

§Errors

Returns an error if the request fails or an instrument cannot be parsed.

Source

pub async fn request_instrument( &self, instrument_id: InstrumentId, ) -> LighterHttpResult<InstrumentAny>

Requests a single instrument from Lighter order book metadata.

§Errors

Returns an error if the request fails, the instrument is not found, or the instrument cannot be parsed.

Source

pub async fn request_instrument_with_status( &self, instrument_id: InstrumentId, ) -> LighterHttpResult<(InstrumentAny, LighterMarketStatus)>

Requests a single instrument and its market status from Lighter order book metadata.

§Errors

Returns an error if the request fails, the instrument is not found, or the instrument cannot be parsed.

Source

pub async fn request_order_book_snapshot( &self, instrument: &InstrumentAny, limit: u16, ) -> LighterHttpResult<OrderBookDeltas>

Requests an HTTP order book snapshot and parses it into Nautilus order book deltas.

§Errors

Returns an error if the instrument has not been registered, the request fails, or any level cannot be parsed.

Trait Implementations§

Source§

impl Clone for LighterHttpClient

Source§

fn clone(&self) -> LighterHttpClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LighterHttpClient

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for LighterHttpClient

Source§

fn default() -> Self

Returns the “default value” for a type. 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
§

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

§

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

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
§

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
§

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

impl<T> Ungil for T
where T: Send,

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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