Skip to main content

oanda_client/
environment.rs

1//! Paired REST and streaming environments.
2
3use crate::{Error, Result};
4use url::Url;
5
6/// OANDA account environment.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum Environment {
9    /// fxTrade Practice.
10    Practice,
11    /// fxTrade Live.
12    Live,
13}
14
15impl Environment {
16    pub(crate) fn urls(self) -> Result<(Url, Url)> {
17        let (rest, stream) = match self {
18            Self::Practice => (
19                "https://api-fxpractice.oanda.com",
20                "https://stream-fxpractice.oanda.com",
21            ),
22            Self::Live => (
23                "https://api-fxtrade.oanda.com",
24                "https://stream-fxtrade.oanda.com",
25            ),
26        };
27        Ok((
28            Url::parse(rest).map_err(|e| Error::InvalidInput(e.to_string()))?,
29            Url::parse(stream).map_err(|e| Error::InvalidInput(e.to_string()))?,
30        ))
31    }
32}