rusty_common/constants/
coinbase.rs1pub mod urls {
8 pub mod websocket {
10 pub const ADVANCED_PROD: &str = "wss://ws-feed.exchange.coinbase.com";
12
13 pub const ADVANCED_SANDBOX: &str = "wss://ws-feed-public.sandbox.exchange.coinbase.com";
15
16 pub const LEGACY_PROD: &str = "wss://ws-feed.pro.coinbase.com";
18
19 pub const LEGACY_SANDBOX: &str = "wss://ws-feed-public.sandbox.pro.coinbase.com";
21 }
22
23 pub mod rest {
25 pub const ADVANCED_PROD: &str = "https://api.coinbase.com/api/v3";
27
28 pub const ADVANCED_SANDBOX: &str = "https://api-public.sandbox.exchange.coinbase.com";
30
31 pub const LEGACY_PROD: &str = "https://api.exchange.coinbase.com";
33
34 pub const LEGACY_SANDBOX: &str = "https://api-public.sandbox.exchange.coinbase.com";
36 }
37
38 pub mod fix {
40 pub const PROD_HOST: &str = "fix-ord.exchange.coinbase.com";
42
43 pub const SANDBOX_HOST: &str = "fix-ord.sandbox.exchange.coinbase.com";
45
46 pub const PORT: u16 = 6121;
48
49 pub const MARKET_DATA_PROD_HOST: &str = "fix-md.exchange.coinbase.com";
51
52 pub const MARKET_DATA_SANDBOX_HOST: &str = "fix-md.sandbox.exchange.coinbase.com";
54
55 pub const MARKET_DATA_PORT: u16 = 6120;
57 }
58}
59
60pub mod rate_limits {
62 pub mod fix50 {
64 pub const NORMAL_RPS: u32 = 100;
66
67 pub const DISCONNECT_THRESHOLD: u32 = 200;
69
70 pub const LOGON_RPS: u32 = 2;
72
73 pub const MAX_BATCH_SIZE: usize = 15;
75 }
76
77 pub mod fix42 {
79 pub const ROLLING_SECOND_LIMIT: u32 = 50;
81
82 pub const BURST_LIMIT: u32 = 100;
84 }
85
86 pub mod rest {
88 pub const STANDARD_RPS: u32 = 10;
90
91 pub const MARKET_DATA_RPS: u32 = 100;
93 }
94
95 pub mod websocket {
97 pub const MESSAGE_RPS: u32 = 100;
99
100 pub const SUBSCRIPTION_RPS: u32 = 10;
102 }
103}
104
105pub mod versions {
107 pub mod fix {
109 pub const SESSION_VERSION: &[u8] = b"FIXT.1.1";
111
112 pub const APPLICATION_VERSION: &[u8] = b"9";
114
115 pub const TARGET_COMP_ID: &[u8] = b"Coinbase";
117
118 pub const HEARTBEAT_INTERVAL: u32 = 30;
120 }
121
122 pub mod rest {
124 pub const ADVANCED_TRADE: &str = "v3";
126
127 pub const LEGACY_EXCHANGE: &str = "v1";
129 }
130}
131
132pub mod limits {
134 pub mod fix {
136 pub const MAX_MESSAGE_SIZE: usize = 8192;
138
139 pub const MAX_OPEN_ORDERS: usize = 500;
141 }
142
143 pub mod websocket {
145 pub const MAX_FRAME_SIZE: usize = 65536; pub const MAX_MESSAGE_SIZE: usize = 10 * 1024 * 1024; }
151}
152
153#[derive(Debug, Clone, Copy, PartialEq, Eq)]
156pub enum Environment {
157 Production,
159 Sandbox,
161}
162
163impl Environment {
164 pub const fn websocket_url(self) -> &'static str {
166 match self {
167 Environment::Production => urls::websocket::ADVANCED_PROD,
168 Environment::Sandbox => urls::websocket::ADVANCED_SANDBOX,
169 }
170 }
171
172 pub const fn rest_url(self) -> &'static str {
174 match self {
175 Environment::Production => urls::rest::ADVANCED_PROD,
176 Environment::Sandbox => urls::rest::ADVANCED_SANDBOX,
177 }
178 }
179
180 pub const fn fix_host(self) -> &'static str {
182 match self {
183 Environment::Production => urls::fix::PROD_HOST,
184 Environment::Sandbox => urls::fix::SANDBOX_HOST,
185 }
186 }
187
188 pub const fn fix_port(self) -> u16 {
190 urls::fix::PORT
191 }
192}
193
194#[cfg(test)]
195mod tests {
196 use super::*;
197
198 #[test]
199 fn test_environment_urls() {
200 assert_eq!(
201 Environment::Production.websocket_url(),
202 "wss://ws-feed.exchange.coinbase.com"
203 );
204 assert_eq!(
205 Environment::Sandbox.websocket_url(),
206 "wss://ws-feed-public.sandbox.exchange.coinbase.com"
207 );
208 }
209
210 #[test]
211 fn test_rate_limits() {
212 assert_eq!(rate_limits::fix50::NORMAL_RPS, 100);
213 assert_eq!(rate_limits::fix50::DISCONNECT_THRESHOLD, 200);
214 assert_eq!(rate_limits::fix50::MAX_BATCH_SIZE, 15);
215 }
216
217 #[test]
218 fn test_fix_constants() {
219 assert_eq!(versions::fix::SESSION_VERSION, b"FIXT.1.1");
220 assert_eq!(versions::fix::APPLICATION_VERSION, b"9");
221 assert_eq!(versions::fix::TARGET_COMP_ID, b"Coinbase");
222 }
223}