lamarge 0.6.0

Client for the LaMarge API: sign-in, takes, transfers, withdrawals and market making, each request checked before it is signed.
Documentation
//! Event journal reads: snapshots, replay pages and the live subscription.

use std::sync::Arc;

use super::{Events, PublicEvents, page::limit_query};
use crate::{
    Result,
    events::EventStream,
    model::{EventPage, PrivateSnapshot, PublicSnapshot},
    transport::{Call, ops},
    types::Cursor,
};

impl PublicEvents<'_> {
    /// The public books at a journal cursor (`GET /v1/snapshot`).
    pub async fn snapshot(&self) -> Result<PublicSnapshot> {
        self.inner.send(Call::new(&ops::GET_SNAPSHOT), None).await
    }

    /// The public events after `after`, at most `limit` (1 to 500; server default 100)
    /// (`GET /v1/events`).
    pub async fn page(&self, after: Cursor, limit: Option<u16>) -> Result<EventPage> {
        let call = limit_query(Call::new(&ops::GET_EVENTS).query("after", after), limit);
        self.inner.send(call, None).await
    }

    /// The public journal as a live [`EventStream`]. Lazy: nothing is sent before the first
    /// poll. The stream owns what it needs, so it outlives the handle.
    pub fn subscribe(&self) -> EventStream {
        EventStream::new(Arc::clone(self.inner), None)
    }
}

impl Events<'_> {
    /// The reader's orders, fills and quote identities at a journal cursor
    /// (`GET /v1/me/snapshot`).
    pub async fn snapshot(&self) -> Result<PrivateSnapshot> {
        self.inner.send(Call::new(&ops::GET_MY_SNAPSHOT), self.auth).await
    }

    /// The reader's events after `after`, at most `limit` (1 to 500; server default 100)
    /// (`GET /v1/me/events`).
    pub async fn page(&self, after: Cursor, limit: Option<u16>) -> Result<EventPage> {
        let call = limit_query(Call::new(&ops::GET_MY_EVENTS).query("after", after), limit);
        self.inner.send(call, self.auth).await
    }

    /// The reader's journal as a live [`EventStream`]. Lazy: nothing is sent before the first
    /// poll. The stream owns what it needs, so it outlives the handle; it follows renewals of a
    /// session's token and ends on sign-out.
    pub fn subscribe(&self) -> EventStream {
        EventStream::new(Arc::clone(self.inner), self.auth.cloned())
    }
}

#[cfg(test)]
mod tests;