Skip to main content

binance_sdk/alpha/
mod.rs

1pub mod rest_api;
2
3pub mod websocket_streams;
4
5use crate::common::{
6    config::{ConfigurationRestApi, ConfigurationWebsocketStreams},
7    constants::{ALPHA_REST_API_PROD_URL, ALPHA_WS_STREAMS_PROD_URL},
8    utils::build_user_agent,
9};
10
11/// Represents the Alpha REST API client for interacting with the Binance Alpha REST API.
12///
13/// This struct provides methods to create REST API clients for production  environments.
14pub struct AlphaRestApi {}
15
16impl AlphaRestApi {
17    /// Creates a REST API client with the given configuration.
18    ///
19    /// If no base path is specified in the configuration, defaults to the production Alpha REST API URL.
20    ///
21    /// # Arguments
22    ///
23    /// * `config` - Configuration for the REST API client
24    ///
25    /// # Returns
26    ///
27    /// A new REST API client configured with the provided settings
28    #[must_use]
29    pub fn from_config(mut config: ConfigurationRestApi) -> rest_api::RestApi {
30        config.user_agent = build_user_agent("alpha");
31        if config.base_path.is_none() {
32            config.base_path = Some(ALPHA_REST_API_PROD_URL.to_string());
33        }
34        rest_api::RestApi::new(config)
35    }
36
37    /// Creates a REST API client configured for the production environment.
38    ///
39    /// # Arguments
40    ///
41    /// * `config` - Configuration for the REST API client
42    ///
43    /// # Returns
44    ///
45    /// A new REST API client configured for the production environment
46    #[must_use]
47    pub fn production(mut config: ConfigurationRestApi) -> rest_api::RestApi {
48        config.base_path = Some(ALPHA_REST_API_PROD_URL.to_string());
49        AlphaRestApi::from_config(config)
50    }
51}
52
53/// Represents the Alpha WebSocket Streams client for interacting with the Binance Alpha WebSocket Streams.
54///
55/// This struct provides methods to create WebSocket Streams clients for production  environments.
56pub struct AlphaWsStreams {}
57
58impl AlphaWsStreams {
59    /// Creates a WebSocket streams client configured with the given settings.
60    ///
61    /// If no WS URL is specified in the configuration, defaults to the production Alpha WebSocket Streams URL.
62    ///
63    /// # Arguments
64    ///
65    /// * `config` - Configuration for the WebSocket streams client
66    ///
67    /// # Returns
68    ///
69    /// A new WebSocket streams client configured with the provided settings
70    #[must_use]
71    pub fn from_config(
72        mut config: ConfigurationWebsocketStreams,
73    ) -> websocket_streams::WebsocketStreamsHandle {
74        config.user_agent = build_user_agent("alpha");
75        if config.ws_url.is_none() {
76            config.ws_url = Some(ALPHA_WS_STREAMS_PROD_URL.to_string());
77        }
78        websocket_streams::WebsocketStreamsHandle::new(config)
79    }
80
81    /// Creates a WebSocket streams client configured for the production environment.
82    ///
83    /// # Arguments
84    ///
85    /// * `config` - Configuration for the WebSocket streams client
86    ///
87    /// # Returns
88    ///
89    /// A new WebSocket streams client configured for the production environment
90    #[must_use]
91    pub fn production(
92        mut config: ConfigurationWebsocketStreams,
93    ) -> websocket_streams::WebsocketStreamsHandle {
94        config.ws_url = Some(ALPHA_WS_STREAMS_PROD_URL.to_string());
95        AlphaWsStreams::from_config(config)
96    }
97}