alpaca-data 0.10.2

High-performance Rust client for Alpaca Market Data API
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
use std::borrow::Cow;

use crate::crypto::Loc;

#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub(crate) enum Endpoint {
    CryptoBars { loc: Loc },
    CryptoQuotes { loc: Loc },
    CryptoTrades { loc: Loc },
    CryptoLatestBars { loc: Loc },
    CryptoLatestQuotes { loc: Loc },
    CryptoLatestTrades { loc: Loc },
    CryptoLatestOrderbooks { loc: Loc },
    CryptoSnapshots { loc: Loc },
    NewsList,
    OptionsBars,
    OptionsConditionCodes { ticktype: &'static str },
    OptionsTrades,
    OptionsLatestQuotes,
    OptionsLatestTrades,
    OptionsSnapshots,
    OptionsChain { underlying_symbol: String },
    OptionsExchangeCodes,
    StocksBars,
    StocksAuctions,
    StocksQuotes,
    StocksTrades,
    StocksBarsSingle { symbol: String },
    StocksAuctionsSingle { symbol: String },
    StocksQuotesSingle { symbol: String },
    StocksTradesSingle { symbol: String },
    StocksLatestBars,
    StocksLatestQuotes,
    StocksLatestTrades,
    StocksLatestBar { symbol: String },
    StocksLatestQuote { symbol: String },
    StocksLatestTrade { symbol: String },
    StocksSnapshots,
    StocksSnapshot { symbol: String },
    StocksConditionCodes { ticktype: &'static str },
    StocksExchangeCodes,
    CorporateActionsList,
}

#[allow(dead_code)]
impl Endpoint {
    pub(crate) fn crypto_bars(loc: Loc) -> Self {
        Self::CryptoBars { loc }
    }

    pub(crate) fn crypto_quotes(loc: Loc) -> Self {
        Self::CryptoQuotes { loc }
    }

    pub(crate) fn crypto_trades(loc: Loc) -> Self {
        Self::CryptoTrades { loc }
    }

    pub(crate) fn crypto_latest_quotes(loc: Loc) -> Self {
        Self::CryptoLatestQuotes { loc }
    }

    pub(crate) fn crypto_latest_bars(loc: Loc) -> Self {
        Self::CryptoLatestBars { loc }
    }

    pub(crate) fn crypto_latest_trades(loc: Loc) -> Self {
        Self::CryptoLatestTrades { loc }
    }

    pub(crate) fn crypto_latest_orderbooks(loc: Loc) -> Self {
        Self::CryptoLatestOrderbooks { loc }
    }

    pub(crate) fn crypto_snapshots(loc: Loc) -> Self {
        Self::CryptoSnapshots { loc }
    }

    pub(crate) fn options_bars() -> Self {
        Self::OptionsBars
    }

    pub(crate) fn options_condition_codes(ticktype: &'static str) -> Self {
        Self::OptionsConditionCodes { ticktype }
    }

    pub(crate) fn options_trades() -> Self {
        Self::OptionsTrades
    }

    pub(crate) fn options_latest_quotes() -> Self {
        Self::OptionsLatestQuotes
    }

    pub(crate) fn options_latest_trades() -> Self {
        Self::OptionsLatestTrades
    }

    pub(crate) fn options_snapshots() -> Self {
        Self::OptionsSnapshots
    }

    pub(crate) fn options_chain(underlying_symbol: impl Into<String>) -> Self {
        Self::OptionsChain {
            underlying_symbol: underlying_symbol.into(),
        }
    }

    pub(crate) fn options_exchange_codes() -> Self {
        Self::OptionsExchangeCodes
    }

    pub(crate) fn stocks_bars() -> Self {
        Self::StocksBars
    }

    pub(crate) fn stocks_auctions() -> Self {
        Self::StocksAuctions
    }

    pub(crate) fn stocks_bars_single(symbol: impl Into<String>) -> Self {
        Self::StocksBarsSingle {
            symbol: symbol.into(),
        }
    }

    pub(crate) fn stocks_auctions_single(symbol: impl Into<String>) -> Self {
        Self::StocksAuctionsSingle {
            symbol: symbol.into(),
        }
    }

    pub(crate) fn stocks_latest_quote(symbol: impl Into<String>) -> Self {
        Self::StocksLatestQuote {
            symbol: symbol.into(),
        }
    }

    pub(crate) fn stocks_snapshot(symbol: impl Into<String>) -> Self {
        Self::StocksSnapshot {
            symbol: symbol.into(),
        }
    }

    pub(crate) fn name(&self) -> &'static str {
        match self {
            Self::CryptoBars { .. } => "crypto.bars",
            Self::CryptoQuotes { .. } => "crypto.quotes",
            Self::CryptoTrades { .. } => "crypto.trades",
            Self::CryptoLatestBars { .. } => "crypto.latest_bars",
            Self::CryptoLatestQuotes { .. } => "crypto.latest_quotes",
            Self::CryptoLatestTrades { .. } => "crypto.latest_trades",
            Self::CryptoLatestOrderbooks { .. } => "crypto.latest_orderbooks",
            Self::CryptoSnapshots { .. } => "crypto.snapshots",
            Self::NewsList => "news.list",
            Self::OptionsBars => "options.bars",
            Self::OptionsConditionCodes { .. } => "options.condition_codes",
            Self::OptionsTrades => "options.trades",
            Self::OptionsLatestQuotes => "options.latest_quotes",
            Self::OptionsLatestTrades => "options.latest_trades",
            Self::OptionsSnapshots => "options.snapshots",
            Self::OptionsChain { .. } => "options.chain",
            Self::OptionsExchangeCodes => "options.exchange_codes",
            Self::StocksBars => "stocks.bars",
            Self::StocksAuctions => "stocks.auctions",
            Self::StocksQuotes => "stocks.quotes",
            Self::StocksTrades => "stocks.trades",
            Self::StocksBarsSingle { .. } => "stocks.bars_single",
            Self::StocksAuctionsSingle { .. } => "stocks.auctions_single",
            Self::StocksQuotesSingle { .. } => "stocks.quotes_single",
            Self::StocksTradesSingle { .. } => "stocks.trades_single",
            Self::StocksLatestBars => "stocks.latest_bars",
            Self::StocksLatestQuotes => "stocks.latest_quotes",
            Self::StocksLatestTrades => "stocks.latest_trades",
            Self::StocksLatestBar { .. } => "stocks.latest_bar_single",
            Self::StocksLatestQuote { .. } => "stocks.latest_quote_single",
            Self::StocksLatestTrade { .. } => "stocks.latest_trade_single",
            Self::StocksSnapshots => "stocks.snapshots",
            Self::StocksSnapshot { .. } => "stocks.snapshot_single",
            Self::StocksConditionCodes { .. } => "stocks.condition_codes",
            Self::StocksExchangeCodes => "stocks.exchange_codes",
            Self::CorporateActionsList => "corporate_actions.list",
        }
    }

    pub(crate) fn path(&self) -> Cow<'_, str> {
        match self {
            Self::CryptoBars { loc } => Cow::Owned(format!("/v1beta3/crypto/{loc}/bars")),
            Self::CryptoQuotes { loc } => Cow::Owned(format!("/v1beta3/crypto/{loc}/quotes")),
            Self::CryptoTrades { loc } => Cow::Owned(format!("/v1beta3/crypto/{loc}/trades")),
            Self::CryptoLatestBars { loc } => {
                Cow::Owned(format!("/v1beta3/crypto/{loc}/latest/bars"))
            }
            Self::CryptoLatestQuotes { loc: Loc::Us } => {
                Cow::Borrowed("/v1beta3/crypto/us/latest/quotes")
            }
            Self::CryptoLatestQuotes { loc: Loc::Us1 } => {
                Cow::Borrowed("/v1beta3/crypto/us-1/latest/quotes")
            }
            Self::CryptoLatestQuotes { loc: Loc::Us2 } => {
                Cow::Borrowed("/v1beta3/crypto/us-2/latest/quotes")
            }
            Self::CryptoLatestQuotes { loc: Loc::Eu1 } => {
                Cow::Borrowed("/v1beta3/crypto/eu-1/latest/quotes")
            }
            Self::CryptoLatestQuotes { loc: Loc::Bs1 } => {
                Cow::Borrowed("/v1beta3/crypto/bs-1/latest/quotes")
            }
            Self::CryptoLatestTrades { loc } => {
                Cow::Owned(format!("/v1beta3/crypto/{loc}/latest/trades"))
            }
            Self::CryptoLatestOrderbooks { loc } => {
                Cow::Owned(format!("/v1beta3/crypto/{loc}/latest/orderbooks"))
            }
            Self::CryptoSnapshots { loc } => Cow::Owned(format!("/v1beta3/crypto/{loc}/snapshots")),
            Self::NewsList => Cow::Borrowed("/v1beta1/news"),
            Self::OptionsBars => Cow::Borrowed("/v1beta1/options/bars"),
            Self::OptionsConditionCodes { ticktype } => {
                Cow::Owned(format!("/v1beta1/options/meta/conditions/{ticktype}"))
            }
            Self::OptionsTrades => Cow::Borrowed("/v1beta1/options/trades"),
            Self::OptionsLatestQuotes => Cow::Borrowed("/v1beta1/options/quotes/latest"),
            Self::OptionsLatestTrades => Cow::Borrowed("/v1beta1/options/trades/latest"),
            Self::OptionsSnapshots => Cow::Borrowed("/v1beta1/options/snapshots"),
            Self::OptionsChain { underlying_symbol } => {
                Cow::Owned(format!("/v1beta1/options/snapshots/{underlying_symbol}"))
            }
            Self::OptionsExchangeCodes => Cow::Borrowed("/v1beta1/options/meta/exchanges"),
            Self::StocksBars => Cow::Borrowed("/v2/stocks/bars"),
            Self::StocksAuctions => Cow::Borrowed("/v2/stocks/auctions"),
            Self::StocksQuotes => Cow::Borrowed("/v2/stocks/quotes"),
            Self::StocksTrades => Cow::Borrowed("/v2/stocks/trades"),
            Self::StocksBarsSingle { symbol } => Cow::Owned(format!("/v2/stocks/{symbol}/bars")),
            Self::StocksAuctionsSingle { symbol } => {
                Cow::Owned(format!("/v2/stocks/{symbol}/auctions"))
            }
            Self::StocksQuotesSingle { symbol } => {
                Cow::Owned(format!("/v2/stocks/{symbol}/quotes"))
            }
            Self::StocksTradesSingle { symbol } => {
                Cow::Owned(format!("/v2/stocks/{symbol}/trades"))
            }
            Self::StocksLatestBars => Cow::Borrowed("/v2/stocks/bars/latest"),
            Self::StocksLatestQuotes => Cow::Borrowed("/v2/stocks/quotes/latest"),
            Self::StocksLatestTrades => Cow::Borrowed("/v2/stocks/trades/latest"),
            Self::StocksLatestBar { symbol } => {
                Cow::Owned(format!("/v2/stocks/{symbol}/bars/latest"))
            }
            Self::StocksLatestQuote { symbol } => {
                Cow::Owned(format!("/v2/stocks/{symbol}/quotes/latest"))
            }
            Self::StocksLatestTrade { symbol } => {
                Cow::Owned(format!("/v2/stocks/{symbol}/trades/latest"))
            }
            Self::StocksSnapshots => Cow::Borrowed("/v2/stocks/snapshots"),
            Self::StocksSnapshot { symbol } => Cow::Owned(format!("/v2/stocks/{symbol}/snapshot")),
            Self::StocksConditionCodes { ticktype } => {
                Cow::Owned(format!("/v2/stocks/meta/conditions/{ticktype}"))
            }
            Self::StocksExchangeCodes => Cow::Borrowed("/v2/stocks/meta/exchanges"),
            Self::CorporateActionsList => Cow::Borrowed("/v1/corporate-actions"),
        }
    }

    pub(crate) fn requires_auth(&self) -> bool {
        match self {
            Self::CryptoBars { .. }
            | Self::CryptoQuotes { .. }
            | Self::CryptoTrades { .. }
            | Self::CryptoLatestBars { .. }
            | Self::CryptoLatestQuotes { .. } => false,
            Self::CryptoLatestTrades { .. }
            | Self::CryptoLatestOrderbooks { .. }
            | Self::CryptoSnapshots { .. } => false,
            Self::OptionsBars
            | Self::NewsList
            | Self::OptionsConditionCodes { .. }
            | Self::OptionsTrades
            | Self::OptionsLatestQuotes
            | Self::OptionsLatestTrades
            | Self::OptionsSnapshots
            | Self::OptionsChain { .. }
            | Self::OptionsExchangeCodes
            | Self::StocksBars
            | Self::StocksAuctions
            | Self::StocksQuotes
            | Self::StocksTrades
            | Self::StocksBarsSingle { .. }
            | Self::StocksAuctionsSingle { .. }
            | Self::StocksQuotesSingle { .. }
            | Self::StocksTradesSingle { .. }
            | Self::StocksLatestBars
            | Self::StocksLatestQuotes
            | Self::StocksLatestTrades
            | Self::StocksLatestBar { .. }
            | Self::StocksLatestQuote { .. }
            | Self::StocksLatestTrade { .. }
            | Self::StocksSnapshots
            | Self::StocksSnapshot { .. }
            | Self::StocksConditionCodes { .. }
            | Self::StocksExchangeCodes
            | Self::CorporateActionsList => true,
        }
    }
}

