• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Executions and Commissions

When an order is filled either fully or partially, the IBApi.EWrapper.execDetails and IBApi.EWrapper.commissionReport events will deliver IBApi.Execution and IBApi.CommissionReport objects. This allows to obtain the full picture of the order's execution and the resulting commissions.

  • Advisors executing allocation orders will receive execution details and commissions for the allocation order itself. To receive allocation details and commissions for a specific subaccount IBApi.EClient.reqExecutions can be used.

Important: To receive commissions reports for all clients it is necessary to connect as the Master Client ID.

  • public class EWrapperImpl : EWrapper
    {
    ...
    public virtual void execDetails(int reqId, Contract contract, Execution execution)
    {
    Console.WriteLine("ExecDetails. " + reqId + " - " + contract.Symbol + ", " + contract.SecType+", " + contract.Currency+" - " + execution.ExecId + ", " + Util.IntMaxString(execution.OrderId) +
    ", " + Util.DecimalMaxString(execution.Shares) + ", " + Util.DecimalMaxString(execution.CumQty) + ", " + execution.LastLiquidity + ", " + execution.PendingPriceRevision);
    }
    ...
    public virtual void commissionReport(CommissionReport commissionReport)
    {
    Console.WriteLine("CommissionReport. " + commissionReport.ExecId + " - " + Util.DoubleMaxString(commissionReport.Commission) + " " + commissionReport.Currency + " RPNL " + Util.DoubleMaxString(commissionReport.RealizedPNL));
    }
  • public class EWrapperImpl implements EWrapper {
    ...
    @Override
    public void execDetails(int reqId, Contract contract, Execution execution) {
    System.out.println(EWrapperMsgGenerator.execDetails( reqId, contract, execution));
    }
    ...
    @Override
    public void commissionReport(CommissionReport commissionReport) {
    System.out.println(EWrapperMsgGenerator.commissionReport(commissionReport));
    }
  • Public Class EWrapperImpl
    Implements EWrapper
    ...
    Public Sub execDetails(reqId As Integer, contract As IBApi.Contract, execution As IBApi.Execution) Implements IBApi.EWrapper.execDetails
    Console.WriteLine("ExecDetails - ReqId [" & reqId & "] Contract [" & contract.Symbol & ", " & contract.SecType &
    "] Execution [Price: " & Util.DoubleMaxString(execution.Price) & ", Exchange: " & execution.Exchange & ", Last Liquidity: " & execution.LastLiquidity.ToString() & ", Shares: " & Util.DecimalMaxString(execution.Shares) & ", Cum Qty: " & Util.DecimalMaxString(execution.CumQty) & ", Pending Price Revision: " & execution.PendingPriceRevision & "]")
    End Sub
    ...
    Public Sub commissionReport(commissionReport As IBApi.CommissionReport) Implements IBApi.EWrapper.commissionReport
    Console.WriteLine("CommissionReport - CommissionReport [" & Util.DoubleMaxString(commissionReport.Commission) & " " & commissionReport.Currency & "]")
    End Sub
  • class TestCppClient : public EWrapper
    {
    ...
    void TestCppClient::execDetails( int reqId, const Contract& contract, const Execution& execution) {
    printf( "ExecDetails. ReqId: %d - %s, %s, %s - %s, %s, %s, %s, %s, %s\n", reqId, contract.symbol.c_str(), contract.secType.c_str(), contract.currency.c_str(), execution.execId.c_str(), Utils::longMaxString(execution.orderId).c_str(), DecimalFunctions::decimalStringToDisplay(execution.shares).c_str(), DecimalFunctions::decimalStringToDisplay(execution.cumQty).c_str(), Utils::intMaxString(execution.lastLiquidity).c_str(), (execution.pendingPriceRevision ? "yes" : "no"));
    }
    ...
    void TestCppClient::commissionReport( const CommissionReport& commissionReport) {
    printf( "CommissionReport. %s - %s %s RPNL %s\n", commissionReport.execId.c_str(), Utils::doubleMaxString(commissionReport.commission).c_str(), commissionReport.currency.c_str(), Utils::doubleMaxString(commissionReport.realizedPNL).c_str());
    }
  • 1 class TestWrapper(wrapper.EWrapper):
    ...
    1  def execDetails(self, reqId: int, contract: Contract, execution: Execution):
    2  super().execDetails(reqId, contract, execution)
    3  print("ExecDetails. ReqId:", reqId, "Symbol:", contract.symbol, "SecType:", contract.secType, "Currency:", contract.currency, execution)
    ...
    1  def commissionReport(self, commissionReport: CommissionReport):
    2  super().commissionReport(commissionReport)
    3  print("CommissionReport.", commissionReport)
  • Note if a correction to an execution is published it will be received as an additional IBApi.EWrapper.execDetails callback with all parameters identical except for the execID in the Execution object. The execID will differ only in the digits after the final period.

Requesting Executions

IBApi.Execution and IBApi.CommissionReport can be requested on demand via the IBApi.EClient.reqExecutions method which receives a IBApi.ExecutionFilter object as parameter to obtain only those executions matching the given criteria. An empty IBApi.ExecutionFilter object can be passed to obtain all previous executions.

  • client.reqExecutions(10001, new ExecutionFilter());
  • client.reqExecutions(10001, new ExecutionFilter());
  • client.reqExecutions(10001, New ExecutionFilter())
  • m_pClient->reqExecutions(10001, ExecutionFilter());
  • 1  self.reqExecutions(10001, ExecutionFilter())

Once all matching executions have been delivered, an IBApi.EWrapper.execDetailsEnd event will be triggered.

  • public class EWrapperImpl : EWrapper
    {
    ...
    public virtual void execDetailsEnd(int reqId)
    {
    Console.WriteLine("ExecDetailsEnd. "+reqId+"\n");
    }
  • public class EWrapperImpl implements EWrapper {
    ...
    @Override
    public void execDetailsEnd(int reqId) {
    System.out.println("Exec Details End: " + EWrapperMsgGenerator.execDetailsEnd( reqId));
    }
  • Public Class EWrapperImpl
    Implements EWrapper
    ...
    Public Sub execDetailsEnd(reqId As Integer) Implements IBApi.EWrapper.execDetailsEnd
    Console.WriteLine("ExecDetailsEnd - ReqId [" & reqId & "]")
    End Sub
  • class TestCppClient : public EWrapper
    {
    ...
    void TestCppClient::execDetailsEnd( int reqId) {
    printf( "ExecDetailsEnd. %d\n", reqId);
    }
  • 1 class TestWrapper(wrapper.EWrapper):
    ...
    1  def execDetailsEnd(self, reqId: int):
    2  super().execDetailsEnd(reqId)
    3  print("ExecDetailsEnd. ReqId:", reqId)

Important: By default, only those executions occurring since midnight for that particular account will be delivered. If you want to request executions up to last 7 days, TWS's Trade Log setting "Show trades for ..." must be adjusted to your requirement. Please note, that IB Gateway would be unable to change the Trade Log's settings, thus limited to only executions since midnight to be delivered.