nautilus_coinbase/common/
consts.rs1use std::{sync::LazyLock, time::Duration};
17
18use nautilus_model::identifiers::{ClientId, Venue};
19use ustr::Ustr;
20
21pub const COINBASE: &str = "COINBASE";
23
24pub static COINBASE_VENUE: LazyLock<Venue> = LazyLock::new(|| Venue::new(Ustr::from(COINBASE)));
26
27pub static COINBASE_CLIENT_ID: LazyLock<ClientId> =
29 LazyLock::new(|| ClientId::new(Ustr::from(COINBASE)));
30
31pub const REST_URL: &str = "https://api.coinbase.com";
32pub const REST_API_PATH: &str = "/api/v3/brokerage";
33pub const WS_URL: &str = "wss://advanced-trade-ws.coinbase.com";
34pub const WS_USER_URL: &str = "wss://advanced-trade-ws-user.coinbase.com";
35
36pub const REST_URL_SANDBOX: &str = "https://api-sandbox.coinbase.com";
37pub const WS_URL_SANDBOX: &str = "wss://advanced-trade-ws-sandbox.coinbase.com";
38pub const WS_USER_URL_SANDBOX: &str = "wss://advanced-trade-ws-user-sandbox.coinbase.com";
39
40pub const JWT_ISSUER: &str = "cdp";
41
42pub const JWT_EXPIRY_SECS: u64 = 120;
44
45pub const ORDER_CONFIG_MARKET_IOC: &str = "market_market_ioc";
46pub const ORDER_CONFIG_LIMIT_GTC: &str = "limit_limit_gtc";
47pub const ORDER_CONFIG_LIMIT_GTD: &str = "limit_limit_gtd";
48pub const ORDER_CONFIG_LIMIT_FOK: &str = "limit_limit_fok";
49pub const ORDER_CONFIG_STOP_LIMIT_GTC: &str = "stop_limit_stop_limit_gtc";
50pub const ORDER_CONFIG_STOP_LIMIT_GTD: &str = "stop_limit_stop_limit_gtd";
51pub const ORDER_CONFIG_BASE_SIZE: &str = "base_size";
52pub const ORDER_CONFIG_QUOTE_SIZE: &str = "quote_size";
53pub const ORDER_CONFIG_LIMIT_PRICE: &str = "limit_price";
54pub const ORDER_CONFIG_STOP_PRICE: &str = "stop_price";
55pub const ORDER_CONFIG_POST_ONLY: &str = "post_only";
56pub const ORDER_CONFIG_END_TIME: &str = "end_time";
57
58pub const ACCOUNTS_PAGE_LIMIT: &str = "250";
60
61pub const ORDER_STATUS_OPEN: &str = "OPEN";
64
65pub const QUERY_KEY_LIMIT: &str = "limit";
68pub const QUERY_KEY_CURSOR: &str = "cursor";
69pub const QUERY_KEY_PRODUCT_IDS: &str = "product_ids";
70pub const QUERY_KEY_ORDER_IDS: &str = "order_ids";
71pub const QUERY_KEY_ORDER_STATUS: &str = "order_status";
72pub const QUERY_KEY_START_DATE: &str = "start_date";
73pub const QUERY_KEY_END_DATE: &str = "end_date";
74pub const QUERY_KEY_START_SEQUENCE_TIMESTAMP: &str = "start_sequence_timestamp";
75pub const QUERY_KEY_END_SEQUENCE_TIMESTAMP: &str = "end_sequence_timestamp";
76
77pub const HTTP_TIMEOUT: Duration = Duration::from_secs(10);
78
79pub const WS_HEARTBEAT_SECS: u64 = 30;
81
82pub const RECONNECT_BASE_BACKOFF: Duration = Duration::from_millis(250);
83pub const RECONNECT_MAX_BACKOFF: Duration = Duration::from_secs(30);
84pub const RECONNECT_JITTER_MS: u64 = 200;
85pub const RECONNECT_BACKOFF_FACTOR: f64 = 2.0;
86pub const RECONNECT_TIMEOUT: Duration = Duration::from_secs(15);
87
88pub const WS_DISCONNECT_TIMEOUT: Duration = Duration::from_secs(5);
91
92pub const WS_SUBSCRIBE_DEADLINE: Duration = Duration::from_secs(5);
94
95#[cfg(test)]
96mod tests {
97 use rstest::rstest;
98
99 use super::*;
100
101 #[rstest]
102 fn test_venue_constant() {
103 assert_eq!(COINBASE_VENUE.as_str(), COINBASE);
104 }
105
106 #[rstest]
107 fn test_url_constants() {
108 assert!(REST_URL.starts_with("https://"));
109 assert!(WS_URL.starts_with("wss://"));
110 assert!(WS_USER_URL.starts_with("wss://"));
111 }
112
113 #[rstest]
114 fn test_timeout_constants() {
115 assert_eq!(HTTP_TIMEOUT, Duration::from_secs(10));
116 assert_eq!(WS_HEARTBEAT_SECS, 30);
117 assert_eq!(WS_SUBSCRIBE_DEADLINE, Duration::from_secs(5));
118 }
119
120 #[rstest]
121 fn test_order_configuration_constants() {
122 assert_eq!(ORDER_CONFIG_MARKET_IOC, "market_market_ioc");
123 assert_eq!(ORDER_CONFIG_LIMIT_GTC, "limit_limit_gtc");
124 assert_eq!(ORDER_CONFIG_LIMIT_GTD, "limit_limit_gtd");
125 assert_eq!(ORDER_CONFIG_LIMIT_FOK, "limit_limit_fok");
126 assert_eq!(ORDER_CONFIG_STOP_LIMIT_GTC, "stop_limit_stop_limit_gtc");
127 assert_eq!(ORDER_CONFIG_STOP_LIMIT_GTD, "stop_limit_stop_limit_gtd");
128 assert_eq!(ORDER_CONFIG_BASE_SIZE, "base_size");
129 assert_eq!(ORDER_CONFIG_QUOTE_SIZE, "quote_size");
130 assert_eq!(ORDER_CONFIG_LIMIT_PRICE, "limit_price");
131 assert_eq!(ORDER_CONFIG_STOP_PRICE, "stop_price");
132 assert_eq!(ORDER_CONFIG_POST_ONLY, "post_only");
133 assert_eq!(ORDER_CONFIG_END_TIME, "end_time");
134 }
135}