kraken_async_rs/wss/messages/
trading_messages.rs

1use crate::crypto::secrets::Token;
2use crate::request_types::{IntOrString, SelfTradePrevention, TimeInForceV2, TriggerType};
3use crate::response_types::{BuySell, OrderType};
4use rust_decimal::serde::{float, float_option};
5use rust_decimal::Decimal;
6use serde::{Deserialize, Serialize};
7use serde_with::skip_serializing_none;
8use simple_builder::Builder;
9
10#[derive(Debug, Eq, PartialEq, Clone, Deserialize)]
11pub enum AddOrderStatus {
12    Ok,
13    Err,
14}
15
16#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
17#[serde(rename_all = "lowercase")]
18pub enum FeePreference {
19    #[serde(rename(deserialize = "fcib"))]
20    Base,
21    #[serde(rename(deserialize = "fciq"))]
22    Quote,
23}
24
25/// Type of price given in the `limit_price` field
26#[derive(Debug, Eq, PartialEq, Clone, Serialize, Deserialize)]
27pub enum PriceType {
28    /// Static or real price, e.g. 65123.29 for BTC/USD
29    #[serde(rename = "static")]
30    Static,
31    /// Percent different from the previous price, e.g. -5.0 (%)
32    #[serde(rename = "pct")]
33    Percent,
34    /// Quote/notional difference from the last traded price, e.g. -500, 150, etc
35    #[serde(rename = "quote")]
36    Quote,
37}
38
39#[derive(Debug, Serialize, Deserialize)]
40pub struct TriggerParams {
41    pub price: Decimal,
42    pub price_type: Option<PriceType>,
43    pub reference: Option<TriggerType>,
44}
45
46#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
47pub struct ConditionalParams {
48    pub order_type: Option<OrderType>,
49    pub limit_price: Option<Decimal>,
50    pub limit_price_type: Option<PriceType>,
51    pub trigger_price: Option<Decimal>,
52    pub trigger_price_type: Option<PriceType>,
53}
54
55#[skip_serializing_none]
56#[derive(Debug, Serialize, Deserialize)]
57pub struct AddOrderParams {
58    pub order_type: OrderType,
59    pub side: BuySell,
60    pub symbol: String,
61    #[serde(with = "float_option")]
62    pub limit_price: Option<Decimal>,
63    pub limit_price_type: Option<PriceType>,
64    pub triggers: Option<TriggerParams>,
65    pub time_in_force: Option<TimeInForceV2>,
66    #[serde(with = "float")]
67    #[serde(rename = "order_qty")]
68    pub order_quantity: Decimal,
69    pub margin: Option<bool>,
70    pub post_only: Option<bool>,
71    pub reduce_only: Option<bool>,
72    pub expire_time: Option<String>,
73    pub deadline: Option<String>,
74    pub effective_time: Option<String>, // RFC3339
75    #[serde(rename = "cl_ord_id")]
76    pub client_order_id: Option<String>,
77    #[serde(rename = "order_userref")]
78    pub order_user_ref: Option<i64>,
79    pub conditional: Option<ConditionalParams>,
80    #[serde(with = "float_option")]
81    #[serde(rename = "display_qty")]
82    pub display_quantity: Option<Decimal>,
83    pub fee_preference: Option<FeePreference>,
84    #[serde(rename = "no_mpp")]
85    pub no_market_price_protection: Option<bool>,
86    pub stp_type: Option<SelfTradePrevention>,
87    #[serde(with = "float_option")]
88    #[serde(rename = "cash_order_qty")]
89    pub cash_order_quantity: Option<Decimal>,
90    pub validate: Option<bool>,
91    pub sender_sub_id: Option<String>,
92    pub token: Token,
93}
94
95#[derive(Debug, Deserialize, PartialEq)]
96pub struct AddOrderResult {
97    pub order_id: String,
98    #[serde(rename = "order_userref")]
99    pub order_user_ref: Option<i64>,
100    pub warning: Option<Vec<String>>,
101    #[serde(rename = "cl_ord_id")]
102    pub client_order_id: Option<String>,
103}
104
105#[skip_serializing_none]
106#[derive(Debug, Serialize, Deserialize, Builder)]
107pub struct AmendOrderParams {
108    pub order_id: Option<String>,
109    #[serde(rename = "cl_ord_id")]
110    pub client_order_id: Option<String>,
111    #[serde(rename = "order_qty")]
112    #[serde(with = "float")]
113    #[builder(required)]
114    pub order_quantity: Decimal,
115    #[serde(rename = "display_qty")]
116    pub display_quantity: Option<Decimal>,
117    #[serde(with = "float_option")]
118    pub limit_price: Option<Decimal>,
119    pub limit_price_type: Option<PriceType>,
120    pub post_only: Option<bool>,
121    #[serde(with = "float_option")]
122    pub trigger_price: Option<Decimal>,
123    pub trigger_price_type: Option<PriceType>,
124    pub deadline: Option<String>,
125    #[builder(required)]
126    pub token: Token,
127}
128
129#[derive(Debug, Deserialize, PartialEq)]
130pub struct AmendOrderResult {
131    pub amend_id: String,
132    pub order_id: Option<String>,
133    #[serde(rename = "cl_ord_id")]
134    pub client_order_id: Option<String>,
135    pub warnings: Option<Vec<String>>,
136}
137
138#[skip_serializing_none]
139#[derive(Debug, Serialize, Deserialize)]
140pub struct EditOrderParams {
141    pub deadline: Option<String>,
142    #[serde(with = "float_option")]
143    #[serde(rename = "display_qty")]
144    pub display_quantity: Option<Decimal>,
145    pub fee_preference: Option<FeePreference>,
146    #[serde(with = "float_option")]
147    pub limit_price: Option<Decimal>,
148    #[serde(rename = "no_mpp")]
149    pub no_market_price_protection: Option<bool>,
150    pub order_id: String,
151    #[serde(with = "float_option")]
152    #[serde(rename = "order_qty")]
153    pub order_quantity: Option<Decimal>,
154    #[serde(rename = "order_userref")]
155    pub order_user_ref: Option<i64>,
156    pub post_only: Option<bool>,
157    pub reduce_only: Option<bool>,
158    pub symbol: String,
159    pub triggers: Option<TriggerParams>,
160    pub validate: Option<bool>,
161    pub token: Token,
162}
163
164#[derive(Debug, Deserialize, PartialEq)]
165pub struct EditOrderResult {
166    pub order_id: String,
167    pub original_order_id: String,
168    pub warning: Option<Vec<String>>,
169}
170
171#[skip_serializing_none]
172#[derive(Debug, Serialize, Deserialize)]
173pub struct CancelOrderParams {
174    pub order_id: Option<Vec<String>>,
175    #[serde(rename = "cl_ord_id")]
176    pub client_order_id: Option<Vec<String>>,
177    #[serde(rename = "order_userref")]
178    pub order_user_ref: Option<Vec<i64>>,
179    pub token: Token,
180}
181
182#[derive(Debug, Deserialize, PartialEq)]
183pub struct CancelOrderResult {
184    pub order_id: Option<String>,
185    pub warning: Option<Vec<String>>,
186    #[serde(rename = "cl_ord_id")]
187    pub client_order_id: Option<String>,
188}
189
190#[derive(Debug, Serialize, Deserialize)]
191pub struct CancelAllOrdersParams {
192    pub token: Token,
193}
194
195#[derive(Debug, Deserialize, PartialEq)]
196pub struct CancelAllOrdersResult {
197    pub count: i32,
198    pub warning: Option<Vec<String>>,
199}
200
201#[derive(Debug, Serialize, Deserialize)]
202pub struct CancelOnDisconnectParams {
203    pub timeout: i64,
204    pub token: Token,
205}
206
207#[derive(Debug, Deserialize, PartialEq)]
208pub struct CancelOnDisconnectResult {
209    #[serde(rename = "currentTime")]
210    pub current_time: String,
211    #[serde(rename = "triggerTime")]
212    pub trigger_time: String,
213    pub warning: Option<Vec<String>>,
214}
215
216#[skip_serializing_none]
217#[derive(Debug, Serialize, Deserialize)]
218pub struct BatchOrder {
219    pub order_type: OrderType,
220    pub side: BuySell,
221    #[serde(with = "float_option")]
222    pub limit_price: Option<Decimal>,
223    pub limit_price_type: Option<PriceType>,
224    pub triggers: Option<TriggerParams>,
225    pub time_in_force: Option<TimeInForceV2>,
226    #[serde(with = "float")]
227    #[serde(rename = "order_qty")]
228    pub order_quantity: Decimal,
229    pub margin: Option<bool>,
230    pub post_only: Option<bool>,
231    pub reduce_only: Option<bool>,
232    pub effective_time: Option<String>, // RFC3339
233    pub expire_time: Option<String>,
234    #[serde(rename = "order_userref")]
235    pub order_user_ref: Option<i64>,
236    pub conditional: Option<ConditionalParams>,
237    #[serde(with = "float_option")]
238    #[serde(rename = "display_qty")]
239    pub display_quantity: Option<Decimal>,
240    pub fee_preference: Option<FeePreference>,
241    #[serde(rename = "no_mpp")]
242    pub no_market_price_protection: Option<bool>,
243    pub stp_type: Option<SelfTradePrevention>,
244    #[serde(with = "float_option")]
245    #[serde(rename = "cash_order_qty")]
246    pub cash_order_quantity: Option<Decimal>,
247    #[serde(rename = "cl_ord_id")]
248    pub client_order_id: Option<String>,
249}
250
251#[skip_serializing_none]
252#[derive(Debug, Serialize, Deserialize)]
253pub struct BatchOrderParams {
254    pub deadline: Option<String>,
255    pub symbol: String,
256    pub validate: Option<bool>,
257    pub token: Token,
258    pub orders: Vec<BatchOrder>,
259}
260
261#[skip_serializing_none]
262#[derive(Debug, Serialize)]
263pub struct BatchCancelParams {
264    pub orders: Vec<IntOrString>,
265    pub token: Token,
266    #[serde(rename = "cl_ord_id")]
267    pub client_order_id: Option<Vec<String>>,
268}
269
270#[derive(Debug, Deserialize, PartialEq)]
271pub struct BatchCancelResult {
272    pub count: i32,
273    pub warning: Option<Vec<String>>,
274}
275
276#[derive(Debug, Deserialize, PartialEq)]
277pub struct BatchCancelResponse {
278    pub orders_cancelled: i64,
279    pub error: Option<String>,
280    pub success: bool,
281    pub req_id: i64,
282    pub time_in: String,
283    pub time_out: String,
284    #[serde(rename = "cl_ord_id")]
285    pub client_order_id: Option<Vec<String>>,
286}