pub struct SymbolFormatter;Expand description
Symbol formatter for converting ParsedSymbol to unified symbol strings
Provides methods to format ParsedSymbol structures into their
canonical unified symbol string representation.
Implementations§
Source§impl SymbolFormatter
impl SymbolFormatter
Sourcepub fn format(parsed: &ParsedSymbol) -> String
pub fn format(parsed: &ParsedSymbol) -> String
Format a ParsedSymbol into a unified symbol string
§Arguments
parsed- The parsed symbol to format
§Returns
Returns the unified symbol string in the appropriate format:
- Spot:
BASE/QUOTE - Swap:
BASE/QUOTE:SETTLE - Futures:
BASE/QUOTE:SETTLE-YYMMDD
§Examples
use ccxt_core::symbol::{ParsedSymbol, SymbolFormatter};
use ccxt_core::types::symbol::ExpiryDate;
// Spot symbol
let spot = ParsedSymbol::spot("BTC".to_string(), "USDT".to_string());
assert_eq!(SymbolFormatter::format(&spot), "BTC/USDT");
// Linear swap symbol
let swap = ParsedSymbol::linear_swap("ETH".to_string(), "USDT".to_string());
assert_eq!(SymbolFormatter::format(&swap), "ETH/USDT:USDT");
// Inverse swap symbol
let inverse = ParsedSymbol::inverse_swap("BTC".to_string(), "USD".to_string());
assert_eq!(SymbolFormatter::format(&inverse), "BTC/USD:BTC");
// Futures symbol
let expiry = ExpiryDate::new(24, 12, 31).unwrap();
let futures = ParsedSymbol::futures("BTC".to_string(), "USDT".to_string(), "USDT".to_string(), expiry);
assert_eq!(SymbolFormatter::format(&futures), "BTC/USDT:USDT-241231");Sourcepub fn format_spot(base: &str, quote: &str) -> String
pub fn format_spot(base: &str, quote: &str) -> String
Sourcepub fn format_futures(
base: &str,
quote: &str,
settle: &str,
year: u8,
month: u8,
day: u8,
) -> String
pub fn format_futures( base: &str, quote: &str, settle: &str, year: u8, month: u8, day: u8, ) -> String
Format a futures symbol from base, quote, settle currencies and expiry date
§Arguments
base- Base currency codequote- Quote currency codesettle- Settlement currency codeyear- 2-digit year (0-99)month- Month (1-12)day- Day (1-31)
§Returns
Returns the formatted futures symbol string BASE/QUOTE:SETTLE-YYMMDD
Auto Trait Implementations§
impl Freeze for SymbolFormatter
impl RefUnwindSafe for SymbolFormatter
impl Send for SymbolFormatter
impl Sync for SymbolFormatter
impl Unpin for SymbolFormatter
impl UnwindSafe for SymbolFormatter
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
Mutably borrows from an owned value. Read more