diff --git a/src/lib.rs b/src/lib.rs index f0c0885..b2a245f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,13 +9,13 @@ pub use kraken_rest_client::*; mod messages; use messages::{ unpack_kraken_result, AddOrderRequest, AssetPairsRequest, CancelAllOrdersAfterRequest, CancelOrderRequest, Empty, - GetOpenOrdersRequest, KrakenResult, TickerRequest, + GetOpenOrdersRequest, KrakenResult, OHLCRequest, TickerRequest, }; pub use messages::{ - AddOrderResponse, AssetPairsResponse, AssetTickerInfo, AssetsResponse, BalanceResponse, BsType, + AddOrderResponse, AssetOHLCInfo, AssetPairsResponse, AssetTickerInfo, AssetsResponse, BalanceResponse, BsType, CancelAllOrdersAfterResponse, CancelAllOrdersResponse, CancelOrderResponse, GetOpenOrdersResponse, - GetWebSocketsTokenResponse, OrderAdded, OrderFlag, OrderInfo, OrderStatus, OrderType, SystemStatusResponse, - TickerResponse, TimeResponse, TxId, UserRefId, + GetWebSocketsTokenResponse, OHLCResponse, OrderAdded, OrderFlag, OrderInfo, OrderStatus, OrderType, + SystemStatusResponse, TickerResponse, TimeResponse, TxId, UserRefId, }; use core::convert::TryFrom; @@ -25,6 +25,8 @@ use std::collections::BTreeSet; #[cfg(feature = "ws")] pub mod ws; +mod tests; + /// A description of a market order to place #[derive(Debug, Clone)] pub struct MarketOrder { @@ -100,6 +102,17 @@ impl KrakenRestAPI { result.and_then(unpack_kraken_result) } + /// (Public) Get the ohlc data for one or more asset pairs + /// + /// Arguments: + /// * pairs: A list of Kraken asset pair strings to get ticker info about + /// * interval: An integer representing time frame interval in minutes (enum: 1 5 15 30 60 240 1440 10080 21600) + /// * since: An integer representing of the epoch (in ms) that you want to get data since + pub fn ohlc(&self, pairs: Vec) -> Result { + let result: Result> = self.client.query_public("OHLC", OHLCRequest { pair: pairs.join(","), interval: None, since: None }); + result.and_then(unpack_kraken_result) + } + /// (Private) Get the balance pub fn get_account_balance(&self) -> Result { let result: Result> = self.client.query_private("Balance", Empty {}); diff --git a/src/messages.rs b/src/messages.rs index 001cd5b..fa771b5 100644 --- a/src/messages.rs +++ b/src/messages.rs @@ -141,6 +141,35 @@ pub struct AssetTickerInfo { /// Type alias for response of Ticker API call pub type TickerResponse = HashMap; +/// A query object to kraken public "OHLC" API call +#[derive(Default, Debug, Serialize, Deserialize)] +pub struct OHLCRequest { + /// A comma-separated list of kraken asset pair strings + pub pair: String, + /// An integer representing time frame interval in minutes (enum: 1 5 15 30 60 240 1440 10080 21600) + #[serde(skip_serializing_if = "Option::is_none")] + pub interval: Option, + /// An integer representing of the epoch (in ms) that you want to get data since + #[serde(skip_serializing_if = "Option::is_none")] + pub since: Option, +} + +/// Result of kraken public "OHLC" API call +// It's result object includes arrays containing differing types, and is somewhat complex. +// See: +// Array of tick data arrays [int