use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Deserialize)]
pub struct Product {
pub product_id: String,
pub price: String,
pub price_percentage_change_24h: String,
pub volume_24h: String,
pub volume_percentage_change_24h: String,
pub base_increment: String,
pub quote_increment: String,
pub quote_min_size: String,
pub quote_max_size: String,
pub base_min_size: String,
pub base_max_size: String,
pub base_name: String,
pub quote_name: String,
pub watched: bool,
pub is_disabled: bool,
pub new: bool,
pub status: String,
pub cancel_only: bool,
pub limit_only: bool,
pub post_only: bool,
pub trading_disabled: bool,
pub auction_mode: bool,
pub product_type: Option<String>,
pub quote_currency_id: String,
pub base_currency_id: String,
pub base_display_symbol: Option<String>,
pub quote_display_symbol: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListProductsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub offset: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub product_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub product_ids: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub get_all_products: Option<bool>,
}
impl ListProductsParams {
pub fn new() -> Self {
Self::default()
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub fn offset(mut self, offset: u32) -> Self {
self.offset = Some(offset);
self
}
pub fn product_type(mut self, product_type: impl Into<String>) -> Self {
self.product_type = Some(product_type.into());
self
}
pub fn product_ids(mut self, ids: &[&str]) -> Self {
self.product_ids = Some(ids.join(","));
self
}
pub fn all(mut self) -> Self {
self.get_all_products = Some(true);
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct ListProductsResponse {
pub products: Vec<Product>,
pub num_products: Option<u32>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetProductParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub get_tradability_status: Option<bool>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct BookLevel {
pub price: String,
pub size: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ProductBook {
pub product_id: String,
pub bids: Vec<BookLevel>,
pub asks: Vec<BookLevel>,
pub time: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GetProductBookResponse {
pub pricebook: ProductBook,
}
#[derive(Debug, Clone, Serialize)]
pub struct GetProductBookParams {
pub product_id: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub aggregation_price_increment: Option<String>,
}
impl GetProductBookParams {
pub fn new(product_id: impl Into<String>) -> Self {
Self {
product_id: product_id.into(),
limit: None,
aggregation_price_increment: None,
}
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
pub fn aggregation(mut self, increment: impl Into<String>) -> Self {
self.aggregation_price_increment = Some(increment.into());
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct BestBidAsk {
pub product_id: String,
pub bids: Vec<BookLevel>,
pub asks: Vec<BookLevel>,
pub time: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GetBestBidAskResponse {
pub pricebooks: Vec<BestBidAsk>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct GetBestBidAskParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub product_ids: Option<String>,
}
impl GetBestBidAskParams {
pub fn new() -> Self {
Self::default()
}
pub fn product_ids(mut self, ids: &[&str]) -> Self {
self.product_ids = Some(ids.join(","));
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum Granularity {
OneMinute,
FiveMinute,
FifteenMinute,
ThirtyMinute,
OneHour,
TwoHour,
SixHour,
OneDay,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Candle {
pub start: String,
pub low: String,
pub high: String,
pub open: String,
pub close: String,
pub volume: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct GetCandlesParams {
#[serde(skip_serializing)]
pub product_id: String,
pub start: String,
pub end: String,
pub granularity: Granularity,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<u32>,
}
impl GetCandlesParams {
pub fn new(
product_id: impl Into<String>,
start: impl Into<String>,
end: impl Into<String>,
granularity: Granularity,
) -> Self {
Self {
product_id: product_id.into(),
start: start.into(),
end: end.into(),
granularity,
limit: None,
}
}
pub fn limit(mut self, limit: u32) -> Self {
self.limit = Some(limit);
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct GetCandlesResponse {
pub candles: Vec<Candle>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Trade {
pub trade_id: String,
pub product_id: String,
pub price: String,
pub size: String,
pub time: String,
pub side: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct GetMarketTradesParams {
#[serde(skip_serializing)]
pub product_id: String,
pub limit: u32,
#[serde(skip_serializing_if = "Option::is_none")]
pub start: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub end: Option<String>,
}
impl GetMarketTradesParams {
pub fn new(product_id: impl Into<String>, limit: u32) -> Self {
Self {
product_id: product_id.into(),
limit,
start: None,
end: None,
}
}
pub fn start(mut self, start: impl Into<String>) -> Self {
self.start = Some(start.into());
self
}
pub fn end(mut self, end: impl Into<String>) -> Self {
self.end = Some(end.into());
self
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct GetMarketTradesResponse {
pub trades: Vec<Trade>,
pub best_bid: Option<String>,
pub best_ask: Option<String>,
}