dxFeed Graal CXX API v5.0.0
Loading...
Searching...
No Matches
PriceIncrements Struct Reference

Represents rules for valid price quantization for a given instrument on a certain exchange. More...

#include <PriceIncrements.hpp>

+ Inheritance diagram for PriceIncrements:

Public Types

using Ptr = std::shared_ptr<PriceIncrements>
 The alias to a type of shared pointer to the PriceIncrements object.
 
using Unique = std::unique_ptr<PriceIncrements>
 The alias to a type of unique pointer to the PriceIncrements object.
 
- Public Types inherited from SharedEntity
using Ptr = std::shared_ptr<SharedEntity>
 The alias to a type of shared pointer to the SharedEntity object.
 

Public Member Functions

std::string getText () const
 Returns textual representation of price increments in the format:
 
std::vector< double > getPriceIncrements () const
 Returns internal representation of price increments as a single array of double values.
 
double getPriceIncrement () const
 Returns the first price increment (for price range adjacent to 0), usually the smallest one.
 
double getPriceIncrement (double price) const
 Returns price increment which shall be applied to the specified price.
 
double getPriceIncrement (double price, std::int32_t direction) const
 Returns price increment which shall be applied to the specified price in the specified direction.
 
std::int32_t getPricePrecision () const
 Returns first price precision (for price range adjacent to 0), usually the largest one.
 
std::int32_t getPricePrecision (double price) const
 Returns price precision for the price range which contains a specified price.
 
double roundPrice (double price) const
 Returns specified price rounded to nearest valid value.
 
double roundPrice (double price, std::int32_t direction) const
 Returns specified price rounded in the specified direction to the nearest value that is valid, according to price increment rules.
 
double roundPrice (double price, RoundingMode roundingMode) const
 Returns specified price rounded according to specified rounding mode to nearest value that is valid, according to price increment rules.
 
double incrementPrice (double price, std::int32_t direction) const
 Returns specified price incremented in the specified direction by appropriate increment and then rounded to the nearest valid value.
 
double incrementPrice (double price, std::int32_t direction, double step) const
 Returns specified price incremented in the specified direction by the maximum of a specified step and appropriate increment, and then rounded to the nearest valid value.
 
bool operator== (const PriceIncrements &other) const
 Returns true if this object is equal to other object.
 
bool operator== (const PriceIncrements::Ptr &other) const
 Returns true if this object is equal to other object.
 
std::size_t hashCode () const noexcept
 
std::string toString () const override
 Returns a string representation of the current object.
 
- Public Member Functions inherited from SharedEntity
template<typename T>
bool is () const noexcept
 Checks that the pointer to the current type could be converted to type T* In other words: whether type T belongs to the type hierarchy in which the current type resides.
 
template<typename T>
std::shared_ptr< T > sharedAs () noexcept
 Returns a pointer to the current object wrapped in a smart pointer to type T.
 
template<typename T>
std::shared_ptr< T > sharedAs () const noexcept
 Returns a pointer to the current object wrapped in a smart pointer to type T.
 
- Public Member Functions inherited from Entity
virtual ~Entity () noexcept=default
 The default virtual d-tor.
 

Static Public Member Functions

static Ptr valueOf (const StringLike &text)
 Returns an instance of price increments for specified textual representation.
 
static Ptr valueOf (double increment)
 Returns an instance of price increments for a specified single increment.
 
static Ptr valueOf (const std::vector< double > &increments)
 Returns an instance of price increments for specified internal representation.
 
static Ptr valueOf (std::initializer_list< double > increments)
 Returns an instance of price increments for specified internal representation.
 
- Static Public Member Functions inherited from RequireMakeShared< PriceIncrements >
static auto createShared (Args &&...args)
 Creates a smart pointer to an object.
 

Static Public Attributes

static const Ptr EMPTY
 Empty price increments - it has empty text and sole increment with value 0.
 

Detailed Description

Represents rules for valid price quantization for a given instrument on a certain exchange.

These rules are defined as a set of price ranges with associated price increments. Each price increment defines what price values are valid for the corresponding price range-valid prices shall be divisible by corresponding price increment.

