An advanced interactive console application to send orders and receive responses.
#include "../Settings/Defaults.h"
#include "MessageFactory.h"
namespace Samples {
MessageFactory::MessageFactory(const std::string& sessionId)
: sessionId_(sessionId)
{}
NewOrderSingle MessageFactory::initNewOrder() const
{
NewOrderSingle msg;
msg->setSenderId(sessionId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Manual)
.setExecutionMode(ExecMode::Aggressive)
return msg;
}
NewOrderSingle & MessageFactory::getNewOrder(const Order& order) const
{
static NewOrderSingle msg = initNewOrder();
msg->setPrice(
PRICE9(order.price_))
.setOrderQty(order.orderQty_)
.setSecurityId(order.securityId_)
.setClOrdId(order.cIOrdId_)
.setOrderRequestId(IdGenerator::newIntId())
.setStopPx(
PRICE9(order.stopPx_))
.setMinQty(order.minQty_)
.setDisplayQty(order.displayQty_)
.setOrdType(order.ordType_)
.setTimeInForce(order.timeInForce_)
.setSide(order.side_);
if (order.timeInForce_ == TimeInForce::GoodTillDate)
return msg;
}
OrderCancelReplaceRequest MessageFactory::initOrderCancelReplaceRequest() const
{
OrderCancelReplaceRequest msg;
msg->setSenderId(sessionId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setSide(SideReq::Buy)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Manual)
.setExecutionMode(ExecMode::Aggressive)
.setOfmOverride(OFMOverrideReq::Disabled);
return msg;
}
OrderCancelReplaceRequest & MessageFactory::getModifyRequest(const Order& order) const
{
static OrderCancelReplaceRequest msg = initOrderCancelReplaceRequest();
msg->setPrice(
PRICE9(order.price_))
.setOrderQty(order.orderQty_)
.setSecurityId(order.securityId_)
.setClOrdId(order.cIOrdId_)
.setOrderId(order.orderId_)
.setOrderRequestId(IdGenerator::newIntId())
.setStopPx(
PRICE9(order.stopPx_))
.setMinQty(order.minQty_)
.setOrdType(order.ordType_)
.setTimeInForce(order.timeInForce_);
if (order.timeInForce_ == TimeInForce::GoodTillDate)
return msg;
}
OrderCancelRequest MessageFactory::initOrderCancelRequest() const
{
OrderCancelRequest msg;
msg->setSenderId(sessionId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setSide(SideReq::Buy)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Manual);
return msg;
}
OrderCancelRequest & MessageFactory::getCancelRequest(const Order& order) const
{
static OrderCancelRequest msg = initOrderCancelRequest();
msg->setClOrdId(order.cIOrdId_)
.setOrderId(order.orderId_)
.setOrderRequestId(IdGenerator::newIntId())
.setSecurityId(order.securityId_);
return msg;
}
NewOrderCross MessageFactory::initNewOrderCross() const
{
NewOrderCross msg;
msg->setSenderId(sessionId_)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Manual);
return msg;
}
NewOrderCross & MessageFactory::getNewOrderCross(const Order& buySideOrder, const Order& sellSideOrder) const
{
static NewOrderCross msg = initNewOrderCross();
msg->setPrice(
PRICE9(buySideOrder.price_))
.setSecurityId(buySideOrder.securityId_)
.setCrossId(IdGenerator::newIntId())
.setOrderRequestId(IdGenerator::newIntId())
.setTransBkdTime(UtcWatch::now().sinceEpoch());
NewOrderCross544::Sides noSides = msg->sides(2);
NewOrderCross544::SidesEntry buyEntry = noSides[0];
NewOrderCross544::SidesEntry sellEntry = noSides[1];
buyEntry.setClOrdId(buySideOrder.cIOrdId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setOrderQty(buySideOrder.orderQty_)
.setSide(buySideOrder.side_)
.setSideTimeInForce(SideTimeInForce::Day);
sellEntry.setClOrdId(sellSideOrder.cIOrdId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setOrderQty(sellSideOrder.orderQty_)
.setSide(sellSideOrder.side_)
.setSideTimeInForce(SideTimeInForce::Day);
return msg;
}
OrderMassActionRequest MessageFactory::initOrderMassActionRequest() const
{
OrderMassActionRequest msg;
msg->setSenderId(sessionId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Automated);
return msg;
}
OrderMassActionRequest & MessageFactory::getOrderMassActionRequest(MassActionScope::Enum scope, const std::string & traits) const
{
static OrderMassActionRequest msg = initOrderMassActionRequest();
msg->setOrderRequestId(IdGenerator::newIntId())
.setMassActionScope(scope);
switch (scope)
{
case MassActionScope::MarketSegmentID:
{
msg->setMarketSegmentId(fromStr<UInt8>(traits));
break;
}
case MassActionScope::InstrumentGroup:
{
msg->setSecurityGroup(traits);
break;
}
case MassActionScope::Instrument:
{
msg->setSecurityId(fromStr<Int32>(traits));
break;
}
default: {}
}
return msg;
}
RequestForQuote MessageFactory::initRequestForQuote() const
{
RequestForQuote msg;
msg->setSenderId(sessionId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Automated)
.setQuoteType(QuoteTyp::Tradeable);
return msg;
}
RequestForQuote & MessageFactory::getRequestForQuote(UInt32 qti, RFQSide::Enum side, Int32 securityId) const
{
static RequestForQuote msg = initRequestForQuote();
msg->setQuoteReqId(IdGenerator::newIntId());
RequestForQuote543::RelatedSym noRelatedSym = msg->relatedSym(1);
noRelatedSym[0].setOrderQty(qti)
.setSide(side)
.setSecurityId(securityId);
return msg;
}
SecurityDefinitionRequest MessageFactory::initSecurityDefinitionRequest() const
{
SecurityDefinitionRequest msg;
msg->setSenderId(sessionId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Automated)
.setSecuritySubType("COMBO");
return msg;
}
SecurityDefinitionRequest & MessageFactory::getSecurityDefinitionRequest() const
{
static SecurityDefinitionRequest msg = initSecurityDefinitionRequest();
msg->setSecurityReqId(IdGenerator::newIntId());
SecurityDefinitionRequest560::Legs noLegs = msg->legs(2);
noLegs[0].setLegSecurityId(DefaultSecurityId)
.setLegSide(SideReq::Buy)
.setLegPrice(
PRICE9(DefaultPriceMantissa))
.setLegRatioQty(1);
noLegs[1].setLegSecurityId(DefaultSecurityId + 1)
.setLegSide(SideReq::Sell)
.setLegPrice(
PRICE9(DefaultPriceMantissa))
.setLegRatioQty(1);
return msg;
}
OrderMassStatusRequest MessageFactory::initOrderMassStatusRequest() const
{
OrderMassStatusRequest msg;
msg->setSenderId(sessionId_)
.setPartyDetailsListReqId(PartyDetailsListReqID)
.setLocation(Location)
.setManualOrderIndicator(ManualOrdIndReq::Automated);
return msg;
}
OrderMassStatusRequest & MessageFactory::getOrderMassStatusRequest(MassStatusReqTyp::Enum type, const std::string & traits) const
{
static OrderMassStatusRequest msg = initOrderMassStatusRequest();
msg->setMassStatusReqId(IdGenerator::newIntId())
.setMassStatusReqType(type);
switch (type)
{
case MassStatusReqTyp::InstrumentGroup:
{
msg->setSecurityGroup(traits);
break;
}
case MassStatusReqTyp::Instrument:
{
msg->setSecurityId(fromStr<Int32>(traits));
break;
}
case MassStatusReqTyp::MarketSegment:
{
msg->setMarketSegmentId(fromStr<UInt8>(traits));
break;
}
case MassStatusReqTyp::AllOrders:
{
break;
}
}
return msg;
}
}
#include "../Settings/Defaults.h"
#include "TradingClient.h"
namespace Samples
{
const SessionSettings& settings, std::string segment, SessionListener* listener,
UInt64 uuid = Session::UndefinedUuid, const std::string& customKey = "")
{
std::transform(segment.begin(), segment.end(), segment.begin(), ::toupper);
if(segment == "CGW")
return new CgwSession(settings, listener, SessionStorageType::FileBased,
ONIXS_ILINK3_NULLPTR, uuid, customKey);
}
using namespace CUI;
typedef ListViewer<Order> OrdersViewer;
TradingClient::TradingClient(const Settings& settings)
: settings_(settings)
, connected_(false)
, messageFactory_(settings.get("SessionId"))
, menu_(this)
, failover_(settings.getAsBool("FaultTolerance", false))
{
createSessions();
constructMenu();
}
void TradingClient::run()
{
menu_.processRequests();
}
void TradingClient::constructMenu()
{
menu_
.add("Connect Sessions.", "Sending Negotiation/Establishment.. ", &TradingClient::establishConnection)
.add("Review the status of sessions. ", "Viewing the status of sessions.. ", &TradingClient::onViewSessions)
.add("Send Sequence. ", "Sending Sequence.. ", &TradingClient::onSendSequence)
.add("Review sent orders and their status. ", "Viewing sent orders and their status.. ", &TradingClient::onViewOrders)
.add("Create and send a New Order. ", "Creating new order.. ", &TradingClient::onSendNewOrder)
.add("Submit Order Modify Request. ", "Order Modify Request.. ", &TradingClient::onOrderModifyRequest)
.add("Submit Order Cancel Request. ", "Order Cancel Request.. ", &TradingClient::onOrderCancelRequest)
.add("Submit Order Mass Action Request. ", "Order Mass Action Request.. ", &TradingClient::onOrderMassActionRequest)
.add("Submit Order Mass Status Request. ", "Order Mass Status Request.. ", &TradingClient::onMassStatusRequest)
.add("Submit SecurityDefinitionRequest. ", "Creating SecurityDefinition.. ", &TradingClient::onSecurityDefinitionRequest)
.add("Submit RequestForQuote. ", "Creating RFQ.. ", &TradingClient::onRequestForQuote)
.add("Submit New Order Cross. ", "Creating Cross Order.. ", &TradingClient::onCrossOrder)
.add("Disconnect all sessions", "Closing connections...", &TradingClient::disconnect)
.add("Reset Sequence Numbers", "Reset Sequence Numbers", &TradingClient::resetSequenceNumbers)
.add("Close the connection and exit. ", "Exiting application.. ", &TradingClient::onExit);
}
bool TradingClient::checkSessionConnected()
{
if (!connected_)
Screen::info("Session is not connected. Please establish the connection first.");
return connected_;
}
void TradingClient::createSessions()
{
Screen::info("Creating the primary iLink3 Session..");
SessionSettings settings;
settings
.licenseStore("../../license")
.sessionId(settings_.get("SessionId"))
.secretKey(settings_.get("SecretKey"))
.accessKey(settings_.get("AccessKey"))
.firmId(settings_.get("FirmId"))
.tradingSystemName(settings_.get("TradingSystemName"))
.tradingSystemVersion(settings_.get("TradingSystemVersion"))
.tradingSystemVendor(settings_.get("TradingSystemVendor"))
.keepAliveInterval(settings_.getAsInt("KeepAliveInterval"));
primarySession_.reset(createSession(settings, settings_.get("MarketSegment"), this));
const int incomingSequenceNumber = settings_.getAsInt("InSeqNum");
if (incomingSequenceNumber > 0)
primarySession_->inSeqNum(incomingSequenceNumber);
const int outgoingSequenceNumber = settings_.getAsInt("OutSeqNum");
if (outgoingSequenceNumber > 0)
primarySession_->outSeqNum(outgoingSequenceNumber);
if (failover_)
{
Screen::info("Creating the backup iLink3 Session..");
backupSession_.reset(
createSession(settings, settings_.get("MarketSegment"), this, primarySession_->uuid(), "Backup"));
backupSession_->faultToleranceIndicator(FTI::Backup);
}
}
void TradingClient::establishConnection(CommandExecutionStatus* status)
{
if (!connected_)
{
try
{
primarySession_->connect(settings_.get("Host"), settings_.getAsInt("Port"));
}
catch (const std::exception& ex)
{
Screen::info("Cannot connect to the primary host: ", ex.what());
if (!failover_)
throw;
}
if (failover_)
{
try
{
backupSession_->connect(settings_.get("BackupHost"), settings_.getAsInt("BackupPort"));
}
catch (const std::exception& ex)
{
Screen::info("Cannot connect to the backup host: ", ex.what());
throw;
}
}
Screen::info("Done");
}
else
Screen::info("Connection is already established.");
*status = ContinueExecution;
}
void TradingClient::disconnect(CommandExecutionStatus*)
{
if (failover_)
{
if (
ONIXS_ILINK3_NULLPTR != backupSession_.get() && backupSession_->state() != SessionStateId::Disconnected)
{
Screen::info("Disconnecting from backup counterparty.. ");
backupSession_->disconnect();
}
}
if (
ONIXS_ILINK3_NULLPTR != primarySession_.get() && primarySession_->state() != SessionStateId::Disconnected)
{
Screen::info("Disconnecting from primary counterparty.. ");
primarySession_->disconnect();
}
Screen::info("Done");
}
void TradingClient::onSendSequence(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
if (failover_)
{
if (FTI::Primary == primarySession_->faultToleranceIndicator())
primarySession_->sendSequenceMessage();
else if (FTI::Primary == backupSession_->faultToleranceIndicator())
backupSession_->sendSequenceMessage();
else
Screen::info("Cannot send a Sequence message because there is no a session with the primary role.");
}
else
primarySession_->sendSequenceMessage();
Screen::info("Done");
}
void TradingClient::onViewOrders(CommandExecutionStatus*)
{
OrderList orderList;
orderBook_.getEntries(orderList);
OrdersViewer::outputItems(orderList, 10);
}
void TradingClient::onViewSessions(CommandExecutionStatus*)
{
Screen::info(std::string("Fail-over is ") + (failover_ ? "on." : "off."));
Screen::info("Primary iLink3 session: ",
primarySession_->toString() + ", State=" + SessionStateId::toString(primarySession_->state()) +
".");
if (failover_)
Screen::info("Backup iLink3 session: ",
backupSession_->toString() + ", State=" + SessionStateId::toString(backupSession_->state()) +
".");
}
void TradingClient::onOrderMassActionRequest(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
Screen::info("Sending Order Mass Action Request to counterparty.. ");
Screen::info("Enter MassActionScope (1=Instrument (default), 9=Market Segment ID, 10=Group Code): ");
const MassActionScope::Enum massActionScope = Screen::getInput<MassActionScope::Enum>(MassActionScope::Instrument);
Screen::info(
"Enter " +
toStr(massActionScope) +
" : ");
const std::string traits = Screen::getInput();
OrderMassActionRequest & msg = messageFactory_.getOrderMassActionRequest(massActionScope, traits);
send(msg);
Screen::info("Done");
}
void TradingClient::onRequestForQuote(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
Screen::info("Sending Request For Quote to counterparty.. ");
Screen::info("Enter Qty (default = 100):");
const UInt32 qti = Screen::getInput<UInt32>(100u);
Screen::info("Enter Side ( 1 = Buy (default), 2 = Sell, 8 = Cross): ");
const RFQSide::Enum side = Screen::getInput<RFQSide::Enum>(RFQSide::Buy);
Screen::info(
"Enter SecurityId (default=" +
toStr(DefaultSecurityId) +
"): ");
const Int32 securityId = Screen::getInput<Int32>(DefaultSecurityId);
RequestForQuote & msg = messageFactory_.getRequestForQuote(qti, side, securityId);
send(msg);
Screen::info("Done");
}
void TradingClient::onSecurityDefinitionRequest(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
Screen::info("Sending Security Definition Request to counterparty.. ");
SecurityDefinitionRequest & msg = messageFactory_.getSecurityDefinitionRequest();
send(msg);
Screen::info("Done");
}
void TradingClient::onMassStatusRequest(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
Screen::info("Sending Mass Status Request to counterparty.. ");
Screen::info("Enter massStatusReqType (1 = Instrument (default), 3 = Group Code, 100 = Market Segment : ");
const MassStatusReqTyp::Enum massStatusReqType = Screen::getInput<MassStatusReqTyp::Enum>(
MassStatusReqTyp::Instrument);
Screen::info(
"Enter " +
toStr(massStatusReqType) +
" : ");
const std::string traits = Screen::getInput();
OrderMassStatusRequest & msg = messageFactory_.getOrderMassStatusRequest(massStatusReqType, traits);
send(msg);
Screen::info("Done");
}
void TradingClient::onSendNewOrder(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
Screen::info("Sending new order to counterparty.. ");
Order order = newOrder();
NewOrderSingle & msg = messageFactory_.getNewOrder(order);
send(msg);
orderBook_.store(order);
Screen::info("Done");
}
void TradingClient::onOrderCancelRequest(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
OrderList ordersInBook;
orderBook_.getEntries(ordersInBook);
if (ordersInBook.empty())
{
Screen::info("No orders found");
return;
}
OrdersViewer orderViewer;
orderViewer.outputItems(ordersInBook, 10);
Screen::out("Enter the index of the order to be canceled ");
const int orderIndex = atoi(Screen::getInput().c_str());
const Order * order = ordersInBook.at(orderIndex - 1);
OrderCancelRequest & msg = messageFactory_.getCancelRequest(*order);
send(msg);
Screen::info("Done");
}
void TradingClient::onOrderModifyRequest(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
OrderList ordersInBook;
orderBook_.getEntries(ordersInBook);
if (ordersInBook.empty())
{
Screen::info("No orders found");
return;
}
OrdersViewer orderViewer;
orderViewer.outputItems(ordersInBook, 10);
Screen::out("Enter the index of the order to be modified ");
const int orderIndex = atoi(Screen::getInput().c_str());
Order* const order = ordersInBook.at(orderIndex - 1);
Screen::info("Enter new OrderQty (or Enter to skip): ");
Screen::getInput(order->orderQty_, order->orderQty_);
Screen::info("Enter new Price mantissa (or Enter to skip): ");
Screen::getInput(order->price_, order->price_);
OrderCancelReplaceRequest & msg = messageFactory_.getModifyRequest(*order);
send(msg);
Screen::info("Done");
}
void TradingClient::onCrossOrder(CommandExecutionStatus*)
{
if (!checkSessionConnected())
return;
Order buySideOrder;
Screen::info(
"Enter Price mantissa (default = " +
toStr(DefaultPriceMantissa) +
"): ");
Screen::getInput(buySideOrder.price_, DefaultPriceMantissa);
Screen::info(
"Enter SecurityId (default=" +
toStr(DefaultSecurityId) +
"): ");
Screen::getInput(buySideOrder.securityId_, DefaultSecurityId);
Screen::info("Enter Quantity (default = 100): ");
Screen::getInput(buySideOrder.orderQty_, 100u);
Order sellSideOrder;
sellSideOrder
.price(buySideOrder.price_)
.securityId(buySideOrder.securityId_)
.orderQty(buySideOrder.orderQty_)
.side(SideReq::Sell);
NewOrderCross & msg = messageFactory_.getNewOrderCross(buySideOrder, sellSideOrder);
send(msg);
orderBook_
.store(buySideOrder)
.store(sellSideOrder);
Screen::info("Done");
}
void TradingClient::onExit(CommandExecutionStatus* status)
{
*status = TerminateExecution;
}
void TradingClient::resetSequenceNumbers(CommandExecutionStatus*)
{
if (
ONIXS_ILINK3_NULLPTR != primarySession_.get() && primarySession_->state() == SessionStateId::Disconnected)
{
if(primarySession_->negotiated())
primarySession_->reset(false);
}
else
Screen::info("Operation can be performed only when the sessions are disconnected");
if (failover_ && backupSession_->state() == SessionStateId::Disconnected && backupSession_->negotiated())
backupSession_->reset(false);
Screen::info("Done");
}
Order TradingClient::newOrder()
{
Order order;
Screen::info(
"Enter SecurityId (default=" +
toStr(DefaultSecurityId) +
"): ");
Screen::getInput(order.securityId_, DefaultSecurityId);
Screen::info(
"Enter OrderType(40) (1-Market order, 2 - Limit order (default), 3 - Stop order, 4 - Stop - Limit order, K - Market - Limit order): ");
Screen::getInputChar(order.ordType_, OrderTypeReq::Limit);
if (order.ordType_ == OrderTypeReq::Limit || order.ordType_ == OrderTypeReq::StopLimit)
{
Screen::info(
"Enter Price mantissa (default = " +
toStr(DefaultPriceMantissa) +
"): ");
Screen::getInput(order.price_, DefaultPriceMantissa);
}
if (order.ordType_ == OrderTypeReq::StopLimit || order.ordType_ == OrderTypeReq::StopwithProtection)
{
Screen::info("Enter StopPx: ");
Screen::getInput(order.stopPx_);
}
Screen::info("Enter OrderQuantity (default = 100): ");
Screen::getInput(order.orderQty_, 100u);
Screen::info("Enter MinQty or skip");
Screen::getInput(order.minQty_,
NullUInt32().value());
Screen::info("Enter DisplayQty or skip");
Screen::getInput(order.displayQty_,
NullUInt32().value());
Screen::info(
"Enter TimeInForce (0 - Day (default), 1 - Good Till Cancel, 3 - Fill and Kill, 6 - Good Till Date): ");
Screen::getInput(order.timeInForce_, TimeInForce::Day);
if (order.timeInForce_ == TimeInForce::GoodTillDate)
{
Screen::info("Enter Expire date YYYYMMDD: ");
Screen::getInputLocalMktDate(order.expireDate_);
}
Screen::info("Enter Side (1 - Buy (default), 2 - Sell): ");
Screen::getInput(order.side_, SideReq::Buy);
return order;
}
void TradingClient::onMessageSending(char* bytes, size_t size, Session*)
{
Screen::out("Outbound message: ", SbeMessage(bytes, static_cast<Messaging::MessageSize>(size)));
}
void TradingClient::onBusinessReject(const BusinessReject521 & msg, Session * sn)
{
Screen::info("BusinessReject received from counterparty: ", msg.toString());
Screen::info("Reject reason : ", BusinessRejectReason::toString(msg.businessRejectReason())
+ (msg.refTagId(refTagId) ?
", refTagId=" +
toStr(refTagId) : std::string()));
if (!msg.refSeqNum(refSeqNum))
sn->outSeqNum(sn->outSeqNum() - 1);
}
void TradingClient::onNegotiationResponse(const NegotiationResponse501 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onNegotiationReject(const NegotiationReject502 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onEstablishmentAck(const EstablishmentAck504 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onEstablishmentReject(const EstablishmentReject505 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onSequence(const Sequence506 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onTerminate(const Terminate507 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onRetransmitReject(const Messaging::RetransmitReject510 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onRetransmission(const Messaging::Retransmission509 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
NotAppliedAction::Enum TradingClient::onNotApplied(const Messaging::NotApplied513 & msg, Session * sn)
{
Screen::info("Message received from counterparty: ", msg.toString());
return SessionListener::onNotApplied(msg, sn);
}
void TradingClient::onExecutionReportNew(const ExecutionReportNew522 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
setOrdStatus(order->orderStatus_, msg);
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportModify(const ExecutionReportModify531 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
setOrdStatus(order->orderStatus_, msg);
order->leavesQty(msg.leavesQty())
.cumQty(msg.cumQty());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportCancel(const ExecutionReportCancel534 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
setOrdStatus(order->orderStatus_, msg);
order->leavesQty(msg.cumQty());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportReject(const ExecutionReportReject523 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
setOrdStatus(order->orderStatus_, msg);
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportStatus(const ExecutionReportStatus532 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
order->orderStatus(OrderStatus::toString(msg.ordStatus()))
.leavesQty(msg.leavesQty())
.cumQty(msg.cumQty());
Screen::info("Order changed: " + order->toString());
BooleanNULL::Enum lastRptRequested = BooleanNULL::Enum();
if (msg.lastRptRequested(lastRptRequested))
Screen::info(
"LastRptRequested = " +
toStr(lastRptRequested));
if (msg.massStatusReqId(massStatusReqId))
Screen::info(
"MassStatusReqID = " +
toStr(massStatusReqId));
}
void TradingClient::onExecutionReportTradeOutright(const ExecutionReportTradeOutright525 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
order->orderStatus(OrdStatusTrd::toString(msg.ordStatus()))
.leavesQty(msg.leavesQty())
.cumQty(msg.cumQty())
.lastPx(msg.lastPx().mantissa());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportTradeSpread(const ExecutionReportTradeSpread526 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
order->orderStatus(OrdStatusTrd::toString(msg.ordStatus()))
.leavesQty(msg.leavesQty())
.cumQty(msg.cumQty())
.lastPx(msg.lastPx().mantissa());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportTradeSpreadLeg(const ExecutionReportTradeSpreadLeg527 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
order->orderId(msg.orderId());
order->securityId(msg.securityId());
order->orderStatus(OrdStatusTrd::toString(msg.ordStatus()));
order->cumQty(msg.cumQty());
order->lastPx(msg.lastPx().mantissa());
order->transactTime(msg.transactTime());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportElimination(const ExecutionReportElimination524 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
setCommonFields(order, msg);
setOrdStatus(order->orderStatus_, msg);
order->leavesQty(msg.cumQty());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportTradeAddendumOutright(const ExecutionReportTradeAddendumOutright548 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
order->orderId(msg.orderId())
.securityId(msg.securityId())
.orderStatus(OrdStatusTrdCxl::toString(msg.ordStatus()))
.lastPx(msg.lastPx().mantissa())
.transactTime(msg.transactTime());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportTradeAddendumSpread(const ExecutionReportTradeAddendumSpread549 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
order->orderId(msg.orderId())
.securityId(msg.securityId())
.orderStatus(OrdStatusTrdCxl::toString(msg.ordStatus()))
.lastPx(msg.lastPx().mantissa())
.transactTime(msg.transactTime());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onExecutionReportTradeAddendumSpreadLeg(const ExecutionReportTradeAddendumSpreadLeg550 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
if(msg.possRetransFlag())
return;
Order * const order = findByOrderId(msg);
assert(order);
order->orderId(msg.orderId())
.securityId(msg.securityId())
.orderStatus(OrdStatusTrdCxl::toString(msg.ordStatus()))
.lastPx(msg.lastPx().mantissa())
.transactTime(msg.transactTime());
Screen::info("Order changed: " + order->toString());
}
void TradingClient::onOrderCancelReject(const OrderCancelReject535 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onOrderCancelReplaceReject(const OrderCancelReplaceReject536 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onSecurityDefinitionResponse(const SecurityDefinitionResponse561 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onMassQuoteAck(const MassQuoteAck545 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onRequestForQuoteAck(const RequestForQuoteAck546 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onQuoteCancelAck(const QuoteCancelAck563& msg, Session*)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onOrderMassActionReport(const OrderMassActionReport562& msg, Session*)
{
Screen::info("Received Order Mass Action Report: ", msg.toString());
Screen::info(
"MassActionScope=",
toStr(msg.massActionScope()));
Screen::info(
"MassActionResponse=",
toStr(msg.massActionResponse()));
if (msg.marketSegmentId(marketSegmentId))
Screen::info(
"MarketSegmentID=",
toStr(marketSegmentId));
}
void TradingClient::onPartyDetailsDefinitionRequestAck(const PartyDetailsDefinitionRequestAck519 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onPartyDetailsListReport(const PartyDetailsListReport538 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onExecutionReportPendingCancel(const Messaging::ExecutionReportPendingCancel564 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onExecutionReportPendingReplace(const Messaging::ExecutionReportPendingReplace565 & msg, Session *)
{
Screen::info("Message received from counterparty: ", msg.toString());
}
void TradingClient::onStateChange(SessionStateId::Enum newState, SessionStateId::Enum , Session *)
{
Screen::info("Session state changed to ", SessionStateId::toString(newState));
connected_ = (newState == SessionStateId::Established);
}
void TradingClient::onFailover(FTI::Enum faultToleranceIndicator, Session * sn)
{
const bool IsPrimarySession = (sn == primarySession_.get());
Screen::info(
"Changing the session role of " + std::string(IsPrimarySession ? "primary" : "backup") + " session to " +
toStr(faultToleranceIndicator) +
" ..");
if (faultToleranceIndicator == FTI::Primary)
{
if (sn == backupSession_.get())
{
backupSession_
->inSeqNum(primarySession_->inSeqNum())
.outSeqNum(primarySession_->outSeqNum());
primarySession_->faultToleranceIndicator(FTI::Backup);
}
else
{
primarySession_
->inSeqNum(backupSession_->inSeqNum())
.outSeqNum(backupSession_->outSeqNum());
backupSession_->faultToleranceIndicator(FTI::Backup);
}
}
}
void TradingClient::onError(SessionErrorReason::Enum, const std::string & description, Session *, Messaging::SbeMessage)
{
Screen::info("Session-level error: ", description);
}
void TradingClient::onWarning(SessionWarningReason::Enum, const std::string & description, Session *, Messaging::SbeMessage)
{
Screen::info("Session-level warning: ", description);
}
}