#[cfg(test)]
mod tests {
    use std::borrow::Cow;

    use super::Endpoint;
    use crate::crypto::Loc;

    #[test]
    fn endpoint_routes_crypto_latest_quotes_to_official_path() {
        let endpoint = Endpoint::crypto_latest_quotes(Loc::Us);

        assert_eq!(endpoint.path(), "/v1beta3/crypto/us/latest/quotes");
        assert!(!endpoint.requires_auth());
    }

    #[test]
    fn endpoint_routes_crypto_historical_paths_with_official_loc_words() {
        assert_eq!(
            Endpoint::crypto_bars(Loc::Us).path(),
            "/v1beta3/crypto/us/bars"
        );
        assert_eq!(
            Endpoint::crypto_quotes(Loc::Us1).path(),
            "/v1beta3/crypto/us-1/quotes"
        );
        assert_eq!(
            Endpoint::crypto_trades(Loc::Eu1).path(),
            "/v1beta3/crypto/eu-1/trades"
        );
        assert!(!Endpoint::crypto_bars(Loc::Eu1).requires_auth());
    }

    #[test]
    fn endpoint_routes_news_and_corporate_actions_to_official_paths() {
        assert_eq!(Endpoint::NewsList.path(), "/v1beta1/news");
        assert!(Endpoint::NewsList.requires_auth());
        assert_eq!(
            Endpoint::CorporateActionsList.path(),
            "/v1/corporate-actions"
        );
        assert!(Endpoint::CorporateActionsList.requires_auth());
    }

