Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / All-Topics

Receive Trade Capture (AE) Report on FIX Protocol

0.00/5 (No votes)
29 Sep 2018CPOL2 min read 5.9K  
Trade Capture Report (AE) is a post-trade message which is sent by the broker or exchange to report the trades for the participants.

Trade Capture Report (AE) message is a post-trade message which is sent by the broker or exchange to report the trades for participant.

How to Request Trade Capture Report?

A client may use Trade Capture Report Request (AD) to subscribe for trade capture reports based upon selection criteria provided on the trade capture report request.

The server will respond with a Trade Capture Report Request Ack (AR) to indicate, via the TradeRequestStatus (750) and TradeRequestResult (749) fields, whether the request is successful or not. Sometimes if the Trade Capture Report Request message is rejected due to some validations, a Reject message can be generated as the response.

Trade Capture Report Request (AD) Message Structure

Tag Field Name Req Description
568 TradeRequestID Y Request unique identifier
569 TradeRequestType Y Type of request
  • 0: All Trades
  • 1: Trades Matching Specified Criteria If none of the criteria below are specified, this will return all trades.
150 ExecType N Request for all trades of a specific execution type
  <Instrument> block N Request for all trades for the list of instruments
  =>Symbol   Symbol name
  => SecurityId   Security Id
  =>……    

You need to remember that these are standard fields for Trade Capture Report Request (AD) message, the list of supported fields may vary between various FIX formats.

Also, always follow the Rules of engagement document provided by the broker before implementing FIX messages.

Trade Capture Report Request Ack (AC) Message

It is acknowledged message to Trade Capture Report Request (AD)

Tag FieldName Req Description
568 TradeRequestID Y Identifier of the request being acknowledged
569 TradeRequestType Y Identifier of the request being acknowledged
750 TradeRequestStatus Y Whether the request is accepted or rejected
0: Accepted
1: Rejected
749 TradeRequestResult Y Reason the request is rejected.
0: Successful
9: Not Authorized
100: Cannot Match Selection Criteria 200: Request Limit for Day Reached

Trade Capture Report

It is a response message to TradeCapture Report Request (AD) which reports trades between counterparties.

Message Structure

Tag Field Name Req Description
568 TradeRequestID Y Request unique identifier
571 TradeReportID Y Unique Id of response message
17 ExecId Y Identifier of the trade
48 SecurityId N Instrument Id
55 Symbol N Symbol name
32 LastQty Y Traded Quantity
31 LastPx Y Traded Price
75 TradeDate Y Traded date
60 TransactTime Y Transaction time of a trade

Implementation

TradeCaptureReportRequest (AD)

C#
TradeCaptureReportRequest request = new TradeCaptureReportRequest();

string requestId = DateTime.UtcNow.ToString("yyyyMMddHHmmssfff");//generate unique request ID
request.TradeRequestID = new TradeRequestID(requestId);
request.TradeRequestType = new TradeRequestType
(TradeRequestType.MATCHED_TRADES_MATCHING_CRITERIA_PROVIDED_ON_REQUEST);

request.NoDates = new NoDates(2);
//Criteria to get trades between two dates
var noDatesGroup = new TradeCaptureReportRequest.NoDatesGroup();
noDatesGroup.TransactTime = new TransactTime(start);
request.AddGroup(noDatesGroup);
noDatesGroup = new TradeCaptureReportRequest.NoDatesGroup();
noDatesGroup.TransactTime = new TransactTime(end);
request.AddGroup(noDatesGroup);
<br>Session.SendToTarget(request, sessionId);

TradeCaptureReportRequest Ack (AC)

C#
public void OnMessage(TradeCaptureReportRequestAck ackReport, SessionID session)
{
	if (ackReport.TradeRequestStatus.getValue() == TradeRequestStatus.REJECTED)
	{
	  if (OnReject != null)
	   Console.WriteLine("TradeReportRequest Rejected");
	}
	else if (ackReport.TradeRequestStatus.getValue() == TradeRequestStatus.ACCEPTED)
	{
	   Console.WriteLine("TradeReportRequestStatus Accepted");
	}
	else if (ackReport.TradeRequestStatus.getValue() == TradeRequestStatus.COMPLETED)
	{
	  Console.WriteLine("TradeReportRequestStatus COMPLETED");
	}
}

TradeCaptureReport (AE)

C#
public override void OnMessage(TradeCaptureReport ackReport, SessionID session)
{
    //Capturing data in DTO
	TradeReport tradeReport = new TradeReport
	{
	  Id = ackReport.ExecID.getValue(),
	  LastQty = ackReport.LastQty.getValue(),
	  TransactTime = ackReport.IsSetTransactTime() ? 
                     ackReport.TransactTime.getValue() : DateTime.UtcNow,
	  LastPrice = ackReport.LastPx.getValue(),
	  InstrumentId = Convert.ToInt32(ackReport.SecurityID.getValue())
	};

	NoSides noSides = ackReport.NoSides;
	tradeReport.Symbol = _symbolMap[tradeReport.InstrumentId];

	var group = new TradeCaptureReport.NoSidesGroup();
	group = (TradeCaptureReport.NoSidesGroup)ackReport.GetGroup(1, group);
	if (group.IsSetSide())
	{
		switch (group.Side.getValue())
		{
		 case Side.BUY:
		  tradeReport.Side = BuySellType.Buy;
		  break;
		  case Side.SELL:
		   tradeReport.Side = BuySellType.Sell;
		  break;
		}
	}
	tradeReport.OrderId = group.OrderID.getValue();
	tradeReport.ClientOrderId = group.ClOrdID.getValue();
}

You can download the code from Github here.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)