1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//! Module for interacting with Kraken's private API endpoints
//! # Note
//! Each type prefixed with "KI" is a [KrakenInput][super::KrakenInput] builder which will build requests for the given
//! endpoint.
//! Each type postfixed with "KO" is the output object that has been returned from Kraken's servers
//! and has been parsed into the given structure.
//! A valid api key and api secret will have to be used when creating a
//! [KrakenClient][super::super::client::KrakenClient] otherwise requests sent to
//! private endpoints will panic before being sent to Kraken

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

// Structs/Enums
use super::asset::{KAsset, KAssetPair};
use super::{
    EndpointInfo, KrakenInput, LedgerType, MethodType, OrderCloseTime, OrderFlags, OrderType,
    TradeHistoryType, TradeType,
};

// Traits
use super::{Input, InputList, InputListItem, IntoInputList, MutateInput, Output, UpdateInput};

/// Get account balance endpoint
pub mod account_balance;

/// Get trade balance endpoint
pub mod trade_balance;

/// Get open orders endpoint
pub mod open_orders;

/// Get closed orders endpoint
pub mod closed_orders;

/// Query orders info endpoint
pub mod query_orders;

/// Get trade history endpoint
pub mod trade_history;

/// Query trades info endpoint
pub mod query_trades;

/// Get open positions endpoint
pub mod open_positions;

/// Get ledgers info endpoint
pub mod ledger_info;

/// Query ledgers endpoint
pub mod query_ledgers;

/// Get trade volume endpoint
pub mod trade_volume;

/// Add standard order endpoint
pub mod add_order;

/// Cancel open order endpoint
pub mod cancel_order;

/// Cancel all orders endpoint
pub mod cancel_all_orders;

/// Cancel all orders after ... endpoint
pub mod cancel_on_timeout;

/// Order description data | See [KOOrderInfo]
#[derive(Deserialize, Serialize, Debug)]
pub struct KOOrderDescription {
    pub pair: String,
    #[serde(rename = "type")]
    pub tradetype: String,
    pub ordertype: String,
    pub price: String,
    pub price2: String,
    pub leverage: String,
    #[serde(rename = "order")]
    pub desc: String,
    #[serde(rename = "close")]
    pub closedesc: String,
}

/// Order status data | See [KOOrderInfo]
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "lowercase")]
pub enum KOOrderStatus {
    /// order pending book entry
    Pending,
    /// open order
    Open,
    /// closed order
    Closed,
    /// order canceled
    Canceled,
    /// order expired
    Expired,
}

/// Order info data | See [KOOpenOrders][open_orders::KOOpenOrders] -
/// [KOClosedOrders][closed_orders::KOClosedOrders] -
/// [KOQueryOrders][query_orders::KOQueryOrders]
#[derive(Deserialize, Serialize, Debug)]
pub struct KOOrderInfo {
    /// Referral order transaction id that created this order
    pub refid: Option<String>,
    /// user reference id
    pub userref: Option<u32>,
    /// status of order:
    pub status: KOOrderStatus,
    /// unix timestamp of when order was placed
    pub opentm: f64,
    /// unix timestamp of order start time (or 0 if not set)
    pub starttm: f64,
    /// unix timestamp of order end time (or 0 if not set)
    pub expiretm: f64,
    /// order description info
    pub descr: KOOrderDescription,
    /// volume of order (base currency unless viqc set in oflags)
    pub vol: String,
    /// volume executed (base currency unless viqc set in oflags)
    pub vol_exec: String,
    /// total cost (quote currency unless unless viqc set in oflags)
    pub cost: String,
    /// total fee (quote currency)
    pub fee: String,
    /// average price (quote currency unless viqc set in oflags)
    pub price: String,
    /// stop price (quote currency, for trailing stops)
    pub stopprice: Option<String>,
    /// triggered limit price (quote currency, when limit based order type triggered)
    pub limitprice: Option<String>,
    /// comma delimited list of miscellaneous info:
    /// + stopped = triggered by stop price
    /// + touched = triggered by touch price
    /// + liquidated = liquidation
    /// + partial = partial fill
    pub misc: String,
    /// comma delimited list of order flags:
    /// + viqc = volume in quote currency
    /// + fcib = prefer fee in base currency (default if selling)
    /// + fciq = prefer fee in quote currency (default if buying)
    /// + nompp = no market price protection
    pub oflags: String,
    /// array of trade ids related to order (if trades info requested and data available)
    pub trades: Option<Vec<String>>,
    /// unix timestamp of when order was closed. Field only present when calling ClosedOrders
    /// endpoint
    pub closetm: Option<f64>,
    /// additional info on status (if any). Field only present when calling ClosedOrders
    pub reason: Option<String>,
}

/// Trade info data | See [KOTradesInfo][query_trades::KOTradesInfo] -
/// [KOTradeHistory][trade_history::KOTradeHistory]
#[derive(Deserialize, Serialize, Debug)]
pub struct KOTradeData {
    /// Order responsible for execution of trade
    pub ordertxid: String,
    pub pair: String,
    pub time: f64,
    #[serde(rename = "type")]
    pub tradetype: String,
    pub ordertype: String,
    pub price: String,
    pub cost: String,
    pub fee: String,
    pub vol: String,
    pub margin: Option<String>,
    pub misc: String,
    pub posstatus: Option<String>,
    pub cprice: Option<String>,
    pub cfee: Option<String>,
    pub cvol: Option<String>,
    pub cmargin: Option<String>,
    pub net: Option<String>,
    pub trades: Option<String>,
}

/// Ledger info data | See [KOLedgers]
#[derive(Deserialize, Serialize, Debug)]
pub struct KOLedgerInfo {
    /// Order responsible for execution of trade
    pub refid: String,
    pub time: f64,
    #[serde(rename = "type")]
    pub ledgertype: String,
    pub aclass: String,
    pub asset: String,
    pub amount: String,
    pub fee: String,
    pub balance: Option<String>,
}

/// Response from the Get Ledgers Info or Query Ledgers endpoints | See
/// [KILedgerInfo][ledger_info::KILedgerInfo] -
/// [KIQueryLedgers][query_ledgers::KIQueryLedgers]
#[derive(Deserialize, Serialize, Debug)]
pub struct KOLedgers {
    /// Map with the ledger ID as the key and the ledger info as the value
    #[serde(flatten)]
    pub ledgers: HashMap<String, KOLedgerInfo>,
}

impl Output for KOLedgers {}