    #[test]
    fn endpoint_names_are_stable_for_representative_routes() {
        assert_eq!(Endpoint::StocksSnapshots.name(), "stocks.snapshots");
        assert_eq!(
            Endpoint::stocks_latest_quote("AAPL").name(),
            "stocks.latest_quote_single"
        );
        assert_eq!(Endpoint::options_chain("AAPL").name(), "options.chain");
        assert_eq!(
            Endpoint::crypto_latest_quotes(Loc::Us).name(),
            "crypto.latest_quotes"
        );
        assert_eq!(Endpoint::NewsList.name(), "news.list");
        assert_eq!(
            Endpoint::CorporateActionsList.name(),
            "corporate_actions.list"
        );
    }

    #[test]
    fn endpoint_routes_crypto_latest_paths_with_official_loc_words() {
        assert_eq!(
            Endpoint::crypto_latest_bars(Loc::Us).path(),
            "/v1beta3/crypto/us/latest/bars"
        );
        assert_eq!(
            Endpoint::crypto_latest_quotes(Loc::Us1).path(),
            "/v1beta3/crypto/us-1/latest/quotes"
        );
        assert_eq!(
            Endpoint::crypto_latest_quotes(Loc::Us2).path(),
            "/v1beta3/crypto/us-2/latest/quotes"
        );
        assert_eq!(
            Endpoint::crypto_latest_quotes(Loc::Bs1).path(),
            "/v1beta3/crypto/bs-1/latest/quotes"
        );
        assert_eq!(
            Endpoint::crypto_latest_trades(Loc::Eu1).path(),
            "/v1beta3/crypto/eu-1/latest/trades"
        );
        assert_eq!(
            Endpoint::crypto_latest_orderbooks(Loc::Us).path(),
            "/v1beta3/crypto/us/latest/orderbooks"
        );
        assert!(!Endpoint::crypto_latest_orderbooks(Loc::Eu1).requires_auth());
    }

