use crate::{Currency, Request};
use serde::{Deserialize, Serialize};
#[derive(Default, Debug, Clone, Serialize)]
pub struct SubscribeRequest {
#[serde(skip_serializing_if = "Option::is_none")]
streams: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
accounts: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
accounts_proposed: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
books: Option<Vec<Book>>,
#[serde(skip_serializing_if = "Option::is_none")]
url: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
url_username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
url_password: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
pub struct Book {
pub taker_gets: Currency,
pub taker_pays: Currency,
#[serde(skip_serializing_if = "Option::is_none")]
pub taker: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub snapshot: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub both: Option<bool>,
}
impl Book {
pub fn new(taker_gets: Currency, taker_pays: Currency) -> Self {
Self {
taker_gets,
taker_pays,
taker: None,
snapshot: None,
both: None,
}
}
pub fn snapshot(self, snapshot: bool) -> Self {
Self {
snapshot: Some(snapshot),
..self
}
}
pub fn taker(self, taker: impl Into<String>) -> Self {
Self {
taker: Some(taker.into()),
..self
}
}
pub fn both(self, both: bool) -> Self {
Self {
both: Some(both),
..self
}
}
}
impl Request for SubscribeRequest {
type Response = SubscribeResponse;
fn method(&self) -> String {
"subscribe".to_owned()
}
}
impl SubscribeRequest {
pub fn new() -> Self {
Self::default()
}
pub fn streams(streams: Vec<String>) -> Self {
Self {
streams: Some(streams),
..Default::default()
}
}
pub fn accounts(accounts: Vec<String>) -> Self {
Self {
accounts: Some(accounts),
..Default::default()
}
}
pub fn accounts_proposed(accounts: Vec<String>) -> Self {
Self {
accounts_proposed: Some(accounts),
..Default::default()
}
}
pub fn books(books: Vec<Book>) -> Self {
Self {
books: Some(books),
..Default::default()
}
}
pub fn url(url: impl Into<String>) -> Self {
Self {
url: Some(url.into()),
..Default::default()
}
}
pub fn url_username(url: impl Into<String>) -> Self {
Self {
url: Some(url.into()),
..Default::default()
}
}
}
#[derive(Debug, Deserialize)]
pub struct SubscribeResponse {}