crypto_rest_client/exchanges/bitmex.rs
1use super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://www.bitmex.com/api/v1";
6
7/// The REST client for BitMEX.
8///
9/// BitMEX has Swap and Future markets.
10///
11/// * REST API doc: <https://www.bitmex.com/api/explorer/>
12/// * Trading at: <https://www.bitmex.com/app/trade/>
13/// * Rate Limits: <https://www.bitmex.com/app/restAPI#Limits>
14/// * 60 requests per minute on all routes (reduced to 30 when
15/// unauthenticated)
16/// * 10 requests per second on certain routes (see below)
17pub struct BitmexRestClient {
18 _api_key: Option<String>,
19 _api_secret: Option<String>,
20}
21
22impl BitmexRestClient {
23 pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
24 BitmexRestClient { _api_key: api_key, _api_secret: api_secret }
25 }
26
27 /// Get trades from a beginning time.
28 ///
29 /// Equivalent to `/trade` with `count=1000`
30 ///
31 /// For example: <https://www.bitmex.com/api/v1/trade?symbol=XBTUSD&count=1000&startTime=2018-09-28T12:34:25.706Z>
32 #[allow(non_snake_case)]
33 pub fn fetch_trades(symbol: &str, start_time: Option<String>) -> Result<String> {
34 let symbol = Some(symbol);
35 let startTime = start_time;
36 gen_api!("/trade", symbol, startTime)
37 }
38
39 /// Get a full Level2 snapshot of orderbook.
40 ///
41 /// Equivalent to `/orderBook/L2` with `depth=0`
42 ///
43 /// For example: <https://www.bitmex.com/api/v1/orderBook/L2?symbol=XBTUSD&depth=0>
44 pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
45 let symbol = Some(symbol);
46 let depth = Some(0);
47 gen_api!("/orderBook/L2", symbol, depth)
48 }
49}