deribit_base/
common.rs

1//! Common functionality shared across all Deribit clients
2
3use async_trait::async_trait;
4use serde::{Deserialize, Serialize};
5
6/// Common configuration for Deribit clients
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct DeribitConfig {
9    pub client_id: String,
10    pub client_secret: String,
11    pub test_net: bool,
12    pub timeout_seconds: u64,
13}
14
15impl Default for DeribitConfig {
16    fn default() -> Self {
17        Self {
18            client_id: String::new(),
19            client_secret: String::new(),
20            test_net: true,
21            timeout_seconds: 30,
22        }
23    }
24}
25
26/// Base URL configuration
27pub struct DeribitUrls;
28
29impl DeribitUrls {
30    pub const PROD_BASE_URL: &'static str = "https://www.deribit.com";
31    pub const TEST_BASE_URL: &'static str = "https://test.deribit.com";
32
33    pub const PROD_WS_URL: &'static str = "wss://www.deribit.com/ws/api/v2";
34    pub const TEST_WS_URL: &'static str = "wss://test.deribit.com/ws/api/v2";
35
36    pub fn get_base_url(test_net: bool) -> &'static str {
37        if test_net {
38            Self::TEST_BASE_URL
39        } else {
40            Self::PROD_BASE_URL
41        }
42    }
43
44    pub fn get_ws_url(test_net: bool) -> &'static str {
45        if test_net {
46            Self::TEST_WS_URL
47        } else {
48            Self::PROD_WS_URL
49        }
50    }
51}
52
53/// Common trait for all Deribit clients
54#[async_trait]
55pub trait DeribitClient {
56    type Error;
57
58    /// Connect to Deribit
59    async fn connect(&mut self) -> Result<(), Self::Error>;
60
61    /// Disconnect from Deribit
62    async fn disconnect(&mut self) -> Result<(), Self::Error>;
63
64    /// Check if connected
65    fn is_connected(&self) -> bool;
66}