All price ranges shall be mutually exclusive, and they shall cover the entire space from 0 to infinity. Therefore, all ranges can be represented as a sequence of numbers where increments are interleaved with range limits, with extreme limits (0 and infinity) omitted for short. Negative space (from negative infinity to 0) uses symmetrical price ranges.

There is a special value PriceIncrements::EMPTY that is used to represent unknown or undefined rules. This value has empty textual representation and is considered to have a sole increment with value 0.

See PriceIncrements::getText() and PriceIncrements::getPriceIncrements() for details about used formats and representations.

NOTE:This class produces precise results for decimal numbers with at most 14 significant digits and at most 14 digits after the decimal point.

Member Function Documentation

◆ getPriceIncrement() [1/3]

double PriceIncrements::getPriceIncrement ( ) const

Returns the first price increment (for price range adjacent to 0), usually the smallest one.

Returns 0 for PriceIncrements::EMPTY price increments.

Returns
The first price increment.

◆ getPriceIncrement() [2/3]

double PriceIncrements::getPriceIncrement ( double price) const

Returns price increment which shall be applied to the specified price.

If the price is Not-a-Number (NaN), then the first price increment is returned. If price is a breakpoint between two ranges, then a minimum of upward and downward increments is returned. This method is equivalent to calling PriceIncrements::getPriceIncrement(price, 0).

Parameters
priceThe price.
Returns
The price increment.

◆ getPriceIncrement() [3/3]

double PriceIncrements::getPriceIncrement ( double price,
std::int32_t direction ) const

Returns price increment which shall be applied to the specified price in the specified direction.

If the price is Not-a-Number (NaN), then the first price increment is returned. If the price is a breakpoint between two ranges and a direction is 0, then a minimum of upward and downward increments is returned.

Parameters
priceThe price.
directionThe direction.
Returns
The price increment.

◆ getPriceIncrements()

std::vector< double > PriceIncrements::getPriceIncrements ( ) const

Returns internal representation of price increments as a single array of double values.

This array specifies all numbers from textual representation (see PriceIncrements::getText()) in the same order. Therefore, numbers at even positions are increments and numbers at odd positions are upper limits. The array always has an odd length - the infinite upper limit of the last range is always omitted, and the first increment (for price range adjacent to 0) is always included even for PriceIncrements::EMPTY value.

Returns
The internal representation of price increments.

◆ getPricePrecision() [1/2]

std::int32_t PriceIncrements::getPricePrecision ( ) const

Returns first price precision (for price range adjacent to 0), usually the largest one.

Returns 0 for PriceIncrements::EMPTY price increments.

Returns
The first price precision.

◆ getPricePrecision() [2/2]

std::int32_t PriceIncrements::getPricePrecision ( double price) const

Returns price precision for the price range which contains a specified price.

Price precision is a number of decimal digits after decimal point that are needed to represent all valid prices in the given price range. This method returns price precision in the interval [0, 18] inclusive. If the price is Not-a-Number (NaN), then the first price precision is returned. If the price is a breakpoint between two ranges, then precision of the lower range is returned.

Parameters
priceThe price.
Returns
The price precision.

◆ getText()

std::string PriceIncrements::getText ( ) const

Returns textual representation of price increments in the format:

TEXT ::= "" | LIST
LIST ::= INCREMENT | RANGE "; " LIST
RANGE ::= INCREMENT " " UPPER_LIMIT

Where INCREMENT is a price increment in the given price range and UPPER_LIMIT is the upper bound of that range. All ranges are listed in the ascending order of upper limits, and the last range is considered to extend toward infinity and is therefore specified without upper limit. All increments and limits are finite positive numbers. The case with empty text is a special stub used for PriceIncrements::EMPTY value, it uses a sole increment with value 0.

Returns
The textual representation.

◆ hashCode()

std::size_t PriceIncrements::hashCode ( ) const
noexcept
Returns
A hash code value for this object.

◆ incrementPrice() [1/2]

double PriceIncrements::incrementPrice ( double price,
std::int32_t direction ) const

Returns specified price incremented in the specified direction by appropriate increment and then rounded to the nearest valid value.

If the price is Not-a-Number (NaN), then NaN is returned. If the appropriate price increment is 0, then the specified price is returned as is. This method is equivalent to calling PriceIncrements::incrementPrice(price, direction, 0).

