crypto_rest_client/exchanges/kraken/
kraken_futures.rs

1use super::super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5// see https://support.kraken.com/hc/en-us/articles/360022839491-API-URLs
6const BASE_URL: &str = "https://futures.kraken.com/derivatives/api/v3";
7
8/// The WebSocket client for Kraken Futures.
9///
10/// * REST API doc: <https://support.kraken.com/hc/en-us/sections/360003562331-REST-API-Public>
11/// * Trading at: <https://futures.kraken.com/>
12/// * Rate Limits: <https://support.kraken.com/hc/en-us/articles/360022635612-Request-Limits-REST-API->
13///   * 500 every 10 seconds
14pub struct KrakenFuturesRestClient {
15    _api_key: Option<String>,
16    _api_secret: Option<String>,
17}
18
19impl KrakenFuturesRestClient {
20    pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
21        KrakenFuturesRestClient { _api_key: api_key, _api_secret: api_secret }
22    }
23
24    /// Get most recent trades.
25    ///
26    /// If `lastTime` is provided, return trade data from the specified
27    /// lastTime.
28    ///
29    /// For example: <https://futures.kraken.com/derivatives/api/v3/history?symbol=PI_XBTUSD>
30    #[allow(non_snake_case)]
31    pub fn fetch_trades(symbol: &str, lastTime: Option<String>) -> Result<String> {
32        gen_api!(format!("/history?symbol={symbol}"), lastTime)
33    }
34
35    /// Get a Level2 snapshot of orderbook.
36    ///
37    /// For example: <https://futures.kraken.com/derivatives/api/v3/orderbook?symbol=PI_XBTUSD>
38    pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
39        gen_api!(format!("/orderbook?symbol={symbol}"))
40    }
41}