    #[test]
    fn endpoint_routes_crypto_snapshots_with_official_loc_words() {
        assert_eq!(
            Endpoint::crypto_snapshots(Loc::Us).path(),
            "/v1beta3/crypto/us/snapshots"
        );
        assert_eq!(
            Endpoint::crypto_snapshots(Loc::Us1).path(),
            "/v1beta3/crypto/us-1/snapshots"
        );
        assert_eq!(
            Endpoint::crypto_snapshots(Loc::Eu1).path(),
            "/v1beta3/crypto/eu-1/snapshots"
        );
        assert!(!Endpoint::crypto_snapshots(Loc::Eu1).requires_auth());
    }

    #[test]
    fn endpoint_routes_stocks_batch_and_single_paths() {
        assert_eq!(Endpoint::stocks_auctions().path(), "/v2/stocks/auctions");
        assert_eq!(Endpoint::stocks_bars().path(), "/v2/stocks/bars");
        assert_eq!(
            Endpoint::stocks_auctions_single("AAPL").path(),
            "/v2/stocks/AAPL/auctions"
        );
        assert_eq!(
            Endpoint::stocks_bars_single("AAPL").path(),
            "/v2/stocks/AAPL/bars"
        );
        assert_eq!(
            Endpoint::stocks_latest_quote("AAPL").path(),
            "/v2/stocks/AAPL/quotes/latest"
        );
        assert_eq!(
            Endpoint::stocks_snapshot("AAPL").path(),
            "/v2/stocks/AAPL/snapshot"
        );
    }

