Пример #1
0
        public void fromApp(QuickFix.Message message, SessionID sessionID)
        {
            // receiving messages
            Symbol sym = new Symbol();

            message.getField(sym);
            Tick k = new TickImpl(sym.getValue());

            {
                // bid
                BidPx   bp = new BidPx();
                BidSize bs = new BidSize();
                k.bid = (decimal)bp.getValue();
                k.bs  = (int)message.getField(bs).getValue();
            }

            {
                // ask
                OfferPx   op = new OfferPx();
                OfferSize os = new OfferSize();
                k.ask = (decimal)op.getValue();
                k.os  = (int)message.getField(os).getValue();
            }

            {
                // last
                Price price = new Price();
                message.getField(price);
                k.trade = (decimal)price.getValue();
            }

            tl.newTick(k);
            //ClOrdID clOrdID = new ClOrdID();
            //message.getField(clOrdID);
        }
Пример #2
0
        //生成返回消息体
        protected virtual void ReportExcuResult(string symbol, Message msg, SessionID sid)
        {
            try
            {
                var cs = msg.getField(ReportIndex);
                var oid = msg.getField(ClientOrderIdIndex);

                if (cs == "0") //queued
                {
                    FixReport(msgTypeQueued, msg, ClientOrderIdIndex, string.Format(rspOrderStatus, Queued, symbol, 0, 0, oid));
                    unFill.ChangeStatus(oid, "Queued");
                }
                else if (cs == "8") // reject
                {
                    var res = string.Format(rspOrderStatus, Reject, symbol, 0, 0, oid);
                    res += string.Format(rspError, msg.getField(TextIndex));
                    FixReport(msgTypeReject, msg, ClientOrderIdIndex, res);
                    unFill.ChangeStatus(oid, "Reject");
                    unFill.Remove(oid);
                }
                else if (cs == "4") // cancel
                {
                    //目前4消息分两种情况:撤单消息返回、市价单不成功或不完全成功。
                    //撤单消息返回时:有41,44字段。
                    //市价单不成功时:无41,44字段。
                    if (msg.isSetField(41) && msg.isSetField(44))
                    {
                        FixReport(msgTypeCancel, msg, ClientOrderIdIndex, string.Format(rspCancel, msg.getField(41)));
                    }
                    else
                    {
                        var res = string.Format(rspOrderStatus, Reject, symbol, 0, 0, oid);
                        res += string.Format(rspError, "MarketOrder is IOC/FOK(TimeInForce)");
                        FixReport(msgTypeReject, msg, ClientOrderIdIndex, res);
                    }
                    unFill.ChangeStatus(oid, "Canceled Or MarketOrderCanceled");
                    unFill.Remove(oid);
                }
                else if (cs == "1") //partiallyFilled
                {
                    var price = msg.getField(PriceIndex);
                    var qty = (msg.getField(SideIndex) == SideSell ? "-" : "") + msg.getField(QtyIndex);

                    DefDealProc(symbol, price, qty, oid);
                    FixReport(msgTypePartFill, msg, ClientOrderIdIndex,
                        string.Format(rspOrderStatus, PartFill, symbol, price, qty, oid));
                    unFill.ChangeStatus(oid, "PartiallyFilled");
                }
                else if (cs == "2") //filled
                {
                    var price = msg.getField(PriceIndex);
                    var qty = (msg.getField(SideIndex) == SideSell ? "-" : "") + msg.getField(QtyIndex);

                    DefDealProc(symbol, price, qty, oid);
                    FixReport(msgTypePartFill, msg, ClientOrderIdIndex,
                        string.Format(rspOrderStatus, FullFill, symbol, price, qty, oid));
                    unFill.ChangeStatus(oid, "Filled");
                    unFill.Remove(oid);
                }
            }
            catch (Exception) { }
        }
Пример #3
0
 //网关拒绝撤单
 protected virtual void MsgOrderCancelReject(Message msg, SessionID sid)
 {
     try
     {
         FixReport(msgTypeCancel, msg, CancelClientOrderIdIndex,
             string.Format(rspCancel, msg.getField(CancelClientOrderIdIndex))
             + string.Format(rspError, msg.getField(TextIndex)));
     }
     catch (Exception){}
 }
