Position Reserve (PR) orders are discussed in detail in the Position Reserve Orders section. If you plan to utilize them when running as a TT Application Server, you would call the SDKAlgo::ReserveRisk() method, preferably from the strategy's Start() method.
bool TrailingCrossStrategy::Start(ttsdk::SDKAlgoPtr algoOrder, ttsdk::SDKAlgoRequestPtr req)
{
// ...
ttsdk::RiskSide side = ttsdk::RiskSide::Buy;
if (profile_.side == ttsdk::OrderSide::Sell)
side = ttsdk::RiskSide::Sell;
algoOrder->ReserveRisk(algoOrder->GetInstrument(), profile_.account_id, side, profile_.quantity, profile_.quantity);
algoOrder->OnPendingRequestCompleted(ttsdk::AlgoResponseCode::Ok);
// ...
}
When the request to reserve risk returns, the SDKAlgoManager::OnRiskReserved() method will be called. You can then notify the strategy which made the request as follows:
void SDKAlgoManager::OnRiskReserved(ttsdk::SDKAlgoPtr algoOrder, const uint64_t instrumentId, const uint64_t accountId,
const ttsdk::RiskSide side, const ttsdk::AlgoResponseCode code)
{
std::cout << "SDKAlgoManager::OnRiskReserved " << algoOrder->GetOrderId() << std::endl;
std::shared_ptr strategy(nullptr);
{
std::unique_lock lock(this->mutexStrategies_);
auto iter = strategies_.find(algoOrder->GetOrderId());
if (iter != strategies_.end())
{
strategy = iter->second;
}
}
if (strategy)
{
return strategy->OnRiskReserved(instrumentId, accountId, side, code);
}
}
To process this call, you must override the BaseStrategy:: OnRiskReserved() method in your specific strategy. For example:
void TrailingCrossStrategy::OnRiskReserved(const uint64_t instrumentId, const uint64_t accountId, const ttsdk::RiskSide side, const ttsdk::AlgoResponseCode code)
{
if (code != ttsdk::AlgoResponseCode::Ok)
{
ttsdk::TTLogWarning("TrailingCrossStrategy failed to reserve risk for algoId: %s [instrumentId: %llu accountId: %llu side: %s]", GetOrderId(), instrumentId, accountId, ttsdk::ToString(side));
algoOrder_->FailAlgo("Position reserve request failed.");
}
else
{
ttsdk::TTLogInfo("TrailingCrossStrategy reserved risk for algoId: %s [instrumentId: %llu accountId: %llu side: %s]", GetOrderId(), instrumentId, accountId, ttsdk::ToString(side));
}
}
Similarly, you can then release Position Reserve orders by calling the SDKAlgo::ReleaseRisk() method. You can notify the strategy which made the request in the same way.