    #[test]
    fn endpoint_routes_options_historical_paths() {
        assert_eq!(Endpoint::options_bars().path(), "/v1beta1/options/bars");
        assert_eq!(Endpoint::options_trades().path(), "/v1beta1/options/trades");
        assert_eq!(
            Endpoint::options_latest_quotes().path(),
            "/v1beta1/options/quotes/latest"
        );
        assert_eq!(
            Endpoint::options_latest_trades().path(),
            "/v1beta1/options/trades/latest"
        );
        assert_eq!(
            Endpoint::options_snapshots().path(),
            "/v1beta1/options/snapshots"
        );
        assert_eq!(
            Endpoint::options_chain("AAPL").path(),
            "/v1beta1/options/snapshots/AAPL"
        );
        assert_eq!(
            Endpoint::options_exchange_codes().path(),
            "/v1beta1/options/meta/exchanges"
        );
        assert_eq!(
            Endpoint::options_condition_codes("trade").path(),
            "/v1beta1/options/meta/conditions/trade"
        );
    }

    #[test]
    fn endpoint_keeps_static_paths_borrowed() {
        assert!(matches!(
            Endpoint::crypto_latest_quotes(Loc::Us).path(),
            Cow::Borrowed("/v1beta3/crypto/us/latest/quotes")
        ));
        assert!(matches!(
            Endpoint::StocksAuctions.path(),
            Cow::Borrowed("/v2/stocks/auctions")
        ));
        assert!(matches!(
            Endpoint::StocksBars.path(),
            Cow::Borrowed("/v2/stocks/bars")
        ));
        assert!(matches!(
            Endpoint::StocksQuotes.path(),
            Cow::Borrowed("/v2/stocks/quotes")
        ));
        assert!(matches!(
            Endpoint::StocksTrades.path(),
            Cow::Borrowed("/v2/stocks/trades")
        ));
        assert!(matches!(
            Endpoint::StocksLatestBars.path(),
            Cow::Borrowed("/v2/stocks/bars/latest")
        ));
        assert!(matches!(
            Endpoint::StocksLatestQuotes.path(),
            Cow::Borrowed("/v2/stocks/quotes/latest")
        ));
        assert!(matches!(
            Endpoint::StocksLatestTrades.path(),
            Cow::Borrowed("/v2/stocks/trades/latest")
        ));
        assert!(matches!(
            Endpoint::StocksSnapshots.path(),
            Cow::Borrowed("/v2/stocks/snapshots")
        ));
        assert!(matches!(
            Endpoint::StocksExchangeCodes.path(),
            Cow::Borrowed("/v2/stocks/meta/exchanges")
        ));
    }

