lamarge 0.8.0

Client for the LaMarge API: sign-in, takes, transfers, withdrawals and market making, each request checked before it is signed.
Documentation
//! Fill reads: current fills and fill history.

use futures_core::Stream;
use serde::{Deserialize, Serialize};

use super::{
    Fills, PageRequest,
    page::{every, history},
};
use crate::{
    Result,
    model::{Fill, FillHistoryRow, Page},
    transport::{Call, ops},
    types::FillId,
};

#[derive(Serialize)]
struct DeliveryBody<'a> {
    tx_hash: &'a str,
}

#[derive(Deserialize)]
struct Delivered {
    fill: Fill,
}

impl Fills<'_> {
    /// Nonfinal fills plus the latest 50 final ones, newest first: a session's taker and maker
    /// fills, or a quoter identity's maker fills. Over 1000 the server answers
    /// `SNAPSHOT_TOO_LARGE`: page with [`history`](Self::history).
    pub async fn list(&self) -> Result<Vec<Fill>> {
        self.inner.send(Call::new(&ops::GET_FILLS), self.auth).await
    }

    /// Accepts responsibility for a requested delivery inside a venue before the taker pays.
    /// Repeats succeed.
    pub async fn accept(&self, id: FillId) -> Result<()> {
        self.inner.send(Call::new(&ops::ACCEPT_FILL).segment(id), self.auth).await
    }

    /// Reports the venue transaction delivering fill `id` (a Lighter transaction hash, an Aster
    /// transfer id); LaMarge verifies it on the venue before paying the maker. An exact repeat
    /// answers the fill again; `DELIVERY_PENDING` while the venue does not show it final yet.
    pub async fn deliver(&self, id: FillId, tx_hash: &str) -> Result<Fill> {
        let call = Call::new(&ops::SUBMIT_DELIVERY).segment(id).json(&DeliveryBody { tx_hash })?;
        let delivered: Delivered = self.inner.send(call, self.auth).await?;
        Ok(delivered.fill)
    }

    /// One page of fill history, newest first.
    pub async fn history(&self, page: &PageRequest) -> Result<Page<FillHistoryRow>> {
        history(self.inner, self.auth, &ops::GET_FILL_HISTORY, page).await
    }

    /// Every fill, newest first, reading pages of `page_size` (clamped to `1..=500`) as
    /// consumed. The stream owns what it needs, so it outlives the handle.
    pub fn history_stream(
        &self,
        page_size: u16,
    ) -> impl Stream<Item = Result<FillHistoryRow>> + Send + Unpin + 'static {
        every(self.inner, self.auth, PageRequest::first(page_size), || {
            Call::new(&ops::GET_FILL_HISTORY)
        })
    }
}

#[cfg(test)]
mod tests;