ITCHCPP 1.6.0
High-Performance NASDAQ TotalView-ITCH 5.0 Parser & Market-Data Platform
Loading...
Searching...
No Matches
itch::BasicPrice< RawType, Decimals > Class Template Reference

A strongly typed fixed-point price carrying its own decimal scale. More...

#include <price.hpp>

Public Types

using raw_type = RawType
 

Public Member Functions

constexpr BasicPrice () noexcept=default
 Constructs a zero-valued price at this scale.
 
constexpr BasicPrice (raw_type raw_value) noexcept
 Wraps a raw on-wire price value at this scale.
 
constexpr auto raw () const noexcept -> raw_type
 The underlying raw integer value, exactly as it appears on the wire.
 
constexpr auto to_double () const noexcept -> double
 The price as a floating-point value (raw / 10^Decimals).
 
auto to_string () const -> std::string
 The price as a fixed-precision decimal string.
 

Static Public Member Functions

static constexpr auto divisor () noexcept -> raw_type
 The scale's divisor, i.e.
 

Static Public Attributes

static constexpr unsigned int decimals = Decimals
 The number of implied decimal places for this price scale.
 

Friends

constexpr auto operator== (BasicPrice, BasicPrice) noexcept -> bool=default
 Compares two prices of the same scale for equality by raw value.
 
constexpr auto operator<=> (BasicPrice, BasicPrice) noexcept=default
 Orders two prices of the same scale by raw value.
 

Detailed Description

template<typename RawType, unsigned int Decimals>
class itch::BasicPrice< RawType, Decimals >

A strongly typed fixed-point price carrying its own decimal scale.

ITCH prices are wire integers with an implied number of decimal places. Standard price fields imply 4 decimals (divisor 10,000); MWCB decline-level prices imply 8 decimals (divisor 100,000,000). Exposing both as a bare uint32_t/uint64_t makes it trivially easy to divide by the wrong scale and silently produce a wrong price.

BasicPrice encodes the scale in the type. The two scales are therefore distinct types (StandardPrice vs MwcbPrice) that cannot be mixed, compared, or assigned to one another by accident: the 4-vs-8 decimal mistake becomes a compile error rather than a runtime bug.

Template Parameters
RawTypeThe unsigned integer type of the on-wire value.
DecimalsThe number of implied decimal places.

Definition at line 35 of file price.hpp.

Member Typedef Documentation

◆ raw_type

template<typename RawType , unsigned int Decimals>
using itch::BasicPrice< RawType, Decimals >::raw_type = RawType

Definition at line 39 of file price.hpp.

Constructor & Destructor Documentation

◆ BasicPrice() [1/2]

template<typename RawType , unsigned int Decimals>
constexpr itch::BasicPrice< RawType, Decimals >::BasicPrice ( )
constexprdefaultnoexcept

Constructs a zero-valued price at this scale.

◆ BasicPrice() [2/2]

template<typename RawType , unsigned int Decimals>
constexpr itch::BasicPrice< RawType, Decimals >::BasicPrice ( raw_type  raw_value)
inlineexplicitconstexprnoexcept

Wraps a raw on-wire price value at this scale.

Parameters
raw_valueThe raw integer price, exactly as it appears on the wire.

Definition at line 50 of file price.hpp.

Member Function Documentation

◆ raw()

template<typename RawType , unsigned int Decimals>
constexpr auto itch::BasicPrice< RawType, Decimals >::raw ( ) const -> raw_type
inlineconstexprnoexcept

The underlying raw integer value, exactly as it appears on the wire.

Returns
The raw integer price at this scale.

Definition at line 55 of file price.hpp.

◆ divisor()

template<typename RawType , unsigned int Decimals>
static constexpr auto itch::BasicPrice< RawType, Decimals >::divisor ( ) -> raw_type
inlinestaticconstexprnoexcept

The scale's divisor, i.e.

10^Decimals.

Returns
The divisor used to convert the raw integer value into a floating-point or decimal-string representation.

Definition at line 61 of file price.hpp.

Referenced by itch::BasicPrice< RawType, Decimals >::to_double().

◆ to_double()

template<typename RawType , unsigned int Decimals>
constexpr auto itch::BasicPrice< RawType, Decimals >::to_double ( ) const -> double
inlineconstexprnoexcept

The price as a floating-point value (raw / 10^Decimals).

Returns
The price converted to a double.

Definition at line 72 of file price.hpp.

References itch::BasicPrice< RawType, Decimals >::divisor().

Referenced by itch::BasicPrice< RawType, Decimals >::to_string().

◆ to_string()

template<typename RawType , unsigned int Decimals>
auto itch::BasicPrice< RawType, Decimals >::to_string ( ) const -> std::string
inline

The price as a fixed-precision decimal string.

Returns
The price formatted with exactly Decimals fractional digits.

Definition at line 79 of file price.hpp.

References itch::BasicPrice< RawType, Decimals >::to_double().

Friends And Related Symbol Documentation

◆ operator==

template<typename RawType , unsigned int Decimals>
constexpr auto operator== ( BasicPrice< RawType, Decimals >  ,
BasicPrice< RawType, Decimals >   
) -> bool=default
friend

Compares two prices of the same scale for equality by raw value.

Parameters
lhsThe left-hand price.
rhsThe right-hand price.
Returns
true if both prices have the same raw value.

◆ operator<=>

template<typename RawType , unsigned int Decimals>
constexpr auto operator<=> ( BasicPrice< RawType, Decimals >  ,
BasicPrice< RawType, Decimals >   
)
friend

Orders two prices of the same scale by raw value.

Parameters
lhsThe left-hand price.
rhsThe right-hand price.
Returns
The three-way comparison result between lhs and rhs.

Member Data Documentation

◆ decimals

template<typename RawType , unsigned int Decimals>
constexpr unsigned int itch::BasicPrice< RawType, Decimals >::decimals = Decimals
staticconstexpr

The number of implied decimal places for this price scale.

Definition at line 42 of file price.hpp.


The documentation for this class was generated from the following file: