pub struct ParsedSymbol {
pub base: String,
pub quote: String,
pub settle: Option<String>,
pub expiry: Option<ExpiryDate>,
}Expand description
Represents a parsed unified symbol with all components
This struct holds all the components of a unified symbol:
base: Base currency (e.g., “BTC”)quote: Quote currency (e.g., “USDT”)settle: Settlement currency for derivatives (e.g., “USDT” or “BTC”)expiry: Expiry date for futures contracts
§Example
use ccxt_core::types::symbol::{ParsedSymbol, ExpiryDate, SymbolMarketType};
// Spot symbol
let spot = ParsedSymbol::spot("BTC".to_string(), "USDT".to_string());
assert_eq!(spot.to_string(), "BTC/USDT");
// Linear swap
let swap = ParsedSymbol::linear_swap("BTC".to_string(), "USDT".to_string());
assert_eq!(swap.to_string(), "BTC/USDT:USDT");
// Futures with expiry
let expiry = ExpiryDate::new(24, 12, 31).unwrap();
let futures = ParsedSymbol::futures("BTC".to_string(), "USDT".to_string(), "USDT".to_string(), expiry);
assert_eq!(futures.to_string(), "BTC/USDT:USDT-241231");Fields§
§base: StringBase currency (e.g., “BTC”)
quote: StringQuote currency (e.g., “USDT”)
settle: Option<String>Settlement currency for derivatives (e.g., “USDT” or “BTC”)
expiry: Option<ExpiryDate>Expiry date for futures contracts
Implementations§
Source§impl ParsedSymbol
impl ParsedSymbol
Sourcepub fn linear_swap(
base: impl AsRef<str>,
quote: impl AsRef<str>,
) -> ParsedSymbol
pub fn linear_swap( base: impl AsRef<str>, quote: impl AsRef<str>, ) -> ParsedSymbol
Create a new linear swap symbol (settled in quote currency)
§Arguments
base- Base currency code (e.g., “BTC”)quote- Quote currency code (e.g., “USDT”)
§Example
use ccxt_core::types::symbol::ParsedSymbol;
let symbol = ParsedSymbol::linear_swap("BTC".to_string(), "USDT".to_string());
assert_eq!(symbol.to_string(), "BTC/USDT:USDT");Sourcepub fn inverse_swap(
base: impl AsRef<str>,
quote: impl AsRef<str>,
) -> ParsedSymbol
pub fn inverse_swap( base: impl AsRef<str>, quote: impl AsRef<str>, ) -> ParsedSymbol
Create a new inverse swap symbol (settled in base currency)
§Arguments
base- Base currency code (e.g., “BTC”)quote- Quote currency code (e.g., “USD”)
§Example
use ccxt_core::types::symbol::ParsedSymbol;
let symbol = ParsedSymbol::inverse_swap("BTC".to_string(), "USD".to_string());
assert_eq!(symbol.to_string(), "BTC/USD:BTC");Sourcepub fn swap(
base: impl AsRef<str>,
quote: impl AsRef<str>,
settle: impl AsRef<str>,
) -> ParsedSymbol
pub fn swap( base: impl AsRef<str>, quote: impl AsRef<str>, settle: impl AsRef<str>, ) -> ParsedSymbol
Create a new swap symbol with explicit settlement currency
§Arguments
base- Base currency codequote- Quote currency codesettle- Settlement currency code
Sourcepub fn futures(
base: impl AsRef<str>,
quote: impl AsRef<str>,
settle: impl AsRef<str>,
expiry: ExpiryDate,
) -> ParsedSymbol
pub fn futures( base: impl AsRef<str>, quote: impl AsRef<str>, settle: impl AsRef<str>, expiry: ExpiryDate, ) -> ParsedSymbol
Create a new futures symbol
§Arguments
base- Base currency codequote- Quote currency codesettle- Settlement currency codeexpiry- Expiry date
§Example
use ccxt_core::types::symbol::{ParsedSymbol, ExpiryDate};
let expiry = ExpiryDate::new(24, 12, 31).unwrap();
let symbol = ParsedSymbol::futures("BTC".to_string(), "USDT".to_string(), "USDT".to_string(), expiry);
assert_eq!(symbol.to_string(), "BTC/USDT:USDT-241231");Sourcepub fn market_type(&self) -> SymbolMarketType
pub fn market_type(&self) -> SymbolMarketType
Determine the market type from symbol structure
- No settle and no expiry → Spot
- Has settle but no expiry → Swap
- Has settle and expiry → Futures
Sourcepub fn contract_type(&self) -> Option<ContractType>
pub fn contract_type(&self) -> Option<ContractType>
Determine if this is a linear or inverse contract
Returns None for spot markets.
- Linear: settle == quote
- Inverse: settle == base
Sourcepub fn is_futures(&self) -> bool
pub fn is_futures(&self) -> bool
Check if this is a futures symbol
Sourcepub fn is_derivative(&self) -> bool
pub fn is_derivative(&self) -> bool
Check if this is a derivative (swap or futures)
Sourcepub fn is_inverse(&self) -> bool
pub fn is_inverse(&self) -> bool
Check if this is an inverse contract
Trait Implementations§
Source§impl Clone for ParsedSymbol
impl Clone for ParsedSymbol
Source§fn clone(&self) -> ParsedSymbol
fn clone(&self) -> ParsedSymbol
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParsedSymbol
impl Debug for ParsedSymbol
Source§impl Default for ParsedSymbol
impl Default for ParsedSymbol
Source§fn default() -> ParsedSymbol
fn default() -> ParsedSymbol
Source§impl<'de> Deserialize<'de> for ParsedSymbol
impl<'de> Deserialize<'de> for ParsedSymbol
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ParsedSymbol, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ParsedSymbol, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for ParsedSymbol
impl Display for ParsedSymbol
Source§impl FromStr for ParsedSymbol
Implement FromStr for ParsedSymbol to enable string parsing
impl FromStr for ParsedSymbol
Implement FromStr for ParsedSymbol to enable string parsing
Source§type Err = SymbolError
type Err = SymbolError
Source§fn from_str(s: &str) -> Result<ParsedSymbol, <ParsedSymbol as FromStr>::Err>
fn from_str(s: &str) -> Result<ParsedSymbol, <ParsedSymbol as FromStr>::Err>
s to return a value of this type. Read moreSource§impl Hash for ParsedSymbol
impl Hash for ParsedSymbol
Source§impl PartialEq for ParsedSymbol
impl PartialEq for ParsedSymbol
Source§impl Serialize for ParsedSymbol
impl Serialize for ParsedSymbol
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for ParsedSymbol
Auto Trait Implementations§
impl Freeze for ParsedSymbol
impl RefUnwindSafe for ParsedSymbol
impl Send for ParsedSymbol
impl Sync for ParsedSymbol
impl Unpin for ParsedSymbol
impl UnwindSafe for ParsedSymbol
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.