Beispiel #1
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();
        }
        protected void ConvertMessage(QuickFix.Message srcMessage, FIXMessage dstMessage)
        {
            foreach (Field field1 in srcMessage)
            {
                int field2 = field1.getField();
                switch (EFIXFieldTypes.GetFIXType(field2))
                {
                case FIXType.Bool:
                    dstMessage.SetBoolValue(field2, srcMessage.getBoolean(field2));
                    continue;

                case FIXType.Int:
                    dstMessage.SetIntValue(field2, srcMessage.getInt(field2));
                    continue;

                case FIXType.Double:
                    dstMessage.SetDoubleValue(field2, srcMessage.getDouble(field2));
                    continue;

                case FIXType.Char:
                    dstMessage.SetCharValue(field2, srcMessage.getChar(field2));
                    continue;

                case FIXType.String:
                    dstMessage.SetStringValue(field2, srcMessage.getString(field2));
                    continue;

                case FIXType.DateTime:
                    DateTime?nullable = new DateTime?();
                    if (!nullable.HasValue)
                    {
                        try
                        {
                            nullable = new DateTime?(srcMessage.getUtcTimeStamp(field2));
                        }
                        catch
                        {
                        }
                    }
                    if (!nullable.HasValue)
                    {
                        try
                        {
                            nullable = new DateTime?(srcMessage.getUtcDateOnly(field2));
                        }
                        catch
                        {
                        }
                    }
                    if (!nullable.HasValue)
                    {
                        try
                        {
                            nullable = new DateTime?(srcMessage.getUtcTimeOnly(field2));
                        }
                        catch
                        {
                        }
                    }
                    if (nullable.HasValue)
                    {
                        dstMessage.SetDateTimeValue(field2, nullable.Value);
                        continue;
                    }
                    else
                    {
                        continue;
                    }

                default:
                    continue;
                }
            }
        }
        public override void fromAdmin(Message message, SessionID sessionID)
        {
            base.fromAdmin(message, sessionID);

            if ((message is QuickFix42.Logout || message is QuickFix42.Reject) && message.isSetField(QuickFix.Text.FIELD))
            {
                Console.WriteLine(message.getString(QuickFix.Text.FIELD));
            }

            if (message is QuickFix42.Logout)
            {
                Disconnect();
            }
        }