示例#1
0
        protected void ProcessNewOrder(object param)
        {
            try
            {
                lock (tLock)
                {
                    Wrapper wrapper = (Wrapper)param;
                    Order   order   = OrderConverter.ConvertNewOrder(wrapper);
                    string  sender  = (string)wrapper.GetField(OrderFields.SENDER);

                    if (!string.IsNullOrEmpty(sender) && TestingModules.ContainsKey(sender))
                    {
                        SentOrders.Add(order.ClOrdId, sender);

                        QuickFix.Message nos = FIXMessageCreator.CreateNewOrderSingle(order.ClOrdId, order.Security.Symbol, order.Side, order.OrdType, order.SettlType,
                                                                                      order.TimeInForce, order.EffectiveTime, order.OrderQty, order.Price, order.StopPx,
                                                                                      order.Account, order.Exchange);

                        Session.SendToTarget(nos, SessionID);

                        SendersDict.Add(nos.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum), sender);
                        KeysDict.Add(nos.Header.GetInt(QuickFix.Fields.Tags.MsgSeqNum), order.ClOrdId);
                    }
                    else
                    {
                        throw new Exception("Cannot create an order for unknown sender");
                    }
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("Critical error processing new order @{0}:{1}", Configuration.Name, ex.Message), Fwk.Main.Common.Util.Constants.MessageType.Error);
            }
        }
示例#2
0
        private static string GetKeyCode <T, TAttribute>(T t, KeysDict datasource) where TAttribute : Attribute
        {
            string key = String.Empty;

            var Keys = GetKeyPropertyInfo <T, TAttribute>(datasource);

            foreach (PropertyInfo propInfo in Keys)
            {
                if (key.Length > 0)
                {
                    key += KeyCodeJoinChar;
                }
                key += EncodeKeyCode(propInfo.GetValue(t, null).ToString());
            }

            return(key);
        }
示例#3
0
        protected void ProcessMessageReject(object param)
        {
            try
            {
                Reject reject = (Reject)param;

                int refSeqNum = reject.GetInt(QuickFix.Fields.Tags.RefSeqNum);

                if (SendersDict.ContainsKey(refSeqNum))
                {
                    string sender = SendersDict[refSeqNum];

                    if (TestingModules.ContainsKey(sender))
                    {
                        if (KeysDict.ContainsKey(refSeqNum))
                        {
                            string        key           = KeysDict[refSeqNum];
                            RejectWrapper rejectWrapper = new RejectWrapper(key, reject);
                            TestingModules[sender].ProcessMessage(rejectWrapper);
                        }
                        else
                        {
                            DoLog(string.Format("Discarding message because no key was identified @{0}: Sender={1}", Configuration.Name, sender), Fwk.Main.Common.Util.Constants.MessageType.Information);
                        }
                    }
                    else
                    {
                        DoLog(string.Format("Discarding message because no sender was identified @{0}: Sender={1}", Configuration.Name, sender), Fwk.Main.Common.Util.Constants.MessageType.Information);
                    }
                }
                else
                {
                    DoLog(string.Format("Discarding message because no sender was identified @{0}: Message={1}", Configuration.Name, refSeqNum), Fwk.Main.Common.Util.Constants.MessageType.Information);
                }
            }
            catch (Exception ex)
            {
                DoLog(string.Format("Critical error processing a Reject message @{0}:{1}", Configuration.Name, ex.Message), Fwk.Main.Common.Util.Constants.MessageType.Error);
            }
        }
示例#4
0
        private static List <PropertyInfo> GetKeyPropertyInfo <TEntity, TAttribute>(KeysDict datasource) where TAttribute : Attribute
        {
            var type = typeof(TEntity);

            if (datasource.ContainsKey(type))
            {
                return(datasource[type]);
            }
            var props = new List <PropertyInfo>();

            var propertys = GetKeyPropertys <TAttribute>(type);

            if (propertys.Count == 0)
            {
                return(null);
            }

            //查找属性是不是在父类
            foreach (var item in propertys)
            {
                var propertyName = item.Name;

                var propInfo = type.GetTypeInfo().GetDeclaredProperty(propertyName);

                //如果类型有父类。且是定义在父类
                while (propInfo == null && type.GetTypeInfo().BaseType != null)
                {
                    type     = type.GetTypeInfo().BaseType;
                    propInfo = type.GetTypeInfo().GetDeclaredProperty(propertyName);
                }

                if (propInfo != null)
                {
                    props.Add(propInfo);
                }
            }
            datasource.Add(type, props);
            return(props);
        }
示例#5
0
 public bool IsKeyInUse(Keys key)
 {
     return(KeysDict.ContainsKey(key));
 }
