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
use indexmap::map::IndexMap;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

use super::{
    AssetPairInfo, EndpointInfo, Input, InputList, InputListItem, IntoInputList, KAssetPair,
    KrakenInput, MethodType, MutateInput, Output, UpdateInput,
};

/// Request builder for the Get Tradable Asset Pairs endpoint
pub struct KIAssetPairs {
    params: IndexMap<String, String>,
}

impl KIAssetPairs {
    /// Constructor returning a [KrakenInput] builder for the get tradeable asset pairs endpoint.
    pub fn build() -> Self {
        KIAssetPairs {
            params: IndexMap::new(),
        }
    }

    /// An asset pair is not required for the get asset info endpoint. 
    /// This method clears a currently populated asset pair list.
    /// Useful for templating
    pub fn clear_pair_list(self) -> Self {
        self.update_input("pair", String::from(""))
    }

    /// Update the list of assets pairs to query info for 
    pub fn with_asset_pair(self, pair: KAssetPair) -> Self {
        self.with_item(pair)
    }

    /// Update the list of assets pairs to query info for 
    pub fn with_asset_pair_list<T>(self, pairs: T) -> Self
    where
        T: IntoIterator<Item = KAssetPair>,
    {
        self.with_item_list(pairs)
    }

    /// [Asset pair info][AssetPairInfo] to retrieve
    pub fn info(self, info: AssetPairInfo) -> Self {
        self.update_input("info", info.to_string())
    }
}

impl Input for KIAssetPairs {
    fn finish(self) -> KrakenInput {
        KrakenInput {
            info: EndpointInfo {
                methodtype: MethodType::Public,
                endpoint: String::from("AssetPairs"),
            },
            params: Some(self.params),
        }
    }

    fn finish_clone(self) -> (KrakenInput, Self) {
        (
            KrakenInput {
                info: EndpointInfo {
                    methodtype: MethodType::Public,
                    endpoint: String::from("AssetPairs"),
                },
                params: Some(self.params.clone()),
            },
            self,
        )
    }
}

impl MutateInput for KIAssetPairs {
    fn list_mut(&mut self) -> &mut IndexMap<String, String> {
        &mut self.params
    }
}

impl UpdateInput for KIAssetPairs {}

impl IntoInputList for KIAssetPairs {
    fn list_name(&self) -> String {
        String::from("pair")
    }
}

impl InputListItem for KIAssetPairs {
    type ListItem = KAssetPair;
}

impl InputList for KIAssetPairs {}

/// Asset pair info data
#[derive(Deserialize, Serialize, Debug)]
pub struct KOAssetPair {
    /// asset class of base component
    pub aclass_base: String,
    /// asset class of quote component
    pub aclass_quote: String,
    /// alternate pair name
    pub altname: String,
    /// asset id of base component
    pub base: String,
    /// volume discount currency
    pub fee_volume_currency: String,
    /// fee schedule array in [volume, percent fee] tuples
    pub fees: Vec<(u64, f64)>,
    /// maker fee schedule array in [volume, percent fee] tuples (if on maker/taker)
    pub fees_maker: Option<Vec<(u64, f64)>>,
    /// array of leverage amounts available when buying
    pub leverage_buy: Vec<u32>,
    /// array of leverage amounts available when selling
    pub leverage_sell: Vec<u32>,
    /// volume lot size
    pub lot: String,
    /// scaling decimal places for volume
    pub lot_decimals: u32,
    /// amount to multiply lot volume by to get currency volume
    pub lot_multiplier: u32,
    /// margin call level
    pub margin_call: u32,
    /// stop-out/liquidation margin level
    pub margin_stop: u32,
    /// minimum order volume for pair
    pub ordermin: Option<String>,
    /// scaling decimal places for pair
    pub pair_decimals: u32,
    /// asset id of quote component
    pub quote: String,
    /// websocket pair name (if available)
    pub wsname: Option<String>,
}

/// Response from the Get Tradable Asset Pairs endpoint
#[derive(Deserialize, Serialize, Debug)]
pub struct KOAssetPairInfo {
    /// Map with the asset pair as the key and the pair's data as the value
    #[serde(flatten)]
    pub pair: HashMap<KAssetPair, KOAssetPair>,
}

impl Output for KOAssetPairInfo {}