algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::strategy::Price Class Reference

A price known to be on its instrument's tick grid. More...

#include <algotradelib/src/strategy/intent.hpp>

Public Member Functions

const Decimal64 & value () const noexcept
 Returns the price as a decimal.
std::string str () const
 Returns the price as text, for logs.

Static Public Member Functions

static std::optional< Price > checked (Decimal64 value, const PriceRule &rule)
 Makes a price from a value that is already on the grid.
static std::optional< Price > rounded (const Decimal64 &value, const PriceRule &rule, OrderSide side)
 Makes a price by rounding a value onto the grid, in the order's favour.

Friends

bool operator== (const Price &lhs, const Price &rhs)
 Compares two prices by exact value (scale included; see Decimal64).
bool operator!= (const Price &lhs, const Price &rhs)
 Compares two prices for inequality.

Detailed Description

A price known to be on its instrument's tick grid.

Make one with checked (for a price you have) or rounded (to move a price onto the grid). For a price computed as a Scalar, use analytics::round_scalar_to_tick first.

Definition at line 29 of file intent.hpp.

Member Function Documentation

◆ checked()

std::optional< Price > algotradelib::strategy::Price::checked ( Decimal64 value,
const PriceRule & rule )
inlinestatic

Makes a price from a value that is already on the grid.

Parameters
valueThe price.
ruleThe instrument's tick rule (from its Instrument reference data).
Returns
The price, or std::nullopt if value is off the grid or rule does not know the grid.

Definition at line 39 of file intent.hpp.

◆ rounded()

std::optional< Price > algotradelib::strategy::Price::rounded ( const Decimal64 & value,
const PriceRule & rule,
OrderSide side )
inlinestatic

Makes a price by rounding a value onto the grid, in the order's favour.

A buy rounds down and a sell rounds up, so the price never becomes worse for the order.

Parameters
valueThe price to round.
ruleThe instrument's tick rule.
sideThe side of the order the price is for.
Returns
The rounded price, or std::nullopt if rule does not know the grid.

Definition at line 57 of file intent.hpp.

◆ str()

std::string algotradelib::strategy::Price::str ( ) const
inline

Returns the price as text, for logs.

Returns
The decimal's text.

Definition at line 79 of file intent.hpp.

◆ value()

const Decimal64 & algotradelib::strategy::Price::value ( ) const
inlinenoexcept

Returns the price as a decimal.

Returns
The exact value the runner sends.

Definition at line 73 of file intent.hpp.

Referenced by checked(), and rounded().

◆ operator!=

bool operator!= ( const Price & lhs,
const Price & rhs )
friend

Compares two prices for inequality.

Parameters
lhsThe first price.
rhsThe second price.
Returns
true if they differ.

Definition at line 97 of file intent.hpp.

◆ operator==

bool operator== ( const Price & lhs,
const Price & rhs )
friend

Compares two prices by exact value (scale included; see Decimal64).

Parameters
lhsThe first price.
rhsThe second price.
Returns
true if they are equal.

Definition at line 87 of file intent.hpp.


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