Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::utils Namespace Reference

Conversions between wire decimals with a constant exponent of -9 (CME PRICE9, ICE Decimal9) and the simulator's 1e-8 fixed point. More...

Classes

class  fixed_string
 A null-terminated character buffer of fixed capacity, stored inline. More...
struct  StringViewHash
 Transparent hash/equality for maps keyed by fixed_string. More...
struct  StringViewEq
class  RingBuffer

Functions

constexpr bool from_decimal9 (int64_t mantissa, int64_t &out) noexcept
 Returns false when the value has a digit at 1e-9.
constexpr int64_t to_decimal9 (int64_t fixed) noexcept
 The inverse.
template<size_t N>
bool copy_wire_field (char(&dst)[N], std::string_view src) noexcept
 Copies a name into a fixed-width wire field.
uint64_t mul_div_floor (uint64_t a, uint64_t b, uint64_t c) noexcept
 floor(a * b / c), with the product held at 128 bits.
uint64_t nextOrderId () noexcept
void executeOrder (Order *order, price_t price, qty_t executed_quantity, time_t timestamp)
template<Side s>
bool isPriceBetter (price_t a, price_t b)
template<Side s>
bool isPriceBetterOrEqual (price_t a, price_t b)
bool isPriceBetter (Side side, price_t a, price_t b)
bool isPriceBetterOrEqual (Side side, price_t a, price_t b)
std::string format_timestamp_iso8601 (const std::chrono::system_clock::time_point &tp, int num_sebsecond_digits=3)
std::string format_timestamp_iso8601 (uint64_t timestamp, int num_subsecond_digits=3)
std::string format_timestamp_iso8601 (int num_sebsecond_digits=3)
std::string format_heatbeat_timestamp ()
uint64_t get_current_time_ns ()

Variables

constexpr int64_t DECIMAL9_PER_FIXED = 1'000'000'000 / DOUBLE_MULTIPLIER
 A 1e-9 mantissa is one decimal place finer than the simulator's scale.
constexpr uint64_t ONE_SECOND_NS = 1'000'000'000
constexpr uint64_t ONE_MILLISECOND_NS = 1'000'000
constexpr uint64_t ONE_MICROSECOND_NS = 1'000

Detailed Description

Conversions between wire decimals with a constant exponent of -9 (CME PRICE9, ICE Decimal9) and the simulator's 1e-8 fixed point.

Null values are each protocol's own, so its codec maps them before calling these.

Function Documentation

◆ copy_wire_field()

template<size_t N>
bool slick::sim::utils::copy_wire_field ( char(&) dst[N],
std::string_view src )
inlinenoexcept

Copies a name into a fixed-width wire field.

Truncates to N-1 characters and zero-fills the remainder. The result is always NUL-terminated, with no bytes copied from beyond the source string.

Copying sizeof(dst) bytes from a shorter string would over-read it and could change the value the receiver sees. Zeroing dst before copying up to N bytes also fails for an N-character value, which overwrites the terminator.

Returns true when the value did not fit, so callers can warn about truncation.

Definition at line 24 of file fixed_string.hpp.

Referenced by slick::sim::utils::fixed_string< sizeof(MarketDataUpdate::symbol)>::assign().

◆ executeOrder()

◆ format_heatbeat_timestamp()

std::string slick::sim::utils::format_heatbeat_timestamp ( )
inline

Definition at line 62 of file timestamp.hpp.

◆ format_timestamp_iso8601() [1/3]

std::string slick::sim::utils::format_timestamp_iso8601 ( const std::chrono::system_clock::time_point & tp,
int num_sebsecond_digits = 3 )
inline

◆ format_timestamp_iso8601() [2/3]

std::string slick::sim::utils::format_timestamp_iso8601 ( int num_sebsecond_digits = 3)
inline

Definition at line 57 of file timestamp.hpp.

References format_timestamp_iso8601().

◆ format_timestamp_iso8601() [3/3]

std::string slick::sim::utils::format_timestamp_iso8601 ( uint64_t timestamp,
int num_subsecond_digits = 3 )
inline

Definition at line 30 of file timestamp.hpp.

References format_timestamp_iso8601().

◆ from_decimal9()

bool slick::sim::utils::from_decimal9 ( int64_t mantissa,
int64_t & out )
inlinenodiscardconstexprnoexcept

Returns false when the value has a digit at 1e-9.

No listed tick or lot is that fine, so such a value is off-tick, and rounding it would trade at a price or size the client never sent.

Definition at line 18 of file decimal.hpp.

References DECIMAL9_PER_FIXED.

◆ get_current_time_ns()

◆ isPriceBetter() [1/2]

template<Side s>
bool slick::sim::utils::isPriceBetter ( price_t a,
price_t b )
inline

Definition at line 8 of file price.hpp.

References slick::sim::BUY.

◆ isPriceBetter() [2/2]

bool slick::sim::utils::isPriceBetter ( Side side,
price_t a,
price_t b )
inline

Definition at line 25 of file price.hpp.

References slick::sim::BUY.

◆ isPriceBetterOrEqual() [1/2]

template<Side s>
bool slick::sim::utils::isPriceBetterOrEqual ( price_t a,
price_t b )
inline

◆ isPriceBetterOrEqual() [2/2]

bool slick::sim::utils::isPriceBetterOrEqual ( Side side,
price_t a,
price_t b )
inline

Definition at line 33 of file price.hpp.

References slick::sim::BUY.

◆ mul_div_floor()

uint64_t slick::sim::utils::mul_div_floor ( uint64_t a,
uint64_t b,
uint64_t c )
inlinenoexcept

floor(a * b / c), with the product held at 128 bits.

Fixed-point quantities carry a 1e8 scale, so the product of two of them overflows 64 bits. Requires b <= c: the result is then at most a and always fits, which is also _udiv128's precondition (it faults on a quotient over 64 bits). MSVC x64 and GCC/Clang take the first two branches; the boost fallback (32-bit MSVC, compilers without __int128) is not built by any CI job.

Definition at line 19 of file math.hpp.

◆ nextOrderId()

◆ to_decimal9()

int64_t slick::sim::utils::to_decimal9 ( int64_t fixed)
inlinenodiscardconstexprnoexcept

The inverse.

A fixed-point value above 9.2e17 would overflow the multiply, but that is 9.2e9 in price or size units - far past any tick, lot or level a wire decimal of this exponent can carry.

Definition at line 29 of file decimal.hpp.

References DECIMAL9_PER_FIXED.

Variable Documentation

◆ DECIMAL9_PER_FIXED

int64_t slick::sim::utils::DECIMAL9_PER_FIXED = 1'000'000'000 / DOUBLE_MULTIPLIER
inlineconstexpr

A 1e-9 mantissa is one decimal place finer than the simulator's scale.

Definition at line 12 of file decimal.hpp.

Referenced by from_decimal9(), and to_decimal9().

◆ ONE_MICROSECOND_NS

uint64_t slick::sim::utils::ONE_MICROSECOND_NS = 1'000
constexpr

Definition at line 101 of file timestamp.hpp.

◆ ONE_MILLISECOND_NS

uint64_t slick::sim::utils::ONE_MILLISECOND_NS = 1'000'000
constexpr

Definition at line 100 of file timestamp.hpp.

◆ ONE_SECOND_NS

uint64_t slick::sim::utils::ONE_SECOND_NS = 1'000'000'000
constexpr