ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
Loading...
Searching...
No Matches
b2bits::constants::detail Namespace Reference

Internal utility functions for financial data conversion. More...

Detailed Description

Internal utility functions for financial data conversion.

These functions handle conversion between human-readable values and fixed-point internal representations. Not intended for direct use; use wrapper functions in the public API instead.

Functions

std::int64_t to_sbe_price_mantissa (std::int64_t val, std::int64_t mult=constants::SBE_PRICE_MULTIPLIER) noexcept
 Convert value to SBE price mantissa (fixed-point representation).
std::int64_t to_sbe_qty_mantissa (std::int64_t val, std::int64_t mult=constants::SBE_QTY_MULTIPLIER) noexcept
 Convert value to SBE quantity mantissa (fixed-point representation).
constexpr std::uint16_t num_price_decimals (std::uint64_t multiplier)
 Calculate number of decimal places in a multiplier.
constexpr bool validate_num_price_decimals (std::uint16_t num_decimals)
 Validate that number of decimals is within supported range.
constexpr std::uint64_t calculate_multiplier (std::uint16_t num_of_decimals)
 Calculate multiplier for a given number of decimal places.

Function Documentation

◆ calculate_multiplier()

std::uint64_t b2bits::constants::detail::calculate_multiplier ( std::uint16_t num_of_decimals)
inlineconstexpr

Calculate multiplier for a given number of decimal places.

Recursively computes 10^num_of_decimals to get the appropriate multiplier. For example, 3 decimals requires a multiplier of 1000.

Parameters
num_of_decimalsNumber of decimal places needed
Returns
Multiplier value (10^num_of_decimals)
Note
Constexpr - evaluated at compile time
Inverse operation of num_price_decimals()
Example:
constexpr auto mult = calculate_multiplier(4); // = 10000
constexpr std::uint64_t calculate_multiplier(std::uint16_t num_of_decimals)
Calculate multiplier for a given number of decimal places.
Definition Constants.h:180

References calculate_multiplier().

Referenced by calculate_multiplier().

◆ num_price_decimals()

std::uint16_t b2bits::constants::detail::num_price_decimals ( std::uint64_t multiplier)
inlineconstexpr

Calculate number of decimal places in a multiplier.

Recursively determines how many decimal places a multiplier represents. For example, 1000 represents 3 decimal places, 1000000 represents 6.

Parameters
multiplierMultiplier value (must be power of 10)
Returns
Number of decimal places
Note
Constexpr - evaluated at compile time
Assumes multiplier is a power of 10
Example:
constexpr auto decimals = num_price_decimals(1'000'000); // = 6
constexpr std::uint16_t num_price_decimals(std::uint64_t multiplier)
Calculate number of decimal places in a multiplier.
Definition Constants.h:139

References num_price_decimals().

Referenced by b2bits::nasdaq::calculate_ratio(), num_price_decimals(), and validate_num_price_decimals().

◆ to_sbe_price_mantissa()

std::int64_t b2bits::constants::detail::to_sbe_price_mantissa ( std::int64_t val,
std::int64_t mult = constants::SBE_PRICE_MULTIPLIER )
inlinenoexcept

Convert value to SBE price mantissa (fixed-point representation).

Multiplies the value by the price multiplier to create a fixed-point representation suitable for SBE encoding. This avoids floating-point precision issues in financial calculations.

Parameters
valValue to convert (e.g., price as integer or scaled value)
multMultiplier to apply (default: SBE_PRICE_MULTIPLIER = 1e9)
Returns
Fixed-point mantissa value
Note
Default multiplier provides 9 decimal places of precision
Example:
// Convert price 123.456 (stored as 123456000 with 6 decimals)
// to full SBE representation with 9 decimals
auto mantissa = to_sbe_price_mantissa(123456000, 1000); // = 123456000000
std::int64_t to_sbe_price_mantissa(std::int64_t val, std::int64_t mult=constants::SBE_PRICE_MULTIPLIER) noexcept
Convert value to SBE price mantissa (fixed-point representation).
Definition Constants.h:92

References b2bits::constants::SBE_PRICE_MULTIPLIER.

◆ to_sbe_qty_mantissa()

std::int64_t b2bits::constants::detail::to_sbe_qty_mantissa ( std::int64_t val,
std::int64_t mult = constants::SBE_QTY_MULTIPLIER )
inlinenoexcept

Convert value to SBE quantity mantissa (fixed-point representation).

Multiplies the value by the quantity multiplier to create a fixed-point representation suitable for SBE encoding. Used for contract quantities.

Parameters
valValue to convert (e.g., quantity as integer)
multMultiplier to apply (default: SBE_QTY_MULTIPLIER = 100)
Returns
Fixed-point mantissa value
Note
Default multiplier provides 2 decimal places of precision
Example:
// Convert quantity 150 to SBE representation
auto mantissa = to_sbe_qty_mantissa(150); // = 15000
std::int64_t to_sbe_qty_mantissa(std::int64_t val, std::int64_t mult=constants::SBE_QTY_MULTIPLIER) noexcept
Convert value to SBE quantity mantissa (fixed-point representation).
Definition Constants.h:116

References b2bits::constants::SBE_QTY_MULTIPLIER.

◆ validate_num_price_decimals()

bool b2bits::constants::detail::validate_num_price_decimals ( std::uint16_t num_decimals)
inlineconstexpr

Validate that number of decimals is within supported range.

Checks if the requested number of decimal places is less than or equal to the maximum supported by SBE_PRICE_MULTIPLIER (9 decimals).

Parameters
num_decimalsNumber of decimal places to validate
Returns
true if num_decimals is supported (? 9), false otherwise
Note
Constexpr - evaluated at compile time
Used for compile-time validation in templates

References num_price_decimals(), and b2bits::constants::SBE_PRICE_MULTIPLIER.

Referenced by b2bits::nasdaq::calculate_ratio().