kraken_rest_client/api/
get_open_positions.rs1use crate::{Client, Result};
2use serde::{de::DeserializeOwned, Deserialize};
3use std::collections::HashMap;
4
5#[must_use = "Does nothing until you send or execute it"]
8pub struct GetOpenPositionsRequest {
9 client: Client,
10 docalcs: bool,
11}
12
13impl GetOpenPositionsRequest {
14 pub fn docalcs(self, docalcs: bool) -> Self {
16 Self { docalcs, ..self }
17 }
18
19 pub async fn execute<T: DeserializeOwned>(self) -> Result<T> {
20 let mut query: Vec<String> = Vec::new();
21
22 if self.docalcs {
23 query.push(String::from("docalcs=true"));
24 }
25
26 let query = if query.is_empty() {
27 None
28 } else {
29 Some(query.join("&"))
30 };
31
32 self.client
33 .send_private("/0/private/OpenPositions", query)
34 .await
35 }
36
37 pub async fn send(self) -> Result<GetOpenPositionsResponse> {
38 self.execute().await
39 }
40}
41
42#[derive(Debug, Deserialize)]
43pub struct OpenPositionInfo {
44 pub ordertxid: String,
45 pub posstatus: String,
46 pub pair: String,
47 pub time: f64,
48 #[serde(rename = "type")]
49 pub position_type: String,
50 pub ordertype: String,
51 pub cost: String,
52 pub fee: String,
53 pub vol: String,
54 pub vol_closed: String,
55 pub margin: String,
56 pub value: Option<String>,
57 pub net: Option<String>,
58 pub terms: String,
59 pub rollovertm: String,
60 pub misc: String,
61 pub oflags: String,
62}
63
64pub type GetOpenPositionsResponse = HashMap<String, OpenPositionInfo>;
65
66impl Client {
67 pub fn get_open_positions(&self) -> GetOpenPositionsRequest {
68 GetOpenPositionsRequest {
69 client: self.clone(),
70 docalcs: false,
71 }
72 }
73}