public static List<OpenInterestSummary> GetAccountSummary() { List<OpenInterestSummary> openInterestSummarys = new List<OpenInterestSummary>(); string xmlPath = GetCommandXmlPath("AccountSummary"); XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); XmlNodeList XmlNodeList = doc.ChildNodes[1].ChildNodes; foreach (XmlNode summaryNode in XmlNodeList) { OpenInterestSummary summaryItem = new OpenInterestSummary(); summaryItem.UpdateByXmlRowAttribute(summaryNode); openInterestSummarys.Add(summaryItem); } int i = 1; foreach (OpenInterestSummary item in openInterestSummarys) { Tuple<string,Guid, string> group = ExchangeData.GetAccountGroup("WF01", item.Id); //Just test item.GroupId = Guid.NewGuid(); item.GroupCode = "Demo"; item.Code = "Account00" + i; i++; } return openInterestSummarys; }
private static OpenInterestSummary OrderSummaryItemSetItem(Guid orderId, Guid instrumentId, AccountType accountType, string executePrice, decimal lotBalance, bool isBuy, decimal contractSize, string executeTime) { OpenInterestSummary orderSummaryItem = new OpenInterestSummary(); var executePriceValue = XmlConvert.ToDecimal(executePrice); decimal buyLot = isBuy ? lotBalance : decimal.Zero; decimal sellLot = !isBuy ? lotBalance : decimal.Zero; orderSummaryItem.Id = orderId; orderSummaryItem.InstrumentId = instrumentId; orderSummaryItem.Code = executeTime; orderSummaryItem.BuyLot = buyLot; orderSummaryItem.BuyAvgPrice = isBuy ? executePrice : "0"; orderSummaryItem.BuyContractSize = buyLot * contractSize; orderSummaryItem.SellLot = sellLot; orderSummaryItem.SellAvgPrice = !isBuy ? executePrice : "0"; orderSummaryItem.SellContractSize = sellLot * contractSize; if (accountType == AccountType.Company) //Company { orderSummaryItem.NetLot = sellLot - buyLot; orderSummaryItem.NetContractSize = sellLot * contractSize - buyLot * contractSize; } else { orderSummaryItem.NetLot = buyLot - sellLot; orderSummaryItem.NetContractSize = buyLot * contractSize - sellLot * contractSize; } orderSummaryItem.NetAvgPrice = isBuy ? executePrice : "-" + executePrice; return(orderSummaryItem); }
internal static List <OpenInterestSummary> GetOpenInterestAccountSummary(XmlNode accountSummaryNode) { List <OpenInterestSummary> openInterestSummarys = new List <OpenInterestSummary>(); foreach (XmlNode summaryNode in accountSummaryNode.ChildNodes) { OpenInterestSummary summaryItem = new OpenInterestSummary(); summaryItem.Initialize(summaryNode); openInterestSummarys.Add(summaryItem); } return(openInterestSummarys); }
internal static List <OpenInterestSummary> GetOpenInterestInstrumentSummary(XmlNode summaryXmlNode) { if (summaryXmlNode == null) { return(null); } List <OpenInterestSummary> openInterestSummarys = new List <OpenInterestSummary>(); foreach (XmlNode instrumentNode in summaryXmlNode.ChildNodes) { OpenInterestSummary instrumentSummary = new OpenInterestSummary(); instrumentSummary.Initialize(instrumentNode); openInterestSummarys.Add(instrumentSummary); } return(openInterestSummarys); }
internal static List <OpenInterestSummary> GetOpenInterestOrderSummary(XmlNode orderSummaryNode, AccountType accountType) { List <OpenInterestSummary> orderSummaryItems = new List <OpenInterestSummary>(); foreach (XmlNode tranNode in orderSummaryNode) { Guid transactionId = new Guid(tranNode.Attributes["ID"].Value); decimal contractSize = decimal.Parse(tranNode.Attributes["ContractSize"].Value); Guid instrumentId = new Guid(tranNode.Attributes["InstrumentID"].Value); string executeTime = tranNode.Attributes["ExecuteTime"].Value; foreach (XmlNode orderNode in tranNode.ChildNodes) { Guid orderId = new Guid(orderNode.Attributes["ID"].Value); bool isBuy = bool.Parse(orderNode.Attributes["IsBuy"].Value); decimal lotBalance = decimal.Parse(orderNode.Attributes["LotBalance"].Value); string executePrice = orderNode.Attributes["ExecutePrice"].Value; OpenInterestSummary orderSummaryItem = OrderSummaryItemSetItem(orderId, instrumentId, accountType, executePrice, lotBalance, isBuy, contractSize, executeTime); orderSummaryItems.Add(orderSummaryItem); } } return(orderSummaryItems); }
private static OpenInterestSummary OrderSummaryItemSetItem(AccountType accountType, string executePrice, decimal lotBalance, bool isBuy, decimal contractSize, string executeTime) { OpenInterestSummary orderSummaryItem = new OpenInterestSummary(); var executePriceValue = XmlConvert.ToDecimal(executePrice); decimal buyLot = isBuy ? lotBalance : decimal.Zero; decimal sellLot = !isBuy ? lotBalance : decimal.Zero; orderSummaryItem.Code = executeTime; orderSummaryItem.BuyLot = buyLot; orderSummaryItem.BuyAvgPrice = isBuy ? executePrice : "0"; orderSummaryItem.BuyContractSize = buyLot * contractSize; orderSummaryItem.SellLot = sellLot; orderSummaryItem.SellAvgPrice = !isBuy ? executePrice : "0"; orderSummaryItem.SellContractSize = sellLot * contractSize; if (accountType == AccountType.Company) //Company { orderSummaryItem.NetLot = sellLot - buyLot; orderSummaryItem.NetContractSize = sellLot * contractSize - buyLot * contractSize; } else { orderSummaryItem.NetLot = buyLot - sellLot; orderSummaryItem.NetContractSize = buyLot * contractSize - sellLot * contractSize; } orderSummaryItem.NetAvgPrice = isBuy ? executePrice : "-" + executePrice; return orderSummaryItem; }
public static List<OpenInterestSummary> GetInstrumentSummary() { List<OpenInterestSummary> openInterestSummarys = new List<OpenInterestSummary>(); string xmlPath = GetCommandXmlPath("InstrumentSummary"); XmlDocument doc = new XmlDocument(); doc.Load(xmlPath); XmlNodeList XmlNodeList = doc.ChildNodes[1].ChildNodes; foreach (XmlNode instrumentNode in XmlNodeList) { OpenInterestSummary instrumentSummary = new OpenInterestSummary(); instrumentSummary.UpdateByXmlRowAttribute(instrumentNode); openInterestSummarys.Add(instrumentSummary); } return openInterestSummarys; }
private Dictionary <string, OpenInterestSummary> GetOpenInterestSummarysByInstrument(Guid[] accountIDs, Guid[] instrumentIDs, string[] blotterCodeSelecteds) { Dictionary <string, OpenInterestSummary> openInterestSummarys = new Dictionary <string, OpenInterestSummary>(); foreach (Guid eachAccountId in accountIDs) { if (!AccountRepository.Default.Contains(eachAccountId)) { continue; } Account account = (Account)AccountRepository.Default.Get(eachAccountId); var trans = account.GetTrans(instrumentIDs); if (trans.Count > 0) { bool hasOpenOrder = false; OpenInterestSummary accountOpenInterestSummary = new OpenInterestSummary(eachAccountId.ToString()); foreach (Transaction tran in trans) { if (tran.OrderType == OrderType.BinaryOption) { continue; } bool isExistsOpenOrder; decimal buyLot, sellLot, buySumEL, sellSumEL, buyContractSize, sellContractSize; tran.OpenInterestSummary(blotterCodeSelecteds, out isExistsOpenOrder, out buyLot, out sellLot, out buySumEL, out sellSumEL, out buyContractSize, out sellContractSize); if (!isExistsOpenOrder) { continue; } hasOpenOrder = true; Instrument instrument = tran.Instrument; if (accountOpenInterestSummary.NumeratorUnit == null || accountOpenInterestSummary.NumeratorUnit > instrument.NumeratorUnit) { accountOpenInterestSummary.NumeratorUnit = instrument.NumeratorUnit; } if (accountOpenInterestSummary.Denominator == null || accountOpenInterestSummary.Denominator < instrument.Denominator) { accountOpenInterestSummary.Denominator = instrument.Denominator; } accountOpenInterestSummary.BuyLot += buyLot; accountOpenInterestSummary.SellLot += sellLot; accountOpenInterestSummary.BuySumEL += buySumEL; accountOpenInterestSummary.SellSumEL += sellSumEL; accountOpenInterestSummary.BuyContractSize += buyContractSize; accountOpenInterestSummary.SellContractSize += sellContractSize; accountOpenInterestSummary.AccountType = account.Type; if (account.Type == AccountType.Company) { accountOpenInterestSummary.NetLot = accountOpenInterestSummary.SellLot - accountOpenInterestSummary.BuyLot; accountOpenInterestSummary.NetContractSize = accountOpenInterestSummary.SellContractSize - accountOpenInterestSummary.BuyContractSize; } else { accountOpenInterestSummary.NetLot = accountOpenInterestSummary.BuyLot - accountOpenInterestSummary.SellLot; accountOpenInterestSummary.NetContractSize = accountOpenInterestSummary.BuyContractSize - accountOpenInterestSummary.SellContractSize; } } if (hasOpenOrder) { openInterestSummarys.Add(accountOpenInterestSummary.Id, accountOpenInterestSummary); } } } return(openInterestSummarys); }
public XmlNode GetOpenInterestInstrumentSummary(Token token, bool isGroupByOriginCode, string[] blotterCodeSelecteds) { Guid[] accountIDs = null; this.GetAccountIDs(token, ref accountIDs); if (accountIDs == null) { return(null); } Array.Sort(accountIDs); var openInterestInstrumentInfos = this.GetOpenInterestInstrumentInfoFromDB(token); _readWriteLock.EnterReadLock(); try { Logger.Info("GetOpenInterestInstrumentSummary"); XmlDocument xmlDoc = new XmlDocument(); XmlElement instrumentsNode = xmlDoc.CreateElement("Instruments"); if (!isGroupByOriginCode) { foreach (OpenInterestInstrumentInfo openInterestInstrumentInfo in openInterestInstrumentInfos.Values) { Guid[] instrumentIDs = new Guid[1]; instrumentIDs.SetValue(openInterestInstrumentInfo.InstrumentId, 0); var openInterestSummarys = this.GetOpenInterestSummarysByInstrument(accountIDs, instrumentIDs, blotterCodeSelecteds); if (openInterestSummarys.Count > 0) { OpenInterestSummary openInterestInstrumentSummary = new OpenInterestSummary(openInterestInstrumentInfo.InstrumentId.ToString()); foreach (OpenInterestSummary accountOpenInterestSummary in openInterestSummarys.Values) { if (openInterestInstrumentSummary.NumeratorUnit == null || accountOpenInterestSummary.NumeratorUnit > accountOpenInterestSummary.NumeratorUnit) { openInterestInstrumentSummary.NumeratorUnit = accountOpenInterestSummary.NumeratorUnit; } if (openInterestInstrumentSummary.Denominator == null || accountOpenInterestSummary.Denominator < accountOpenInterestSummary.Denominator) { openInterestInstrumentSummary.Denominator = accountOpenInterestSummary.Denominator; } openInterestInstrumentSummary.BuyLot += accountOpenInterestSummary.BuyLot; openInterestInstrumentSummary.SellLot += accountOpenInterestSummary.SellLot; openInterestInstrumentSummary.BuySumEL += accountOpenInterestSummary.BuySumEL; openInterestInstrumentSummary.SellSumEL += accountOpenInterestSummary.SellSumEL; openInterestInstrumentSummary.BuyContractSize += accountOpenInterestSummary.BuyContractSize; openInterestInstrumentSummary.SellContractSize += accountOpenInterestSummary.SellContractSize; openInterestInstrumentSummary.NetLot = accountOpenInterestSummary.NetLot; openInterestInstrumentSummary.NetContractSize = accountOpenInterestSummary.NetContractSize; } XmlNode instrumentNode = xmlDoc.ImportNode(openInterestInstrumentSummary.ToXmlNode("Instrument", openInterestInstrumentInfo.Code), true); instrumentsNode.AppendChild(instrumentNode); } } } else { Dictionary <string, List <Guid> > originCodeInstruments = new Dictionary <string, List <Guid> >(); foreach (OpenInterestInstrumentInfo openInterestInstrumentInfo in openInterestInstrumentInfos.Values) { List <Guid> originCodeOpenInterestInstrumentInfos; if (!originCodeInstruments.ContainsKey(openInterestInstrumentInfo.OriginCode)) { originCodeOpenInterestInstrumentInfos = new List <Guid>(); originCodeInstruments.Add(openInterestInstrumentInfo.OriginCode, originCodeOpenInterestInstrumentInfos); } else { originCodeOpenInterestInstrumentInfos = originCodeInstruments[openInterestInstrumentInfo.OriginCode]; } originCodeOpenInterestInstrumentInfos.Add(openInterestInstrumentInfo.InstrumentId); } foreach (string originCode in originCodeInstruments.Keys) { List <Guid> originCodeOpenInterestInstrumentInfos = originCodeInstruments[originCode]; var openInterestSummarys = this.GetOpenInterestSummarysByInstrument(accountIDs, originCodeOpenInterestInstrumentInfos.ToArray(), blotterCodeSelecteds); if (openInterestSummarys.Count > 0) { OpenInterestSummary openInterestInstrumentSummary = new OpenInterestSummary(originCode); foreach (OpenInterestSummary accountOpenInterestSummary in openInterestSummarys.Values) { if (openInterestInstrumentSummary.NumeratorUnit == null || accountOpenInterestSummary.NumeratorUnit > accountOpenInterestSummary.NumeratorUnit) { openInterestInstrumentSummary.NumeratorUnit = accountOpenInterestSummary.NumeratorUnit; } if (openInterestInstrumentSummary.Denominator == null || accountOpenInterestSummary.Denominator < accountOpenInterestSummary.Denominator) { openInterestInstrumentSummary.Denominator = accountOpenInterestSummary.Denominator; } openInterestInstrumentSummary.BuyLot += accountOpenInterestSummary.BuyLot; openInterestInstrumentSummary.SellLot += accountOpenInterestSummary.SellLot; openInterestInstrumentSummary.BuySumEL += accountOpenInterestSummary.BuySumEL; openInterestInstrumentSummary.SellSumEL += accountOpenInterestSummary.SellSumEL; openInterestInstrumentSummary.BuyContractSize += accountOpenInterestSummary.BuyContractSize; openInterestInstrumentSummary.SellContractSize += accountOpenInterestSummary.SellContractSize; openInterestInstrumentSummary.NetLot += accountOpenInterestSummary.NetLot; openInterestInstrumentSummary.NetContractSize += accountOpenInterestSummary.NetContractSize; } XmlNode instrumentNode = xmlDoc.ImportNode(openInterestInstrumentSummary.ToXmlNode("Instrument", originCode), true); instrumentsNode.AppendChild(instrumentNode); } } } if (!instrumentsNode.HasChildNodes) { instrumentsNode = null; } return(instrumentsNode); } catch (Exception e) { Logger.Error(e); return(null); } finally { _readWriteLock.ExitReadLock(); } }
//internal static void Initialize(this Transaction transaction, XmlNode xmlNode) //{ // foreach (XmlAttribute attribute in xmlNode.Attributes) // { // String nodeName = attribute.Name; // String nodeValue = attribute.Value; // if (nodeName == "ID") // { // transaction.Id = new Guid(nodeValue); // } // else if (nodeName == "Code") // { // transaction.Code = nodeValue; // } // else if (nodeName == "Type") // { // transaction.Type = (TransactionType)(int.Parse(nodeValue)); // } // else if (nodeName == "SubType") // { // transaction.SubType = (TransactionSubType)(int.Parse(nodeValue)); // } // else if (nodeName == "Phase") // { // transaction.Phase = (OrderPhase)(int.Parse(nodeValue)); // } // else if (nodeName == "BeginTime") // { // transaction.BeginTime = DateTime.Parse(nodeValue); // } // else if (nodeName == "EndTime") // { // transaction.EndTime = DateTime.Parse(nodeValue); // } // else if (nodeName == "ExpireType") // { // transaction.ExpireType = (ExpireType)(int.Parse(nodeValue)); // } // else if (nodeName == "SubmitTime") // { // transaction.SubmitTime = DateTime.Parse(nodeValue); // } // else if (nodeName == "SubmitorID") // { // transaction.SubmitorId = new Guid(nodeValue); // } // else if (nodeName == "ExecuteTime") // { // transaction.ExecuteTime = DateTime.Parse(nodeValue); // } // else if (nodeName == "OrderType") // { // transaction.OrderType = (OrderType)(int.Parse(nodeValue)); // } // else if (nodeName == "ContractSize") // { // transaction.ContractSize = decimal.Parse(nodeValue); // } // else if (nodeName == "AccountID") // { // transaction.AccountId = new Guid(nodeValue); // } // else if (nodeName == "InstrumentID") // { // transaction.InstrumentId = new Guid(nodeValue); // } // else if (nodeName == "ErrorCode") // { // transaction.Error = (TransactionError)Enum.Parse(typeof(TransactionError), nodeValue); // } // else if (nodeName == "AssigningOrderID" && !string.IsNullOrEmpty(nodeValue)) // { // transaction.AssigningOrderId = new Guid(nodeValue); // } // else if (nodeName == "InstrumentCategory") // { // transaction.InstrumentCategory = (InstrumentCategory)Enum.Parse(typeof(InstrumentCategory), nodeValue); // } // } //} //internal static void Initialize(this Order order, XmlNode xmlNode) //{ // foreach (XmlAttribute attribute in xmlNode.Attributes) // { // string nodeName = attribute.Name; // string nodeValue = attribute.Value; // if (nodeName.Equals("ID")) // { // order.Id = new Guid(nodeValue); // } // else if (nodeName.Equals("Code")) // { // order.Code = nodeValue; // } // else if (nodeName.Equals("Lot")) // { // order.Lot = decimal.Parse(nodeValue); // } // else if (nodeName == "MinLot") // { // if (!string.IsNullOrEmpty(nodeValue)) // { // order.MinLot = decimal.Parse(nodeValue); // } // } // else if (nodeName.Equals("IsOpen")) // { // order.IsOpen = bool.Parse(nodeValue); // } // else if (nodeName.Equals("IsBuy")) // { // order.IsBuy = bool.Parse(nodeValue); // } // else if (nodeName.Equals("SetPrice")) // { // order.SetPrice = nodeValue; // } // else if (nodeName.Equals("ExecutePrice")) // { // order.ExecutePrice = nodeValue; // } // else if (nodeName.Equals("BestPrice")) // { // order.BestPrice = nodeValue; // } // else if (nodeName.Equals("BestTime")) // { // order.BestTime = DateTime.Parse(nodeValue); // } // else if (nodeName.Equals("TradeOption")) // { // order.TradeOption = (TradeOption)(int.Parse(nodeValue)); // } // else if (nodeName.Equals("DQMaxMove")) // { // order.DQMaxMove = int.Parse(nodeValue); // } // else if (nodeName.Equals("HitCount")) // { // order.HitCount = short.Parse(nodeValue); // } // } //} internal static void Initialize(this OpenInterestSummary openInterestSummary, XmlNode xmlNode) { foreach (XmlAttribute attribute in xmlNode.Attributes) { String nodeName = attribute.Name; String nodeValue = attribute.Value; if (nodeName == "ID") { Guid id; Guid.TryParse(nodeValue, out id); if (id == Guid.Empty) { openInterestSummary.OriginCode = nodeValue; openInterestSummary.IsOrigin = true; } else { openInterestSummary.IsOrigin = false; openInterestSummary.Id = Guid.Parse(nodeValue); } } else if (nodeName == "Code") { openInterestSummary.Code = nodeValue; } else if (nodeName == "Type") { openInterestSummary.AccountType = (AccountType)(int.Parse(nodeValue)); } else if (nodeName == "MinNumeratorUnit") { openInterestSummary.MinNumeratorUnit = int.Parse(nodeValue); } else if (nodeName == "MaxDenominator") { openInterestSummary.MaxDenominator = int.Parse(nodeValue);; } else if (nodeName == "BuyLot") { openInterestSummary.BuyLot = decimal.Parse(nodeValue);; } else if (nodeName == "AvgBuyPrice") { openInterestSummary.BuyAvgPrice = nodeValue;; } else if (nodeName == "BuyContractSize") { openInterestSummary.BuyContractSize = decimal.Parse(nodeValue);; } else if (nodeName == "SellLot") { openInterestSummary.SellLot = decimal.Parse(nodeValue);; } else if (nodeName == "AvgSellPrice") { openInterestSummary.SellAvgPrice = nodeValue;; } else if (nodeName == "SellContractSize") { openInterestSummary.SellContractSize = decimal.Parse(nodeValue);; } else if (nodeName == "NetLot") { openInterestSummary.NetLot = decimal.Parse(nodeValue);; } else if (nodeName == "AvgNetPrice") { openInterestSummary.NetAvgPrice = nodeValue;; } else if (nodeName == "NetContractSize") { openInterestSummary.NetContractSize = decimal.Parse(nodeValue);; } } }