crypto_rest_client/exchanges/ftx.rs
1use super::utils::http_get;
2use crate::error::Result;
3use std::collections::BTreeMap;
4
5const BASE_URL: &str = "https://ftx.com/api";
6
7/// The RESTful client for FTX.
8///
9/// FTX has Spot, LinearFuture, LinearSwap, Option, Move and BVOL markets.
10///
11/// * RESTful API doc: <https://docs.ftx.com/#rest-api>
12/// * Trading at <https://ftx.com/markets>
13/// * Rate Limits: <https://docs.ftx.com/?python#rate-limits>
14/// * Non-order placement requests do not count towards rate limits.
15/// * Rate limits are tiered by account trading volumes.
16pub struct FtxRestClient {
17 _api_key: Option<String>,
18 _api_secret: Option<String>,
19}
20
21impl FtxRestClient {
22 pub fn new(api_key: Option<String>, api_secret: Option<String>) -> Self {
23 FtxRestClient { _api_key: api_key, _api_secret: api_secret }
24 }
25
26 /// Get the latest Level2 snapshot of orderbook.
27 ///
28 /// Top 100 bids and asks are returned.
29 ///
30 /// For example: <https://ftx.com/api/markets/BTC-PERP/orderbook?depth=100>,
31 // <https://ftx.com/api/markets/BTC/USD/orderbook?depth=100>
32 pub fn fetch_l2_snapshot(symbol: &str) -> Result<String> {
33 gen_api!(format!("/markets/{symbol}/orderbook?depth=100"))
34 }
35
36 /// Get open interest.
37 ///
38 /// For example:
39 /// - <https://ftx.com/api/futures>
40 pub fn fetch_open_interest() -> Result<String> {
41 gen_api!("/futures")
42 }
43}