pub struct MarketKey { /* private fields */ }Expand description
One instrument’s name, written venue.product:id, such as
acme.perp:ABCUSD.
A key has no public constructor from text or from parts. Only a product’s
KeySpace makes one, and it canonicalizes the id first, so two keys are
equal exactly when they name the same instrument. On an event-contract
venue a key names one outcome, not a market.
It serializes as its text form. To read one back, parse a RawKey and
hand it to the product’s constructors, which canonicalize it again.
use std::borrow::Cow;
use polyoxide_venue::{KeySpace, MarketKey, ProductClass, ProductId, RawKey, VenueId};
/// A perpetual whose ids are ASCII and uppercased.
struct Perp;
impl KeySpace for Perp {
const VENUE: VenueId = VenueId::from_static("acme");
const PRODUCT: ProductId = ProductId::from_static("perp");
const CLASS: ProductClass = ProductClass::PerpetualFuture;
type Id = PerpId;
fn parse_id(text: &str) -> Result<PerpId, String> {
if text.is_ascii() {
Ok(PerpId(text.to_ascii_uppercase()))
} else {
Err("an id is ASCII".into())
}
}
fn id_text(id: &PerpId) -> Cow<'_, str> {
Cow::Borrowed(&id.0)
}
}
/// An id in canonical form: only `Perp::parse_id` makes one.
struct PerpId(String);
let key = Perp::parse(&RawKey::parse("acme.perp:abcusd")?)?;
assert_eq!(key, Perp::key(&Perp::parse_id("ABCUSD")?));
assert_eq!(key.to_string(), "acme.perp:ABCUSD");
assert_eq!(key.class(), ProductClass::PerpetualFuture);Implementations§
Source§impl MarketKey
impl MarketKey
Sourcepub fn class(&self) -> ProductClass
pub fn class(&self) -> ProductClass
The product’s class, which its KeySpace::CLASS declares. It follows
from the venue and product, so the text form does not carry it.
Trait Implementations§
impl Eq for MarketKey
Source§impl Ord for MarketKey
impl Ord for MarketKey
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialOrd for MarketKey
impl PartialOrd for MarketKey
impl StructuralPartialEq for MarketKey
Auto Trait Implementations§
impl Freeze for MarketKey
impl RefUnwindSafe for MarketKey
impl Send for MarketKey
impl Sync for MarketKey
impl Unpin for MarketKey
impl UnsafeUnpin for MarketKey
impl UnwindSafe for MarketKey
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