3#include <algotradelib/core>
22 case OrderStatus::UNKNOWN:
23 case OrderStatus::PENDING:
24 case OrderStatus::PENDING_CANCEL:
25 case OrderStatus::PENDING_REPLACE:
26 case OrderStatus::PARTIAL_FILLED:
28 case OrderStatus::FILLED:
29 case OrderStatus::CANCELED:
30 case OrderStatus::REJECTED:
31 case OrderStatus::CANCEL_REJECTED:
32 case OrderStatus::REPLACE_REJECTED:
33 case OrderStatus::REPLACED:
49template <
typename Broker>
84 std::chrono::system_clock::time_point
as_of_{};
102 const std::chrono::system_clock::time_point epoch{};
124 if (position.instrument_ == instrument) {
125 return position.quantity_;
143 if (!(position.instrument_ == instrument)) {
146 const auto sum =
decimal_add(total, position.quantity_);
167 for (
const auto& order :
working_) {
168 if (!(order.order_.instrument_ == instrument) || order.order_.side_ != side) {
175 order.order_.quantity_, order.order_.execution_.filled_quantity_
213 if (!(position.instrument_ == instrument)) {
217 position.sellable_basis_ ? *position.sellable_basis_ :
sellable_basis_;
219 reading.
quantity_ = position.sellable_quantity_;
234 if (reading.
quantity_ && position.sellable_quantity_ &&
241 reading.
quantity_ = position.sellable_quantity_;
253 for (
const auto& amount :
cash_) {
254 if (amount.currency_ == currency) {
255 return amount.amount_;
272 if (amount.cash_.currency_ == currency) {
273 return amount.cash_.amount_;
292 if (position.instrument_ == instrument) {
293 return position.sellable_quantity_;
305 for (
const auto& order :
working_) {
306 if (order.ref_ == ref) {
A three-letter currency code, such as KRW or USD (ISO 4217 style).
An exact signed decimal: an int64 coefficient times 10^-scale.
static Decimal64 parse(std::string_view input)
Parses a decimal string exactly (no binary floating point).
What a strategy sees and emits: events, intents, the portfolio, reconciliation and risk limits.
bool order_is_open(OrderStatus status)
Tests whether an order in a given status may still trade.
The library: broker-neutral types (core), and the modules below.
OrderStatus
Where an order stands in its lifecycle.
std::optional< Decimal64 > decimal_add(const Decimal64 &lhs, const Decimal64 &rhs)
Adds two decimals exactly.
std::optional< Decimal64 > decimal_subtract(const Decimal64 &lhs, const Decimal64 &rhs)
Subtracts two decimals exactly.
bool decimal_less(const Decimal64 &lhs, const Decimal64 &rhs)
Compares two decimals numerically, whatever their scales.
OrderSide
The side of an order: its economic direction, buy or sell.
Identifies an instrument: its country, venue and symbol.
A broker's reference to one order, used to amend or cancel it.
What a sellable quantity covers, and how RiskGuard must treat resting sells against it.
RestingTreatment resting_
How resting sells are treated; unestablished by default.
Coverage coverage_
What the figure covers; unestablished by default.
An order still open to modification or cancellation.
A sellable quantity together with what it covers, read from the same row.
A sellable quantity together with what it covers, read from the same row.
SellableBasis basis_
What the figure covers; unestablished if the rows disagree.
std::optional< Decimal64 > quantity_
The figure, or std::nullopt if no row of the instrument reported one.
What the account holds and which orders are still working, as a strategy sees it.
std::vector< WorkingOrder< Broker > > working_
Orders still outstanding at the broker.
SellableBasis sellable_basis_
What the sellable_quantity_ figures on positions_ cover.
std::vector< Money > cash_
Cash per currency, in a backtest only.
std::optional< Decimal64 > buying_power_in(const Currency ¤cy) const
Returns the buying power in a currency.
std::optional< Decimal64 > net_quantity_of(const InstrumentId &instrument) const
Returns the net quantity held of an instrument, summed over every row.
Decimal64 working_quantity(const InstrumentId &instrument, OrderSide side) const
Returns the quantity still to fill on open orders for an instrument and side.
std::chrono::system_clock::time_point working_as_of_
When the working-order listing was received, on the same clock as as_of_.
std::optional< Decimal64 > quantity_of(const InstrumentId &instrument) const
Returns the quantity of the first position row for an instrument.
const WorkingOrder< Broker > * find_working(const OrderRef< Broker > &ref) const
Finds a working order by its reference.
std::vector< BuyingPower > buying_power_
What may be spent, per currency.
std::optional< Decimal64 > cash_in(const Currency ¤cy) const
Returns the cash held in a currency (backtest only; see cash_).
std::chrono::system_clock::time_point as_of_
When the holdings were received, on this machine's clock.
std::optional< Decimal64 > sellable_quantity_of(const InstrumentId &instrument) const
Returns the sellable quantity the broker reported for an instrument (first row).
SellableReading sellable_reading_for(const InstrumentId &instrument) const
Returns an instrument's sellable quantity and its basis, taken from the same row.
std::vector< HoldingPosition > positions_
Every position row the broker reported.
bool listing_newer_than_holdings() const noexcept
Tests whether the working-order listing is newer than the holdings.