Parameters
priceThe price to increment.
directionThe direction.
Returns
The new price.
Exceptions
JavaException("IllegalArgumentException")if the direction is 0

◆ incrementPrice() [2/2]

double PriceIncrements::incrementPrice ( double price,
std::int32_t direction,
double step ) const

Returns specified price incremented in the specified direction by the maximum of a specified step and appropriate increment, and then rounded to the nearest valid value.

If the price is Not-a-Number (NaN), then NaN is returned. If both step and appropriate price increment are 0, then the specified price is returned as is. Note that a step must be positive even for negative directions.

Parameters
priceThe price to increment.
directionThe direction.
stepThe step.
Returns
The new price.
Exceptions
JavaException("IllegalArgumentException")if the direction is 0, or the step uses an invalid value

◆ operator==() [1/2]

bool PriceIncrements::operator== ( const PriceIncrements & other) const

Returns true if this object is equal to other object.

Parameters
otherAnother object
Returns
true if this object is equal to other object

◆ operator==() [2/2]

bool PriceIncrements::operator== ( const PriceIncrements::Ptr & other) const
inline

Returns true if this object is equal to other object.

Parameters
otherAnother object
Returns
true if this object is equal to other object

◆ roundPrice() [1/3]

double PriceIncrements::roundPrice ( double price) const

Returns specified price rounded to nearest valid value.

If the price is Not-a-Number (NaN), then NaN is returned. If the appropriate price increment is 0, then the specified price is returned as is. This method is equivalent to calling PriceIncrements::roundPrice(price, 0).

Parameters
priceThe price to round.
Returns
The rounded price.

◆ roundPrice() [2/3]

double PriceIncrements::roundPrice ( double price,
RoundingMode roundingMode ) const

Returns specified price rounded according to specified rounding mode to nearest value that is valid, according to price increment rules.

If the price is Not-a-Number (NaN), then NaN is returned. If the appropriate price increment is 0, then the specified price is returned as is.

Parameters
priceThe price to round.
roundingModeThe rounding mode.
Returns
The rounded price.

◆ roundPrice() [3/3]

double PriceIncrements::roundPrice ( double price,
std::int32_t direction ) const

Returns specified price rounded in the specified direction to the nearest value that is valid, according to price increment rules.

If the price is Not-a-Number (NaN), then NaN is returned. If the appropriate price increment is 0, then the specified price is returned as is. If a direction is 0, then the price is rounded to the nearest valid value.

Parameters
priceThe price to round.
directionThe direction.
Returns
The rounded price.

◆ toString()

std::string PriceIncrements::toString ( ) const
overridevirtual

Returns a string representation of the current object.

Returns
A string representation

Reimplemented from SharedEntity.

◆ valueOf() [1/4]

PriceIncrements::Ptr PriceIncrements::valueOf ( const std::vector< double > & increments)
static

Returns an instance of price increments for specified internal representation.

See PriceIncrements::getPriceIncrements() for details about internal representation.

Parameters
incrementsThe increments.
Returns
The price increments instance.
Exceptions
JavaException("IllegalArgumentException")if data contains invalid values

◆ valueOf() [2/4]

PriceIncrements::Ptr PriceIncrements::valueOf ( const StringLike & text)
static

Returns an instance of price increments for specified textual representation.

See PriceIncrements::getText() for format specification.

Parameters
textThe textual representation.
Returns
The price increments instance.
Exceptions
JavaException("IllegalArgumentException")if text uses wrong format or contains invalid values.

◆ valueOf() [3/4]

PriceIncrements::Ptr PriceIncrements::valueOf ( double increment)
static

Returns an instance of price increments for a specified single increment.

Parameters
incrementThe increment.
Returns
The price increments instance.
Exceptions
JavaException("IllegalArgumentException")if increment uses invalid value

◆ valueOf() [4/4]

PriceIncrements::Ptr PriceIncrements::valueOf ( std::initializer_list< double > increments)
static

Returns an instance of price increments for specified internal representation.

See PriceIncrements::getPriceIncrements() for details about internal representation.

Parameters
incrementsThe increments.
Returns
The price increments instance.
Exceptions
JavaException("IllegalArgumentException")if data contains invalid values