1use crate::Error;
2use chrono::serde::ts_milliseconds;
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use std::{fmt, str};
6
7#[derive(Debug, Deserialize, Serialize)]
8pub enum OrderType {
9 BID,
10 ASK,
11}
12impl fmt::Display for OrderType {
13 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 OrderType::BID => write!(f, "BID"),
16 OrderType::ASK => write!(f, "ASK"),
17 }
18 }
19}
20
21impl str::FromStr for OrderType {
22 type Err = Error;
23
24 fn from_str(s: &str) -> Result<Self, Self::Err> {
25 match s {
26 "BID" => Ok(OrderType::BID),
27 "ASK" => Ok(OrderType::ASK),
28 _ => Err(Error::InvalidCurrencyPair(s.to_string())),
29 }
30 }
31}
32
33#[derive(Debug, Deserialize, Serialize)]
34pub struct Order {
35 pub order_id: String,
36 #[serde(with = "ts_milliseconds")]
37 pub creation_timestamp: DateTime<Utc>,
38 #[serde(with = "ts_milliseconds")]
39 pub expiration_timestamp: DateTime<Utc>,
40 #[serde(with = "ts_milliseconds")]
41 pub completed_timestamp: DateTime<Utc>,
42 #[serde(rename = "type")]
43 pub order_type: OrderType,
44 pub state: String,
45 pub limit_price: String,
46 pub limit_volume: String,
47 pub base: String,
48 pub counter: String,
49 pub fee_base: String,
50 pub fee_counter: String,
51 pub pair: String,
52}
53
54#[derive(Deserialize)]
55pub struct ListOrdersResponse {
56 pub orders: Vec<Order>,
57}
58
59#[derive(Debug, Deserialize, Serialize)]
61pub struct OrderBookEntry {
62 pub price: String,
64 pub volume: String,
66}
67
68#[derive(Debug, Deserialize, Serialize)]
70pub struct OrderBook {
71 pub asks: Vec<OrderBookEntry>,
72 pub bids: Vec<OrderBookEntry>,
73 #[serde(with = "ts_milliseconds")]
74 pub timestamp: DateTime<Utc>,
75}