示例#6
0
        public (bool success, string reason) InitMap(string[] keys, string map)
        {
            CustomNamesDict = null;

            if (map.IsNulle())
            {
                throw new ArgumentNullException(nameof(map), "");
            }

            if (keys.IsNulle())
            {
                throw new ArgumentOutOfRangeException(nameof(keys), "");
            }

            IgnoreKeys  = new Dictionary <string, bool>();
            MapFileKeys = new Dictionary <string, bool>();
            KeysDict    = keys.ToDictionaryIgnoreDuplicateKeys(k => k, k => false,
                                                               comparer: IgnoreCase ? StringComparer.OrdinalIgnoreCase : null);

            Dictionary <string, bool> _anyKeysEver = new Dictionary <string, bool>();

            string[] lines = map.SplitLines(trimLines: true, removeEmptyLines: true);

            if (lines.IsNulle())
            {
                return(false, "Null or empty input");
            }

            NamesToCustomDict = new Dictionary <string, List <string> >(lines.Length);
            NamesToCustomDictWithMultiples = new Dictionary <string, List <string> >();

            int multipleNamesInitialLen = (int)(lines.Length * 1.2);

            CustomNamesDict = new Dictionary <string, string>(multipleNamesInitialLen);

            for (int i = 0; i < lines.Length; i++)
            {
                string line = lines[i];

                if (line.StartsWith("//"))
                {
                    continue;                     // ignore comment
                }
                int commIdx = line.IndexOf("//");
                if (commIdx > 0)                 // don't worry about validating if // existed otherwise, alphanum checks still to come
                {
                    line = line.Substring(0, commIdx);
                }

                string[] vals = line.Split(_colonSplit, StringSplitOptions.RemoveEmptyEntries);

                if (vals.Length != 2)
                {
                    if (vals.Length == 1)
                    {
                        string _key = vals[0].NullIfEmptyTrimmed();

                        if (_key == null)
                        {
                            continue;
                        }

                        else if (KeysDict.ContainsKey(_key))
                        {
                            // key was already present with no value, ignore.
                            _anyKeysEver[_key] = true;
                            continue;
                        }
                    }
                    return(false, $"One of the lines is invalid, does not have a key-value set.");
                }

                string key = vals[0].NullIfEmptyTrimmed();
                string val = vals[1].NullIfEmptyTrimmed();

                if (key == null || key.Length > 15 || !key.IsAsciiAlphaNumeric())
                {
                    return(false, $"One of the keys is invalid ('{key?.SubstringMax(10, "...")}')");
                }

                _anyKeysEver[key] = true;

                //if (NamesToCustomDict.Count == 0 // can't just check `i == 0` because first line(s) could have been comments (see above)
                //	&& removeTopKeyIfMatch.NotNulle()
                //	&& (IgnoreCase ? key.EqualsIgnoreCase(removeTopKeyIfMatch) : key == removeTopKeyIfMatch)) {
                //	TopKeyValue = (key, val);
                //	continue;
                //}

                if (!KeysDict.ContainsKey(key))
                {
                    return(false, $"Invalid (unrecognized) key ('{key}')");
                }

                if (val == "IGNORE")                   // MUST check this before duplicate key check below! CAN have a doubled duplicate in case of IGNORE
                {
                    IgnoreKeys[key] = true;
                    continue;
                }

                if (NamesToCustomDict.ContainsKey(key))
                {
                    return(false, $"Duplicate key value encountered '{key}'");
                }

                string badValueMsg = $"Value for key '{key}' is invalid (e.g. too long, or null, or invalid characters, etc)";

                if (val.IsNulle() || key == val)
                {
                    continue;
                }

                if (val.Length > 256)
                {
                    return(false, badValueMsg);
                }

                List <string> valsList  = new List <string>();
                const int     maxValLen = 30;

                if (key.Length == val.Length && (IgnoreCase ? key.EqualsIgnoreCase(val) : key == val))
                {
                    continue;
                }

                if (val.IsAsciiAlphaNumeric())
                {
                    if (val.Length > maxValLen)
                    {
                        return(false, badValueMsg);
                    }
                    valsList.Add(val);
                }
                else
                {
                    string[] mVals = val.SplitAndRemoveWhiteSpaceEntries('|');                     //.Split(_barSplit);
                    if (mVals == null || mVals.Length < 2)
                    {
                        return(false, badValueMsg);
                    }

                    for (int j = 0; j < mVals.Length; j++)
                    {
                        string v1 = mVals[j];
                        if (v1.Length > maxValLen || !v1.IsAsciiAlphaNumeric())
                        {
                            return(false, badValueMsg);
                        }
                        valsList.Add(v1);
                    }
                }

                bool isMultiValues = valsList.Count > 1;

                NamesToCustomDict.Add(key, valsList);
                if (isMultiValues)
                {
                    NamesToCustomDictWithMultiples.Add(key, valsList.ToList());
                }

                for (int j = 0; j < valsList.Count; j++)                   // string mVal in valsList)
                {
                    string mVal = valsList[j];
                    if (CustomNamesDict.ContainsKey(mVal))
                    {
                        return(false, $"Value {mVal.SubstringMax(15)} was entered more than once.");
                    }

                    CustomNamesDict.Add(mVal, key);
                    //if (isMultiValues) {
                    //	MultipleCustomNamesDict[mVal] = valsList.ToList(); //.Where((vv, idxx) => vv.NotNulle()).ToList();
                    //}
                }
            }

            foreach (string key in KeysDict.Keys)
            {
                if (_anyKeysEver.ContainsKey(key))
                {
                    MapFileKeys[key] = true;
                }
            }

            return(true, null);
        }