pub struct HyperliquidAssetId(pub u32);Expand description
Represents an asset ID for Hyperliquid.
Asset IDs follow Hyperliquid’s convention:
- Perps: raw index into meta.universe (
0..10_000) - Spot:
10_000 + indexin spotMeta.universe (10_000..100_000) - Builder perps:
100_000 + dex_index * 10_000 + meta_index(100_000..100_000_000) - Outcomes (HIP-4):
100_000_000 + 10 * outcome + sidewhere side is0or1
Tuple Fields§
§0: u32Implementations§
Source§impl HyperliquidAssetId
impl HyperliquidAssetId
Sourcepub fn builder_perp(dex_index: u32, meta_index: u32) -> Self
pub fn builder_perp(dex_index: u32, meta_index: u32) -> Self
Creates a builder perpetual asset ID.
Sourcepub fn outcome(outcome: u32, side: u8) -> Self
pub fn outcome(outcome: u32, side: u8) -> Self
Creates an outcome (HIP-4) asset ID from outcome and side.
Encoding: 100_000_000 + 10 * outcome + side. Only sides 0 and 1
are valid for binary outcomes.
§Panics
Panics if side is not 0 or 1.
Sourcepub fn from_outcome_encoding(encoding: u32) -> Option<Self>
pub fn from_outcome_encoding(encoding: u32) -> Option<Self>
Creates an outcome (HIP-4) asset ID from an encoded 10 * outcome + side value.
Sourcepub fn is_builder_perp(self) -> bool
pub fn is_builder_perp(self) -> bool
Checks if this is a builder perp (100_000..100_000_000).
Sourcepub fn is_outcome(self) -> bool
pub fn is_outcome(self) -> bool
Checks if this is a valid outcome (HIP-4) asset.
Requires the id to be in the outcome range and have a valid side
digit (0 or 1). Ids in the range with side digits 2..=9 are
not valid HIP-4 outcomes per the protocol.
Sourcepub fn base_index(self) -> u32
pub fn base_index(self) -> u32
Gets the base index for the asset.
- Perp: raw index.
- Spot:
asset_id - 10_000. - Builder perp: meta index within the dex.
- Outcome: encoding
10 * outcome + side.
Sourcepub fn outcome_index(self) -> Option<u32>
pub fn outcome_index(self) -> Option<u32>
Returns the outcome number for an outcome asset, otherwise None.
Sourcepub fn outcome_side(self) -> Option<u8>
pub fn outcome_side(self) -> Option<u8>
Returns the outcome side (0 or 1) for an outcome asset, otherwise None.
Sourcepub fn outcome_encoding(self) -> Option<u32>
pub fn outcome_encoding(self) -> Option<u32>
Returns the outcome encoding (10 * outcome + side) for an outcome asset.
Trait Implementations§
Source§impl Clone for HyperliquidAssetId
impl Clone for HyperliquidAssetId
Source§fn clone(&self) -> HyperliquidAssetId
fn clone(&self) -> HyperliquidAssetId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HyperliquidAssetId
impl Debug for HyperliquidAssetId
Source§impl<'de> Deserialize<'de> for HyperliquidAssetId
impl<'de> Deserialize<'de> for HyperliquidAssetId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for HyperliquidAssetId
impl Display for HyperliquidAssetId
Source§impl Hash for HyperliquidAssetId
impl Hash for HyperliquidAssetId
Source§impl PartialEq for HyperliquidAssetId
impl PartialEq for HyperliquidAssetId
Source§fn eq(&self, other: &HyperliquidAssetId) -> bool
fn eq(&self, other: &HyperliquidAssetId) -> bool
self and other values to be equal, and is used by ==.Source§impl Serialize for HyperliquidAssetId
impl Serialize for HyperliquidAssetId
impl Copy for HyperliquidAssetId
impl Eq for HyperliquidAssetId
impl StructuralPartialEq for HyperliquidAssetId
Auto Trait Implementations§
impl Freeze for HyperliquidAssetId
impl RefUnwindSafe for HyperliquidAssetId
impl Send for HyperliquidAssetId
impl Sync for HyperliquidAssetId
impl Unpin for HyperliquidAssetId
impl UnsafeUnpin for HyperliquidAssetId
impl UnwindSafe for HyperliquidAssetId
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more