deribit_http/model/
types.rs1use pretty_simple_display::{DebugPretty, DisplaySimple};
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6use std::collections::HashMap;
7
8#[skip_serializing_none]
10#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
11pub struct ApiError {
12 pub code: i32,
14 pub message: String,
16 pub data: Option<serde_json::Value>,
18}
19
20#[skip_serializing_none]
22#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
23pub struct AuthToken {
24 pub access_token: String,
26 pub token_type: String,
28 pub expires_in: u64,
30 pub refresh_token: Option<String>,
32 pub scope: String,
34}
35
36#[derive(DebugPretty, DisplaySimple, Clone, Default, Serialize, Deserialize)]
38pub struct RequestParams {
39 params: HashMap<String, serde_json::Value>,
40}
41
42impl RequestParams {
43 pub fn new() -> Self {
45 Self::default()
46 }
47
48 pub fn add<T: Serialize>(mut self, key: &str, value: T) -> Self {
50 if let Ok(json_value) = serde_json::to_value(value) {
51 self.params.insert(key.to_string(), json_value);
52 }
53 self
54 }
55
56 pub fn to_json(&self) -> serde_json::Value {
58 serde_json::to_value(&self.params).unwrap_or(serde_json::Value::Null)
59 }
60
61 pub fn is_empty(&self) -> bool {
63 self.params.is_empty()
64 }
65}
66
67#[derive(DebugPretty, DisplaySimple, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
69pub enum TimeInForce {
70 #[serde(rename = "good_til_cancelled")]
72 GoodTilCancelled,
73 #[serde(rename = "good_til_day")]
75 GoodTilDay,
76 #[serde(rename = "fill_or_kill")]
78 FillOrKill,
79 #[serde(rename = "immediate_or_cancel")]
81 ImmediateOrCancel,
82}
83
84impl TimeInForce {
85 pub fn as_str(&self) -> &'static str {
87 match self {
88 TimeInForce::GoodTilCancelled => "good_til_cancelled",
89 TimeInForce::GoodTilDay => "good_til_day",
90 TimeInForce::FillOrKill => "fill_or_kill",
91 TimeInForce::ImmediateOrCancel => "immediate_or_cancel",
92 }
93 }
94}
95
96#[skip_serializing_none]
98#[derive(DebugPretty, DisplaySimple, Clone, Serialize, Deserialize)]
99pub struct Withdrawal {
100 pub address: String,
102 pub amount: f64,
104 pub currency: String,
106 pub fee: f64,
108 pub id: u64,
110 pub priority: String,
112 pub state: String,
114 pub created_timestamp: u64,
116 pub updated_timestamp: Option<u64>,
118 pub transaction_id: Option<String>,
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(rename_all = "lowercase")]
125pub enum Direction {
126 Buy,
128 Sell,
130}