1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! 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;