Пример #4
0
        protected string GetSymbol(Message msg)
        {
            try
            {
                return symbolList[msg.getField(ClientOrderIdIndex)];
            }
            catch (Exception){}

            try
            {
                return msg.getField(SymbolIndex);
            }
            catch (Exception){}

            return string.Empty;
        }
Пример #5
0
 protected void FixReport(int type, Message msg, int IDfieldNum, string connect)
 {
     if (ReportCallBack != null)
     {
         try
         {
             ReportCallBack(type, msg.getField(IDfieldNum), connect);
         }
         catch (Exception)
         {
             ReportCallBack(type, string.Empty, connect);
         }
     }
 }
Пример #6
0
        void Application.fromApp(QuickFix.Message message, SessionID sessionID)
        {
            //Console.WriteLine("from app:"+message.ToString());
            // 查询股份和资产不是FIX4.2的标准功能,需要特殊处理
            if (message.getHeader().getString(35) == "UAP")
            {
                PosType     posType     = new PosType();
                LongQty     longQty     = new LongQty();
                ShortQty    shortQty    = new ShortQty();
                NoPositions noPositions = new NoPositions();
                Group       group       = new Group(noPositions.getField(), posType.getField());

                if ((message.getField(724) == "9") && (FundStatusReport != null))// 资产
                {
                    //string currency = message.getField(15);
                    double balance          = 0.0;
                    double availableBalance = 0.0;
                    double totalAsserts     = 0.0;
                    double capitalAsserts   = 0.0;
                    double marketValue      = 0.0;
                    double buyFreezed       = 0.0;

                    for (uint i = 1; i <= int.Parse(message.getField(noPositions.getField())); i++)
                    {
                        message.getGroup(i, group);
                        switch (group.getField(posType.getField()))
                        {
                        case "FB":
                            balance = double.Parse(group.getField(longQty.getField()));
                            break;

                        case "FAV":
                            availableBalance = double.Parse(group.getField(longQty.getField()));
                            break;

                        case "MV":
                            totalAsserts = double.Parse(group.getField(longQty.getField()));
                            break;

                        case "F":
                            capitalAsserts = double.Parse(group.getField(longQty.getField()));
                            break;

                        case "SV":
                            marketValue = double.Parse(group.getField(longQty.getField()));
                            break;

                        case "FBF":
                            buyFreezed = double.Parse(group.getField(shortQty.getField()));
                            break;
                        }
                    }
                    FundStatusReport(this, new FundStatusReportEventArgs(balance, availableBalance, totalAsserts,
                                                                         capitalAsserts, marketValue, buyFreezed));
                }
                else if ((message.getField(724) == "0") && (PositionStatusReport != null)) // 股份
                {
                    string accountID        = message.getString(1);;
                    string securityExchange = message.getString(207);
                    switch (securityExchange)
                    {
                    case "XSHG":
                        securityExchange = "SH";
                        break;

                    case "XSHE":
                        securityExchange = "SZ";
                        break;
                    }

                    string securityID       = message.getString(55);
                    double balance          = 0.0;
                    double availableBalance = 0.0;
                    double quantity         = 0.0;

                    for (uint i = 1; i <= int.Parse(message.getField(noPositions.getField())); i++)
                    {
                        message.getGroup(i, group);
                        switch (group.getField(posType.getField()))
                        {
                        case "SB": balance = double.Parse(group.getField(longQty.getField())); break;

                        case "SAV": availableBalance = double.Parse(group.getField(longQty.getField())); break;

                        case "SQ": quantity = double.Parse(group.getField(longQty.getField())); break;
                        }
                    }
                    PositionStatusReport(this, new PositionStatusReportEventArgs(accountID, securityExchange, securityID,
                                                                                 balance, availableBalance, quantity));
                }
            }
            else
            {
                base.crack(message, sessionID); // 调用默认处理方法
            }
            message.Dispose();
        }