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
//! Order reads, order history and per-order quote cancellation.

use futures_core::Stream;

use super::{
    Orders, PageRequest,
    page::{every, history},
};
use crate::{
    Result,
    model::{Order, OrderHistoryRow, Page, QuoteCancellation},
    transport::{Call, ops},
    types::{ClientId, OrderId},
};

impl Orders<'_> {
    /// Capital pools, open orders and orders holding funds, plus the latest 50 empty closed or
    /// failed ones, oldest first; a quoter sees its identity's only. With `client_order_id`, the
    /// one order it names, if any. Over 1000 the server answers `SNAPSHOT_TOO_LARGE`: page with
    /// [`history`](Self::history).
    pub async fn list(&self, client_order_id: Option<&ClientId>) -> Result<Vec<Order>> {
        let mut call = Call::new(&ops::GET_ORDERS);
        if let Some(id) = client_order_id {
            call = call.query("client_order_id", id);
        }
        self.inner.send(call, self.auth).await
    }

    /// One order.
    pub async fn get(&self, id: OrderId) -> Result<Order> {
        self.inner.send(Call::new(&ops::GET_ORDER).segment(id), self.auth).await
    }

    /// Removes the order from admission; advances its `cancel_epoch` on every call.
    pub async fn cancel_quotes(&self, id: OrderId) -> Result<QuoteCancellation> {
        self.inner.send(Call::new(&ops::DELETE_QUOTES).segment(id), self.auth).await
    }

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

    /// Every order, 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<OrderHistoryRow>> + Send + Unpin + 'static {
        every(self.inner, self.auth, PageRequest::first(page_size), || {
            Call::new(&ops::GET_ORDER_HISTORY)
        })
    }
}

#[cfg(test)]
mod tests;