public ObservableCollection <SpreadLogModel> TransferFromDictionaryToCollection(Dictionary <Int64, SpreadLogModel> dict) { ObservableCollection <SpreadLogModel> tempColl = new ObservableCollection <SpreadLogModel>(); ObservableCollection <SpreadLogModel> finalColl = new ObservableCollection <SpreadLogModel>(); listOfItemToRemove.Clear(); leastOrderId = 0; foreach (var item in dict) { tempColl.Add(item.Value); } foreach (var item in tempColl.ToList()) { if (item.ExchangeOrderId == 1700000001452627) { Console.WriteLine("symbol : " + item.StrategyTag); } bool hasValue = finalColl.Any(m => m.LogTime == item.LogTime && m.StrategyTag == item.StrategyTag && m.Threshold == item.Threshold); if (hasValue) { var coll = from p in finalColl where (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && (p.Threshold == item.Threshold) select p; leastOrderId = coll.FirstOrDefault().ExchangeOrderId; SpreadLogModel leastValue = coll.FirstOrDefault(); if (leastOrderId != 0) { foreach (var val in coll) { if (val.ExchangeOrderId < leastOrderId) { listOfItemToRemove.Add(leastValue); leastOrderId = val.ExchangeOrderId; leastValue = val; } } if (!(finalColl.Contains(leastValue))) { finalColl.Add(leastValue); foreach (var delItem in listOfItemToRemove) { tempColl.Remove(delItem); } } } } else { finalColl.Add(item); } } //foreach(var item in finalColl) //{ // Console.WriteLine("Symbol " + item.StrategyTag + " | threshold : " + item.Threshold + " | orderPrices : " + item.OrderPrice + " | exchnageId : " + item.ExchangeOrderId + " | logtime : " + item.LogTime + " | DateTime : " + item.DateTime + " | " + item.LogTimeStr); //} return(finalColl); }
public ObservableCollection <SpreadLogModel> ProcessDataFromConsoleDataSource(List <string> rawData, bool MatchWithEveryRec) { ObservableCollection <SpreadLogModel> _consoleObsrvColl = new ObservableCollection <SpreadLogModel>(); try { foreach (var item in rawData) { try { SpreadLogModel obj = (SpreadLogModel)ReturnSpreadLogObjFromConsoleDate(item); if (MatchWithEveryRec) { if (_consoleObsrvColl.Any(p => (p.LogTime == obj.LogTime) && (p.StrategyTag == obj.StrategyTag) && (p.SpreadPrice == obj.SpreadPrice)) == true) { var coll = from p in _consoleObsrvColl where (p.LogTime == obj.LogTime) && (p.StrategyTag == obj.StrategyTag) && (p.SpreadPrice == obj.SpreadPrice) select p; foreach (var value in coll) { if (value.ExchangeOrderId > obj.ExchangeOrderId) { _consoleObsrvColl.Add(obj); listOfItemToRemove.Add(value); _consoleObsrvColl.Remove(value); break; } } } else { _consoleObsrvColl.Add(obj); } } else { _consoleObsrvColl.Add(obj); } } catch (Exception ex) { listOfErrorneousConsoleRecord.Add(item); } } } catch (Exception ex) { return(null); } return(_consoleObsrvColl); }
public SpreadLogModel ReturnSpreadLogObjFromConsoleDate(string line) { string logTimeStr = SearchedObjectFromString(line, StaticVariables.RegexPattern_Time); DateTime dt; if (DateTime.TryParse(DateTimeHelper.ReturnDate_from_DDD_MMM_YYYY(logTimeStr.Substring(logTimeStr.IndexOf(":") + 2, (logTimeStr.Length) - (logTimeStr.IndexOf(":") + 3))), out dt)) { // int result = DateTimeHelper.calculateSeconds(dt); } string Symbol_console = SearchedObjectFromString(line, StaticVariables.RegexPattern_Symbol); string id_console = SearchedObjectFromString(line, StaticVariables.RegexPattern_ID); string Side = SearchedObjectFromString(line, StaticVariables.RegexPattern_Type); string OptType = SearchedObjectFromString(line, StaticVariables.RegexPattern_Option); string callPrc = SearchedObjectFromString(line, StaticVariables.RegexPattern_CallPrice); string PutPrc = SearchedObjectFromString(line, StaticVariables.RegexPattern_PutPrice); string FutPrc = SearchedObjectFromString(line, StaticVariables.RegexPattern_FuturePrice); string ExcgId = (SearchedObjectFromString(line, StaticVariables.RegexPattern_OrderNum)).Substring(0, (SearchedObjectFromString(line, StaticVariables.RegexPattern_OrderNum).Length) - 1); string ExecPrice = SearchedObjectFromString(line, StaticVariables.RegexPattern_Spread); SpreadLogModel item = new SpreadLogModel() { LogTime = DateTimeHelper.calculateSeconds(dt), DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(DateTimeHelper.calculateSeconds(dt), "HH:mm:ss"), StrategyTag = (Symbol_console.Substring(Symbol_console.IndexOf(":") + 2, ((Symbol_console.Length) - (Symbol_console.IndexOf(":") + 3)))).Trim(), ID_Console = Convert.ToInt32(id_console.Substring(id_console.IndexOf(":") + 2, ((id_console.Length) - (id_console.IndexOf(":") + 3)))), Side = Side.Substring(Side.IndexOf(":") + 2, ((Side.Length) - (Side.IndexOf(":") + 3))), OptionType = OptType.Substring(OptType.IndexOf(":") + 2, ((OptType.Length) - (OptType.IndexOf(":") + 3))), CallPrice = Convert.ToDouble(callPrc.Substring(callPrc.IndexOf(":") + 2, ((callPrc.Length) - (callPrc.IndexOf(":") + 3)))), CallPriceStr = callPrc, PutPrice = Convert.ToDouble(PutPrc.Substring(PutPrc.IndexOf(":") + 2, ((PutPrc.Length) - (PutPrc.IndexOf(":") + 3)))), PutPriceStr = PutPrc, FuturePrice = Convert.ToDouble(FutPrc.Substring(FutPrc.IndexOf(":") + 2, ((FutPrc.Length) - (FutPrc.IndexOf(":") + 3)))), FuturePriceStr = FutPrc, ExchangeOrderId = Convert.ToInt64(ExcgId.Substring(ExcgId.IndexOf(":") + 2, ((ExcgId.Length) - (ExcgId.IndexOf(":") + 3)))), SpreadPrice = Convert.ToDouble(ExecPrice.Substring(ExecPrice.IndexOf(":") + 2, ((ExecPrice.Length) - (ExecPrice.IndexOf(":") + 3)))) }; return(item); }
public ObservableCollection <SpreadLogModel> GetFinalResultSet(ObservableCollection <SpreadLogModel> user1Data, ObservableCollection <SpreadLogModel> user2Data, bool IsStrictChecking, bool MatchWithEveryRecordOfUser2, string comaprison) { finalResultCollAftrComparison.Clear(); switch (comaprison) { case "IsComparisonWithConsole_NSE": #region #When comparison is with Console_NSE //foreach(var item in user1Data) //{ // Console.WriteLine("Symbol " + item.StrategyTag + " | threshold : " + item.Threshold + " | orderPrices : " + item.OrderPrice + " | exchnageId : " + item.ExchangeOrderId + " | logtime : " + item.LogTime + " | DateTime : " + item.DateTime + " | " + item.LogTimeStr); //} //Console.WriteLine("Printing user 2 details "); //foreach (var item in user2Data) //{ // Console.WriteLine("Symbol " + item.StrategyTag + " | threshold : " + item.Threshold + " | orderPrices : " + item.OrderPrice + " | exchnageId : " + item.ExchangeOrderId + " | logtime : " + item.LogTime + " | DateTime : " + item.DateTime + " | " + item.LogTimeStr); //} foreach (var item in user1Data) { if (!IsStrictChecking) { //var coll = user2Data.Where(p => (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && (p.Threshold == item.Threshold)); var coll = from p in user2Data where (p.LogTime == item.LogTime) && (p.StrategyTag == item.Symbol) && (Math.Abs(p.Threshold) == Math.Abs(item.Threshold)) select p; if (coll.Any(p => (p.LogTime == item.LogTime) && (p.StrategyTag == item.Symbol) && (Math.Abs(p.Threshold) == Math.Abs(item.Threshold)) == true)) { foreach (var value in coll) { if ((item.CallPrice == value.CallPrice) || (item.PutPrice == value.PutPrice) || (item.FuturePrice == value.FuturePrice)) { if (item.ExchangeOrderId > value.ExchangeOrderId) { leastValueObj = (SpreadLogModel)value; leastValueObj.UserCode = "Console_NSE"; greaterValueObj = item; } else { leastValueObj = item; greaterValueObj = (SpreadLogModel)value; greaterValueObj.UserCode = "Console_NSE"; } } } /***till here we have got the element with which item[user1] has to be compared****/ if (leastValueObj != null && greaterValueObj != null) { if (leastValueObj.UserCode.Contains(item.UserCode)) { user1ValueObj = (SpreadLogModel)leastValueObj; user2ValueObj = (SpreadLogModel)greaterValueObj; } else { user1ValueObj = (SpreadLogModel)greaterValueObj; user2ValueObj = (SpreadLogModel)leastValueObj; } WinnerHighlightStruct winnerStruct = new WinnerHighlightStruct(); winnerStruct.participant1UserId = item.UserCode; winnerStruct.winneruserId = user1ValueObj.ExchangeOrderId < user2ValueObj.ExchangeOrderId ? user1ValueObj.UserCode : user2ValueObj.UserCode; SpreadLogModel element = new SpreadLogModel() { LogTimeStr = Convert.ToString(user1ValueObj.LogTime) + " || " + Convert.ToString(user2ValueObj.LogTime), ExchangeOrderIdStr = Convert.ToString(user1ValueObj.ExchangeOrderId) + " || " + Convert.ToString(user2ValueObj.ExchangeOrderId), OrderPrice = user1ValueObj.OrderPrice + " || " + user2ValueObj.OrderPrice, GreaterValue = user1ValueObj.ExchangeOrderId < user2ValueObj.ExchangeOrderId ? user1ValueObj.UserCode : user2ValueObj.UserCode, // DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item1.LogTime, "HH:mm:ss") + "||" + DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(leastValueItem.LogTime, "HH:mm:ss"), DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item.LogTime, "MM/dd/yyyy HH:mm:ss"), StrategyTag = user1ValueObj.StrategyTag + " || " + user2ValueObj.StrategyTag, MktAnalaysisParams = user1ValueObj.Mkt + " || " + user2ValueObj.Mkt, Difference = Math.Abs(Convert.ToInt32(user1ValueObj.ExchangeOrderId - user2ValueObj.ExchangeOrderId)), WinnerHighLightVal = winnerStruct }; if (Math.Abs(element.Difference) <= StaticVariables.DiffThreshold) { finalResultCollAftrComparison.Add(element); } leastValueObj = null; greaterValueObj = null; } } } } #endregion break; case "IsComparisonWithConsole": #region #When comparison is with console foreach (var item in user1Data) { double callPrice_Q = fileReader.SearchedObjectFromStringForConsole(item.OrderPrice, StaticVariables.RegexPattern_CALLQ); double putPrice_Q = fileReader.SearchedObjectFromStringForConsole(item.OrderPrice, StaticVariables.RegexPattern_PUTQ); double futPrice_Q = fileReader.SearchedObjectFromStringForConsole(item.OrderPrice, StaticVariables.RegexPattern_FUTQ); string symbolAccToConsole = item.StrategyTag.Remove(0, 3); symbolAccToConsole = symbolAccToConsole.Remove((symbolAccToConsole).IndexOf('_')); item.StrategyTag = symbolAccToConsole; if (!IsStrictChecking) { foreach (var value in user2Data) { if (value.LogTime == item.LogTime && value.StrategyTag == item.StrategyTag && (float)value.SpreadPrice == item.Threshold) { if ((callPrice_Q == value.CallPrice) || (putPrice_Q == value.PutPrice) || (futPrice_Q == value.FuturePrice)) { if (item.ExchangeOrderId > value.ExchangeOrderId) { leastValueObj = (SpreadLogModel)value; leastValueObj.UserCode = "Console"; leastValueObj.OrderPrice = leastValueObj.FuturePriceStr + " | " + leastValueObj.CallPriceStr + " | " + leastValueObj.PutPriceStr; greaterValueObj = item; } else { leastValueObj = item; greaterValueObj = (SpreadLogModel)value; greaterValueObj.UserCode = "Console"; greaterValueObj.OrderPrice = greaterValueObj.FuturePriceStr + " | " + greaterValueObj.CallPriceStr + " | " + greaterValueObj.PutPriceStr; } /***till here we have got the element with which item[user1] has to be compared****/ if (leastValueObj.UserCode.Contains("T")) { user1ValueObj = (SpreadLogModel)leastValueObj; user2ValueObj = (SpreadLogModel)greaterValueObj; } else { user1ValueObj = (SpreadLogModel)greaterValueObj; user2ValueObj = (SpreadLogModel)leastValueObj; } WinnerHighlightStruct winnerStruct = new WinnerHighlightStruct(); winnerStruct.participant1UserId = item.UserCode; winnerStruct.winneruserId = user1ValueObj.ExchangeOrderId < user2ValueObj.ExchangeOrderId ? user1ValueObj.UserCode : user2ValueObj.UserCode; SpreadLogModel element = new SpreadLogModel() { LogTimeStr = Convert.ToString(user1ValueObj.LogTime) + " || " + Convert.ToString(user2ValueObj.LogTime), ExchangeOrderIdStr = Convert.ToString(user1ValueObj.ExchangeOrderId) + " || " + Convert.ToString(user2ValueObj.ExchangeOrderId), OrderPrice = user1ValueObj.OrderPrice + " || " + user2ValueObj.OrderPrice, GreaterValue = user1ValueObj.ExchangeOrderId < user2ValueObj.ExchangeOrderId ? user1ValueObj.UserCode : user2ValueObj.UserCode, // DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item1.LogTime, "HH:mm:ss") + "||" + DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(leastValueItem.LogTime, "HH:mm:ss"), DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item.LogTime, "HH:mm:ss"), StrategyTag = user1ValueObj.StrategyTag + " || " + user2ValueObj.StrategyTag, MktAnalaysisParams = (user1ValueObj.MktAnalaysisParams).Remove(0, user1ValueObj.MktAnalaysisParams.IndexOf(':') + 1), Difference = Math.Abs(Convert.ToInt32(user1ValueObj.ExchangeOrderId - user2ValueObj.ExchangeOrderId)), WinnerHighLightVal = winnerStruct }; //SpreadLogModel element = new SpreadLogModel() //{ // LogTimeStr = Convert.ToString(leastValueObj.LogTime) + " || " + Convert.ToString(greaterValueObj.LogTime), // ExchangeOrderIdStr = Convert.ToString(leastValueObj.ExchangeOrderId) + " || " + Convert.ToString(greaterValueObj.ExchangeOrderId), // OrderPrice = leastValueObj.OrderPrice + " || " + greaterValueObj.OrderPrice, // GreaterValue = greaterValueObj.UserCode, // // DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item1.LogTime, "HH:mm:ss") + "||" + DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(leastValueItem.LogTime, "HH:mm:ss"), // DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item.LogTime, "HH:mm:ss"), // StrategyTag = leastValueObj.StrategyTag + " || " + greaterValueObj.StrategyTag, // MktAnalaysisParams = item.MktAnalaysisParams, // Difference = Math.Abs(Convert.ToInt32(leastValueObj.ExchangeOrderId - greaterValueObj.ExchangeOrderId)) //}; if (Math.Abs(element.Difference) <= StaticVariables.DiffThreshold) { finalResultCollAftrComparison.Add(element); } } } } #region #difficult to debug method //var coll = from p in user2Data where (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && ((float)p.SpreadPrice == item.Threshold) select p; //if (coll.Any(p => (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && ((float)p.SpreadPrice == item.Threshold)) == true) //{ // foreach (var value in coll) // { // if ((callPrice_Q == value.CallPrice) || (putPrice_Q == value.PutPrice) || (futPrice_Q == value.FuturePrice)) // { // if (item.ExchangeOrderId > value.ExchangeOrderId) // { // leastValueObj = (SpreadLogModel)value; // leastValueObj.UserCode = "Console"; // leastValueObj.OrderPrice = leastValueObj.FuturePriceStr + " | " + leastValueObj.CallPriceStr + " | " + leastValueObj.PutPriceStr; // greaterValueObj = item; // } // else // { // leastValueObj = item; // greaterValueObj = (SpreadLogModel)value; // greaterValueObj.UserCode = "Console"; // leastValueObj.OrderPrice = greaterValueObj.FuturePriceStr + " | " + greaterValueObj.CallPriceStr + " | " + greaterValueObj.PutPriceStr; // } // } // } // /***till here we have got the element with which item[user1] has to be compared****/ // SpreadLogModel element = new SpreadLogModel() // { // LogTimeStr = Convert.ToString(leastValueObj.LogTime) + " || " + Convert.ToString(greaterValueObj.LogTime), // ExchangeOrderIdStr = Convert.ToString(leastValueObj.ExchangeOrderId) + " || " + Convert.ToString(greaterValueObj.ExchangeOrderId), // OrderPrice = leastValueObj.OrderPrice + " || " + greaterValueObj.OrderPrice, // GreaterValue = greaterValueObj.UserCode, // // DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item1.LogTime, "HH:mm:ss") + "||" + DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(leastValueItem.LogTime, "HH:mm:ss"), // DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item.LogTime, "HH:mm:ss"), // StrategyTag = leastValueObj.StrategyTag + " || " + greaterValueObj.StrategyTag, // MktAnalaysisParams = item.MktAnalaysisParams, // Difference = Math.Abs(Convert.ToInt32(leastValueObj.ExchangeOrderId - greaterValueObj.ExchangeOrderId)) // }; // if (Math.Abs(element.Difference) <= StaticVariables.DiffThreshold) // finalResultCollAftrComparison.Add(element); //} #endregion /**********Fill Percentage Value*********/ } } #endregion break; case "IsComparisonWithQuantum": #region #When comparison is with Quantum foreach (var item in user1Data) { // Console.WriteLine(item.StrategyTag); if (!IsStrictChecking) { //var coll = user2Data.Where(p => (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && (p.Threshold == item.Threshold)); var coll = from p in user2Data where (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && (p.Threshold == item.Threshold) select p; if (coll.Any(p => (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && (p.Threshold == item.Threshold)) == true) { foreach (var value in coll) { if ((item.CallPrice == value.CallPrice) || (item.PutPrice == value.PutPrice) || (item.FuturePrice == value.FuturePrice)) { if (item.ExchangeOrderId > value.ExchangeOrderId) { leastValueObj = (SpreadLogModel)value; greaterValueObj = item; } else { leastValueObj = item; greaterValueObj = (SpreadLogModel)value; } } } /***till here we have got the element with which item[user1] has to be compared****/ if (leastValueObj.UserCode.Contains(item.UserCode)) { user1ValueObj = (SpreadLogModel)leastValueObj; user2ValueObj = (SpreadLogModel)greaterValueObj; } else { user1ValueObj = (SpreadLogModel)greaterValueObj; user2ValueObj = (SpreadLogModel)leastValueObj; } WinnerHighlightStruct winnerStruct = new WinnerHighlightStruct(); winnerStruct.participant1UserId = item.UserCode; winnerStruct.winneruserId = user1ValueObj.ExchangeOrderId < user2ValueObj.ExchangeOrderId ? user1ValueObj.UserCode : user2ValueObj.UserCode; SpreadLogModel element = new SpreadLogModel() { LogTimeStr = Convert.ToString(user1ValueObj.LogTime) + " || " + Convert.ToString(user2ValueObj.LogTime), ExchangeOrderIdStr = Convert.ToString(user1ValueObj.ExchangeOrderId) + " || " + Convert.ToString(user2ValueObj.ExchangeOrderId), OrderPrice = user1ValueObj.OrderPrice + " || " + user2ValueObj.OrderPrice, GreaterValue = user1ValueObj.ExchangeOrderId < user2ValueObj.ExchangeOrderId ? user1ValueObj.UserCode : user2ValueObj.UserCode, // DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item1.LogTime, "HH:mm:ss") + "||" + DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(leastValueItem.LogTime, "HH:mm:ss"), DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(item.LogTime, "MM/dd/yyyy HH:mm:ss"), StrategyTag = user1ValueObj.StrategyTag + " || " + user2ValueObj.StrategyTag, MktAnalaysisParams = user1ValueObj.Mkt + " || " + user2ValueObj.Mkt, Difference = Math.Abs(Convert.ToInt32(user1ValueObj.ExchangeOrderId - user2ValueObj.ExchangeOrderId)), WinnerHighLightVal = winnerStruct }; if (Math.Abs(element.Difference) <= StaticVariables.DiffThreshold) { finalResultCollAftrComparison.Add(element); } } } } #endregion break; } return(finalResultCollAftrComparison); }
public List <Tuple <Int64, short, SpreadLogModel> > FillOrderPriceDictionary(DataTable dt, List <Tuple <Int64, short, SpreadLogModel> > dict) { List <Tuple <Int64, short, SpreadLogModel> > tempDict = (List <Tuple <Int64, short, SpreadLogModel> >)dict; foreach (DataRow node in dt.Rows) { try { long exorderId = Convert.ToInt64(node["exorderno"]); int logTime = Convert.ToInt32(node["logtime"]); string DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(logTime, "HH:mm:ss"); string symbol = Convert.ToString(node["secdesc"]); string symbolShort = Convert.ToString(node["symbol"]); double orderPrice = (Convert.ToDouble(node["price"])) / 100; short state = 2; short side = Convert.ToInt16(node["side"]); int token = Convert.ToInt32(node["token"]); int qty = Convert.ToInt32(node["qty"]); string tokenType = Convert.ToString(node["type"]); float threshold = ((float)(Convert.ToInt32(node["origth"])) / 100); char mktAnalysis = Convert.ToChar(node["ticktype"]); // char mktAnalysis = (char)(node["ticktype"]); //char mktAnalysis = 'Z'; int userId = Convert.ToInt32(node["userid"]); //int userId = Convert.ToInt32("AcceptRejectRule/"); string userCode = "T" + userId; //if(tempDict.Count>0) //{ if (state != 9) { bool tupleHasProduct = tempDict.Any(m => m.Item1 == exorderId && m.Item2 == state); if (!tupleHasProduct) { SpreadLogModel element = new SpreadLogModel(); element.ExchangeOrderId = exorderId; element.DateTime = DateTime; element.LogTime = logTime; element.SpreadQty = qty; element.UserID = (short)userId; element.UserCode = userCode; element.Threshold = threshold; element.StrategyType = strategyType; element.Side = side == 1 ? "BUY" : "SELL"; element.SpreadState = state == 9 ? "CANCELLED" : "TRADED"; element.Mkt = mktAnalysis; if (tokenType == "PE") { element.OrderPrice = tokenType + " | " + Convert.ToString(orderPrice); element.PutPrice = orderPrice; element.StrategyTag = symbol.Remove(symbol.Length - 2, 2); element.Symbol = symbolShort; } else if (tokenType == "CE") { element.OrderPrice = tokenType + " | " + Convert.ToString(orderPrice); element.CallPrice = orderPrice; element.StrategyTag = symbol.Remove(symbol.Length - 2, 2); element.Symbol = symbolShort; } else { element.OrderPrice = tokenType + " | " + Convert.ToString(orderPrice); element.FuturePrice = orderPrice; // element.StrategyTag = symbol; } Tuple <Int64, short, SpreadLogModel> _item = new Tuple <Int64, short, SpreadLogModel>(exorderId, state, element); tempDict.Add(_item); } else { var item = tempDict.Find(s => (s.Item1 == exorderId) && (s.Item2 == state)); SpreadLogModel element = new SpreadLogModel(); element.ExchangeOrderId = item.Item1; element.DateTime = item.Item3.DateTime; element.LogTime = item.Item3.LogTime; element.SpreadQty = item.Item3.SpreadQty; element.StrategyTag = item.Item3.StrategyTag; element.Symbol = symbolShort; element.Threshold = item.Item3.Threshold; element.StrategyType = item.Item3.StrategyType; element.Side = item.Item3.Side; element.SpreadState = item.Item3.SpreadState; element.Mkt = item.Item3.Mkt; element.UserCode = item.Item3.UserCode; element.UserID = item.Item3.UserID; if (tokenType == "PE") { element.OrderPrice = item.Item3.OrderPrice + " | " + tokenType + " | " + Convert.ToString(orderPrice); element.PutPrice = orderPrice; // element.FuturePrice = item.Item3.FuturePrice; element.CallPrice = item.Item3.CallPrice; } else if (tokenType == "CE") { element.OrderPrice = item.Item3.OrderPrice + " | " + tokenType + " | " + Convert.ToString(orderPrice); element.PutPrice = item.Item3.PutPrice; // element.FuturePrice = item.Item3.FuturePrice; element.CallPrice = orderPrice; } else { element.OrderPrice = item.Item3.OrderPrice + " | " + tokenType + " | " + Convert.ToString(orderPrice); // element.StrategyTag = item.Item3.StrategyTag + "|" + symbol; element.PutPrice = item.Item3.PutPrice; element.FuturePrice = orderPrice; element.CallPrice = item.Item3.CallPrice; } tempDict.Remove(item); Tuple <long, short, SpreadLogModel> item_New = new Tuple <long, short, SpreadLogModel>(item.Item1, item.Item2, element); tempDict.Add(item_New); } } else { continue; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(null); } } return(tempDict); }
public SpreadLogModel ProcessDataTableRowElement(DataRow row) { try { int userId = Convert.ToInt32(row["userid"]); string userCode = "T" + userId; long exorderId = Convert.ToInt64(row["exorderno"]); int logTime = Convert.ToInt32(row["logtime"]); string DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(logTime, "HH:mm:ss"); string symbol = Convert.ToString(row["secdesc"]); short state = Convert.ToInt16(row["orderstate"]); short side = Convert.ToInt16(row["side"]); short strategyTypeInShort = Convert.ToInt16(row["strategytype"]); int qty = Convert.ToInt32(row["qty"]); string tokenType = Convert.ToString(row["type"]); string stateStr = state == 9 ? "CANCELLED" : "TRADED"; string spreadSide = side == 1 ? "BUY" : "SELL"; if (strategyTypeInShort == 5) { strategyType = "FF"; } else if (strategyTypeInShort == 2) { strategyType = "CR"; } else if (strategyTypeInShort == 3) { strategyType = "BF"; } else if (strategyTypeInShort == 4) { strategyType = "BOX"; } else if (strategyTypeInShort == 6) { strategyType = "CSR"; } else if (strategyTypeInShort == 8) { strategyType = "PULSE"; } else { strategyType = ""; } string orderPricefinal = FillOrderPricesInSpread(exorderId, state); float threshold = ((float)(Convert.ToInt32(row["origth"])) / 100); char mktAnalysis = Convert.ToChar(row["ticktype"]); SpreadLogModel item = new SpreadLogModel() { UserID = (short)userId, UserCode = userCode, DateTime = DateTime, LogTime = logTime, ExchangeOrderId = exorderId, SpreadQty = qty, StrategyTag = symbol, Threshold = threshold, StrategyType = strategyType, Side = spreadSide, //HybridID = Convert.ToString((node["HybridID"])), SpreadState = stateStr, OrderPrice = orderPricefinal + " ]", //MktAnalaysisParams=Convert.ToString((node["MktAnalaysisParams"])) Mkt = mktAnalysis }; return(item); } catch (Exception ex) { return(null); } }
public ObservableCollection <SpreadLogModel> GetDataFromXml(string filePath, short user, bool MatchWithEveryRec) { try { XmlDocument doc = new XmlDocument(); doc.Load(filePath); XmlElement root = doc.DocumentElement; XmlNodeList nodes = root.SelectNodes("Table1"); ObservableCollection <SpreadLogModel> UserResult = new ObservableCollection <SpreadLogModel>(); foreach (XmlNode node in nodes) { if (node.HasChildNodes) { string mktA = Convert.ToString((node["MktAnalaysisParams"].InnerText)); // Console.WriteLine(mktA.IndexOf("TickType : ")); mktA = mktA.Substring(mktA.IndexOf("TickType"), 11); SpreadLogModel item = new SpreadLogModel() { UserID = Convert.ToInt16((node["UserID"].InnerText)), UserCode = Convert.ToString("T" + (node["UserID"].InnerText)), DateTime = Convert.ToString((node["DateTime"].InnerText)), LogTime = Convert.ToInt32((node["LogTime"].InnerText)), SpreadPrice = Convert.ToDouble((node["SpreadPrice"].InnerText)), ExchangeOrderId = Convert.ToInt64((node["ExchangeOrderId"].InnerText)), SpreadQty = Convert.ToInt32((node["SpreadQty"].InnerText)), StrategyTag = (node["StrategyTag"].InnerText), Threshold = float.Parse(node["Threshold"].InnerText), StrategyType = Convert.ToString((node["StrategyType"].InnerText)), Side = Convert.ToString((node["Side"].InnerText)), StrategyID = Convert.ToInt32((node["StrategyID"].InnerText)), //HybridID = Convert.ToString((node["HybridID"].InnerText)), SpreadState = Convert.ToString((node["SpreadState"].InnerText)), SpreadPriceStr = Convert.ToString((node["SpreadState"].InnerText)) == "CANCELLED" ? "" : Convert.ToString((node["SpreadPrice"].InnerText)), OrderPrice = Convert.ToString((node["OrderPrice"].InnerText)) + " ]", //MktAnalaysisParams=Convert.ToString((node["MktAnalaysisParams"].InnerText)) MktAnalaysisParams = mktA }; if (MatchWithEveryRec) { if (UserResult.Any(p => (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && (p.Threshold == item.Threshold)) == true) { var coll = from p in UserResult where (p.LogTime == item.LogTime) && (p.StrategyTag == item.StrategyTag) && (p.Threshold == item.Threshold) select p; foreach (var value in coll) { if (value.ExchangeOrderId > item.ExchangeOrderId) { UserResult.Add(item); UserResult.Remove(value); break; } } } else { UserResult.Add(item); } } else { UserResult.Add(item); } } } return(UserResult); } catch (Exception ex) { return(null); } }
public SpreadLogModel SetDictionaryForConsole_NSEComparison(string csvLine, Int64 foId) { string[] values = csvLine.Split(','); Int64 Fo_Id = Convert.ToInt64(values[30]); string stateStr = (Convert.ToString(values[29])).TrimEnd(); if (Fo_Id == foId && stateStr != "OCXL") { string dateTimeStr = (Convert.ToString(values[10]) + " " + Convert.ToString(values[28])); DateTime dt; if (DateTime.TryParse(dateTimeStr, out dt)) { // int result = DateTimeHelper.calculateSeconds(dt); } string Symbol_console = Convert.ToString(values[9]).TrimStart(); Symbol_console = Symbol_console.TrimEnd(); string side = Convert.ToString(values[7]); string OptType = Convert.ToString(values[12]); //string priceIndicator = Convert.ToString(values[12]); if (OptType == "CE") { callPrc = Convert.ToDouble(values[18]); strike = Convert.ToDouble(values[11]); } else if (OptType == "PE") { PutPrc = Convert.ToDouble(values[18]); strike = Convert.ToDouble(values[11]); } else { FutPrc = Convert.ToDouble(values[18]); strike = 0; } Int64 ExcgId = Convert.ToInt64(values[6]); SpreadLogModel dictItem; if (DictionaryOrderId_SpreadLogModel.TryGetValue(ExcgId, out dictItem)) { if (OptType == "CE") { dictItem.CallPrice = callPrc; dictItem.Strike = strike; } else if (OptType == "PE") { dictItem.PutPrice = PutPrc; dictItem.Strike = strike; } else { dictItem.FuturePrice = FutPrc; } if (dictItem.FuturePrice != 0 && dictItem.CallPrice != 0 && dictItem.PutPrice != 0) { dictItem.OrderPrice = "CE : " + dictItem.CallPrice + " | PE : " + dictItem.PutPrice + " | FT : " + dictItem.FuturePrice; //dictItem.Threshold = (float)(Convert.ToDouble(dictItem.FuturePrice - dictItem.Strike) - Convert.ToDouble(dictItem.PutPrice - dictItem.CallPrice)); dictItem.Threshold = (float)(Convert.ToDouble((dictItem.CallPrice - dictItem.PutPrice) - (dictItem.FuturePrice - dictItem.Strike))); } } else { SpreadLogModel item = new SpreadLogModel() { LogTime = DateTimeHelper.calculateSeconds(dt), DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(DateTimeHelper.calculateSeconds(dt), "HH:mm:ss"), StrategyTag = Symbol_console, Side = side == "B" ? "Buy" : "Sell", OptionType = OptType, CallPrice = callPrc, PutPrice = PutPrc, FuturePrice = FutPrc, ExchangeOrderId = ExcgId, SpreadState = stateStr == "OCXL" ? "CANCELLED" : "TRADED", Strike = strike }; DictionaryOrderId_SpreadLogModel.Add(ExcgId, item); } } return(null); }
public SpreadLogModel ReturnSpreadLogModelObjPostReadingCommaSeparatedTXTFile(string csvLine, Int64 foId) { string[] values = csvLine.Split(','); Int64 Fo_Id = Convert.ToInt64(values[30]); string stateStr = (Convert.ToString(values[29])).TrimEnd(); if (Fo_Id == foId && stateStr != "OCXL") { #region #Extracting values of the csv file line and returning the object string dateTimeStr = (Convert.ToString(values[10]) + " " + Convert.ToString(values[28])); DateTime dt; if (DateTime.TryParse(dateTimeStr, out dt)) { // int result = DateTimeHelper.calculateSeconds(dt); } string Symbol_console = Convert.ToString(values[9]); string side = Convert.ToString(values[7]); string OptType = Convert.ToString(values[12]); //string priceIndicator = Convert.ToString(values[12]); if (OptType == "CE") { callPrc = Convert.ToDouble(values[18]); strike = Convert.ToDouble(values[11]); } else if (OptType == "PE") { PutPrc = Convert.ToDouble(values[18]); strike = Convert.ToDouble(values[11]); } else { FutPrc = Convert.ToDouble(values[18]); strike = 0; } Int64 ExcgId = Convert.ToInt64(values[6]); SpreadLogModel dictItem; if (DictionaryOrderId_SpreadLogModel.TryGetValue(ExcgId, out dictItem)) { if (dictItem.OptionType == "CE") { } else if (dictItem.OptionType == "PE") { } else { } return(DictionaryOrderId_SpreadLogModel[ExcgId]); } else { SpreadLogModel item = new SpreadLogModel() { LogTime = DateTimeHelper.calculateSeconds(dt), DateTime = DateTimeHelper.getDateTimeStrFromNSEEpochSeconds(DateTimeHelper.calculateSeconds(dt), "HH:mm:ss"), StrategyTag = Symbol_console, Side = side == "B" ? "Buy" : "Sell", OptionType = OptType, CallPrice = callPrc, PutPrice = PutPrc, FuturePrice = FutPrc, ExchangeOrderId = ExcgId, SpreadState = stateStr == "OCXL" ? "CANCELLED" : "TRADED", Strike = strike }; DictionaryOrderId_SpreadLogModel.Add(ExcgId, item); return(DictionaryOrderId_SpreadLogModel[ExcgId]); } #endregion } else { return(null); } }