Beispiel #1
0
        public void OnExecutionReport(object sender, ExecutionReportEventArgs e)
        {
            if (ExecutionReport != null)
            {
                QuickFix42.ExecutionReport sourceReport = e.ExecutionReport;
                try
                {
                    SmartQuant.FIX.ExecutionReport report = new SmartQuant.FIX.ExecutionReport();
                    if (sourceReport.isSetField(41))//如果已有原始编号OrigClOrdID
                    {
                        report.OrigClOrdID = sourceReport.getOrigClOrdID().getValue();
                    }
                    else if (sourceReport.isSetField(11))//如果有标识委托所对应的ClOrdID
                    {
                        report.ClOrdID = sourceReport.getClOrdID().getValue();
                    }

                    report.ExecID = sourceReport.getExecID().getValue();
                    char execType = sourceReport.getExecType().getValue();
                    //Console.WriteLine(execType);
                    switch (execType)//订单执行结果
                    {
                    case '0':
                        report.ExecType = ExecType.New;
                        break;

                    case '1':
                        report.ExecType = ExecType.PartialFill;
                        break;

                    case '2':
                        report.ExecType = ExecType.Fill;
                        break;

                    case '4':
                        report.ExecType = ExecType.Cancelled;
                        break;

                    case '6':
                        report.ExecType = ExecType.PendingCancel;
                        break;

                    case '8':
                        report.ExecType = ExecType.Rejected;
                        break;

                    default:
                        report.ExecType = ExecType.Undefined;
                        break;
                    }
                    if ((execType == '1') || (execType == '2'))                   //执行结果是部分成交或是全部成交
                    {
                        report.LastPx  = sourceReport.getLastPx().getValue();     //本次成交均价
                        report.LastQty = sourceReport.getLastShares().getValue(); //本次成交数量
                    }
                    report.OrderQty = sourceReport.getOrderQty().getValue();      //订单委托量

                    char orderStatus = sourceReport.getOrdStatus().getValue();
                    if (orderStatus == '1' || orderStatus == '2')               //订单状态是部分成交或是全部成交
                    {
                        report.AvgPx     = sourceReport.getAvgPx().getValue();  //平均成交价
                        report.CumQty    = sourceReport.getCumQty().getValue(); //累计成交量
                        report.LeavesQty = report.OrderQty - report.CumQty;     //未成交量
                    }

                    switch (orderStatus)
                    {
                    case '0':
                        report.OrdStatus = OrdStatus.New;
                        break;

                    case '1':
                        report.OrdStatus = OrdStatus.PartiallyFilled;
                        break;

                    case '2':
                        report.OrdStatus = OrdStatus.Filled;
                        break;

                    case '4':
                        report.OrdStatus = OrdStatus.Cancelled;
                        break;

                    case '6':
                        report.OrdStatus = OrdStatus.PendingCancel;
                        break;

                    case '8':
                        report.OrdStatus = OrdStatus.Rejected;
                        break;

                    default:
                        report.OrdStatus = OrdStatus.Undefined;
                        break;
                    }
                    if (sourceReport.isSetTransactTime())//传送时间
                    {
                        report.TransactTime = sourceReport.getTransactTime().getValue();
                    }
                    if (sourceReport.isSetText())
                    {
                        report.Text = sourceReport.getText().getValue();
                    }
                    ExecutionReport(this, new SmartQuant.FIX.ExecutionReportEventArgs(report));
                }
                catch (Exception ex)
                {
                    EmitError(-1, -1, ex.Message);
                }
            }
        }
        public override void onMessage(QuickFix42.ExecutionReport report, QuickFix.SessionID sessionID)
        {
            if (report.getExecType().getValue() == QuickFix.ExecType.PENDING_CANCEL ||
                report.getExecType().getValue() == QuickFix.ExecType.CANCELED ||
                report.getExecType().getValue() == QuickFix.ExecType.PENDING_REPLACE ||
                report.getExecType().getValue() == QuickFix.ExecType.REPLACE)
            {
                object request = cancelRequests[report.getClOrdID().getValue()];

                if (request == null)
                {
                    report.set(new OrigClOrdID(report.getClOrdID().getValue()));
                }
                else
                {
                    if (request is FIXOrderCancelRequest)
                    {
                        report.set(new OrigClOrdID((request as FIXOrderCancelRequest).OrigClOrdID));
                    }

                    if (request is FIXOrderCancelReplaceRequest)
                    {
                        report.set(new OrigClOrdID((request as FIXOrderCancelReplaceRequest).OrigClOrdID));
                    }
                }
            }

            ExecutionReport Report = new ExecutionReport();

            if (report.isSetOrderID())
            {
                Report.OrderID = report.getOrderID().getValue();
            }
            ////if (report.isSetSecondaryOrderID()) Report.SecondaryOrderID = report.getSecondaryOrderID().getValue();
            if (report.isSetClOrdID())
            {
                Report.ClOrdID = report.getClOrdID().getValue();
            }
            if (report.isSetOrigClOrdID())
            {
                Report.OrigClOrdID = report.getOrigClOrdID().getValue();
            }
            ////if (report.isSetListID()) Report.ListID = report.getListID().getValue();
            if (report.isSetExecID())
            {
                Report.ExecID = report.getExecID().getValue();
            }
            ////if (report.isSetExecRefID()) Report.ExecRefID = report.getExecRefID().getValue();
            if (report.isSetExecType())
            {
                (Report as FIXExecutionReport).ExecType = report.getExecType().getValue();
            }
            if (report.isSetOrdStatus())
            {
                (Report as FIXExecutionReport).OrdStatus = report.getOrdStatus().getValue();
            }
            if (report.isSetOrdRejReason())
            {
                Report.OrdRejReason = report.getOrdRejReason().getValue();
            }
            ////if (report.isSetExecRestatementReason()) Report.ExecRestatementReason = report.getExecRestatementReason().getValue();
            ////if (report.isSetAccount()) Report.Account = report.getAccount().getValue();
            ////if (report.isSetSettlmntTyp()) Report.SettlType = report.getSettlmntTyp().getValue();
            //if (report.isSetFutSettDate           ()) Report.FutSettDate            = report.getFutSettDate           ().getValue();
            if (report.isSetSymbol())
            {
                Report.Symbol = report.getSymbol().getValue();
            }
            ////if (report.isSetSymbolSfx()) Report.SymbolSfx = report.getSymbolSfx().getValue();
            ////if (report.isSetSecurityID()) Report.SecurityID = report.getSecurityID().getValue();
            //if (report.isSetIDSource              ()) Report.IDSource               = report.getIDSource              ().getValue();
            ////if (report.isSetSecurityType()) Report.SecurityType = report.getSecurityType().getValue();
            ////if (report.isSetMaturityMonthYear()) Report.MaturityMonthYear = report.getMaturityMonthYear().getValue();
            //if (report.isSetMaturityDay           ()) Report.MaturityDate           = DateTime.Parse(report.getMaturityDay           ().getValue());
            //if (report.isSetPutOrCall             ()) Report.PutOrCall              = report.getPutOrCall             ().getValue();
            ////if (report.isSetStrikePrice()) Report.StrikePrice = report.getStrikePrice().getValue();
            ////if (report.isSetOptAttribute()) Report.OptAttribute = report.getOptAttribute().getValue();
            ////if (report.isSetContractMultiplier()) Report.ContractMultiplier = report.getContractMultiplier().getValue();
            ////if (report.isSetCouponRate()) Report.CouponRate = report.getCouponRate().getValue();
            ////if (report.isSetSecurityExchange()) Report.SecurityExchange = report.getSecurityExchange().getValue();
            ////if (report.isSetIssuer()) Report.Issuer = report.getIssuer().getValue();
            ////if (report.isSetEncodedIssuerLen()) Report.EncodedIssuerLen = report.getEncodedIssuerLen().getValue();
            ////if (report.isSetEncodedIssuer()) Report.EncodedIssuer = report.getEncodedIssuer().getValue();
            ////if (report.isSetSecurityDesc()) Report.SecurityDesc = report.getSecurityDesc().getValue();
            ////if (report.isSetEncodedSecurityDescLen()) Report.EncodedSecurityDescLen = report.getEncodedSecurityDescLen().getValue();
            ////if (report.isSetEncodedSecurityDesc()) Report.EncodedSecurityDesc = report.getEncodedSecurityDesc().getValue();
            if (report.isSetSide())
            {
                (Report as FIXExecutionReport).Side = report.getSide().getValue();
            }
            if (report.isSetOrderQty())
            {
                Report.OrderQty = report.getOrderQty().getValue();
            }
            ////if (report.isSetCashOrderQty()) Report.CashOrderQty = report.getCashOrderQty().getValue();
            if (report.isSetOrdType())
            {
                (Report as FIXExecutionReport).OrdType = report.getOrdType().getValue();
            }
            if (report.isSetPrice())
            {
                Report.Price = report.getPrice().getValue();
            }
            ////if (report.isSetStopPx()) Report.StopPx = report.getStopPx().getValue();
            //if (report.isSetPegDifference         ()) Report.PegDifference          = report.getPegDifference         ().getValue();
            ////if (report.isSetDiscretionInst()) Report.DiscretionInst = report.getDiscretionInst().getValue();
            ////if (report.isSetDiscretionOffset()) Report.DiscretionOffsetValue = report.getDiscretionOffset().getValue();
            ////if (report.isSetCurrency()) Report.Currency = report.getCurrency().getValue();
            ////if (report.isSetComplianceID()) Report.ComplianceID = report.getComplianceID().getValue();
            //if (report.isSetSolicitedFlag         ()) Report.SolicitedFlag          = report.getSolicitedFlag         ().getValue();
            ////if (report.isSetTimeInForce()) (Report as FIXExecutionReport).TimeInForce = report.getTimeInForce().getValue();
            ////if (report.isSetEffectiveTime()) Report.EffectiveTime = report.getEffectiveTime().getValue();
            ////if (report.isSetExpireDate()) Report.ExpireDate = DateTime.Parse(report.getExpireDate().getValue());
            ////if (report.isSetExpireTime()) Report.ExpireTime = report.getExpireTime().getValue();
            ////if (report.isSetExecInst()) Report.ExecInst = report.getExecInst().getValue();
            //if (report.isSetRule80A               ()) Report.Rule80A                = report.getRule80A               ().getValue();
            if (report.isSetLastShares())
            {
                Report.LastQty = report.getLastShares().getValue();
            }
            if (report.isSetLastPx())
            {
                Report.LastPx = report.getLastPx().getValue();
            }
            ////if (report.isSetLastSpotRate()) Report.LastSpotRate = report.getLastSpotRate().getValue();
            ////if (report.isSetLastForwardPoints()) Report.LastForwardPoints = report.getLastForwardPoints().getValue();
            ////if (report.isSetLastMkt()) Report.LastMkt = report.getLastMkt().getValue();
            ////if (report.isSetTradingSessionID()) Report.TradingSessionID = report.getTradingSessionID().getValue();
            ////if (report.isSetLastCapacity()) Report.LastCapacity = report.getLastCapacity().getValue();
            if (report.isSetLeavesQty())
            {
                Report.LeavesQty = report.getLeavesQty().getValue();
            }
            if (report.isSetCumQty())
            {
                Report.CumQty = report.getCumQty().getValue();
            }
            if (report.isSetAvgPx())
            {
                Report.AvgPx = report.getAvgPx().getValue();
            }
            ////if (report.isSetDayOrderQty()) Report.DayOrderQty = report.getDayOrderQty().getValue();
            ////if (report.isSetDayCumQty()) Report.DayCumQty = report.getDayCumQty().getValue();
            ////if (report.isSetDayAvgPx()) Report.DayAvgPx = report.getDayAvgPx().getValue();
            ////if (report.isSetGTBookingInst()) Report.GTBookingInst = report.getGTBookingInst().getValue();
            ////if (report.isSetTradeDate()) Report.TradeDate = DateTime.Parse(report.getTradeDate().getValue());
            if (report.isSetTransactTime())
            {
                Report.TransactTime = report.getTransactTime().getValue();
            }
            //if (report.isSetReportToExch          ()) Report.ReportToExch           = report.getReportToExch          ().getValue();
            ////if (report.isSetCommission()) Report.Commission = report.getCommission().getValue();
            ////if (report.isSetCommType()) (Report as FIXExecutionReport).CommType = report.getCommType().getValue();
            ////if (report.isSetGrossTradeAmt()) Report.GrossTradeAmt = report.getGrossTradeAmt().getValue();
            ////if (report.isSetSettlCurrAmt()) Report.SettlCurrAmt = report.getSettlCurrAmt().getValue();
            ////if (report.isSetSettlCurrency()) Report.SettlCurrency = report.getSettlCurrency().getValue();
            ////if (report.isSetHandlInst()) Report.HandlInst = report.getHandlInst().getValue();
            ////if (report.isSetMinQty()) Report.MinQty = report.getMinQty().getValue();
            ////if (report.isSetMaxFloor()) Report.MaxFloor = report.getMaxFloor().getValue();
            //if (report.isSetOpenClose             ()) Report.OpenClose              = report.getOpenClose             ().getValue();
            ////if (report.isSetMaxShow()) Report.MaxShow = report.getMaxShow().getValue();
            if (report.isSetText())
            {
                Report.Text = report.getText().getValue();
            }
            ////if (report.isSetEncodedTextLen()) Report.EncodedTextLen = report.getEncodedTextLen().getValue();
            ////if (report.isSetEncodedText()) Report.EncodedText = report.getEncodedText().getValue();
            //if (report.isSetFutSettDate2          ()) Report.FutSettDate2           = report.getFutSettDate2          ().getValue();
            ////if (report.isSetOrderQty2()) Report.OrderQty2 = report.getOrderQty2().getValue();
            //if (report.isSetClearingFirm          ()) Report.ClearingFirm           = report.getClearingFirm          ().getValue();
            //if (report.isSetClearingAccount       ()) Report.ClearingAccount        = report.getClearingAccount       ().getValue();
            ////if (report.isSetMultiLegReportingType()) Report.MultiLegReportingType = report.getMultiLegReportingType().getValue();

            //

            SingleOrder order;

            if (Report.ExecType == SmartQuant.FIX.ExecType.PendingCancel ||
                Report.ExecType == SmartQuant.FIX.ExecType.Cancelled ||
                Report.ExecType == SmartQuant.FIX.ExecType.PendingReplace ||
                Report.ExecType == SmartQuant.FIX.ExecType.Replace)
            {
                order = OrderManager.Orders.All[Report.OrigClOrdID] as SingleOrder;
            }
            else
            {
                order = OrderManager.Orders.All[Report.ClOrdID] as SingleOrder;
            }

            Instrument instrument = order.Instrument;

            Report.Symbol = instrument.Symbol;

            Report.TransactTime = Clock.Now;

            // emit execution report

            EmitExecutionReport(Report);
        }