    #[test]
    fn endpoint_routes_all_stocks_dynamic_paths_and_marks_them_authenticated() {
        let cases = [
            (
                Endpoint::StocksAuctionsSingle {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/auctions",
            ),
            (
                Endpoint::StocksBarsSingle {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/bars",
            ),
            (
                Endpoint::StocksQuotesSingle {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/quotes",
            ),
            (
                Endpoint::StocksTradesSingle {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/trades",
            ),
            (
                Endpoint::StocksLatestBar {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/bars/latest",
            ),
            (
                Endpoint::StocksLatestQuote {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/quotes/latest",
            ),
            (
                Endpoint::StocksLatestTrade {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/trades/latest",
            ),
            (
                Endpoint::StocksSnapshot {
                    symbol: "AAPL".into(),
                },
                "/v2/stocks/AAPL/snapshot",
            ),
            (
                Endpoint::StocksConditionCodes { ticktype: "trade" },
                "/v2/stocks/meta/conditions/trade",
            ),
            (
                Endpoint::OptionsConditionCodes { ticktype: "trade" },
                "/v1beta1/options/meta/conditions/trade",
            ),
        ];

        for (endpoint, expected_path) in cases {
            assert!(matches!(endpoint.path(), Cow::Owned(_)));
            assert_eq!(endpoint.path(), expected_path);
            assert!(endpoint.requires_auth());
        }
    }

    #[test]
    fn endpoint_requires_auth_for_all_stocks_batch_routes() {
        let cases = [
            Endpoint::StocksAuctions,
            Endpoint::StocksBars,
            Endpoint::StocksQuotes,
            Endpoint::StocksTrades,
            Endpoint::StocksLatestBars,
            Endpoint::StocksLatestQuotes,
            Endpoint::StocksLatestTrades,
            Endpoint::StocksSnapshots,
            Endpoint::StocksExchangeCodes,
        ];

        for endpoint in cases {
            assert!(endpoint.requires_auth());
        }

        assert!(!Endpoint::crypto_latest_quotes(Loc::Us1).requires_auth());
    }

    #[test]
    fn endpoint_requires_auth_for_options_historical_routes() {
        let cases = [
            Endpoint::OptionsBars,
            Endpoint::OptionsTrades,
            Endpoint::OptionsLatestQuotes,
            Endpoint::OptionsLatestTrades,
            Endpoint::OptionsSnapshots,
            Endpoint::OptionsExchangeCodes,
        ];

        for endpoint in cases {
            assert!(endpoint.requires_auth());
            assert!(matches!(endpoint.path(), Cow::Borrowed(_)));
        }

        let endpoint = Endpoint::options_chain("AAPL");
        assert!(endpoint.requires_auth());
        assert!(matches!(endpoint.path(), Cow::Owned(_)));

        let endpoint = Endpoint::OptionsConditionCodes { ticktype: "quote" };
        assert!(endpoint.requires_auth());
        assert!(matches!(endpoint.path(), Cow::Owned(_)));
    }
}