Beispiel #1
0
        internal static List <AccountGroupGNP> GetGroupNetPosition(XmlNode netXmlNode)
        {
            if (netXmlNode == null)
            {
                return(null);
            }
            List <AccountGroupGNP> accountGroups = new List <AccountGroupGNP>();

            foreach (XmlNode groupNode in netXmlNode.ChildNodes)
            {
                Guid            groupId         = new Guid(groupNode.Attributes["ID"].Value);
                string          groupCode       = groupNode.Attributes["Code"].Value;
                AccountGroupGNP accountGroupGNP = new AccountGroupGNP(groupId, groupCode);

                foreach (XmlNode accountNode in groupNode.ChildNodes[0].ChildNodes)
                {
                    Guid        accountId   = new Guid(accountNode.Attributes["ID"].Value);
                    string      accountCode = accountNode.Attributes["Code"].Value;
                    AccountType type        = (AccountType)Enum.ToObject(typeof(AccountType), int.Parse(accountNode.Attributes["Type"].Value));
                    AccountGNP  accountGNP  = new AccountGNP(accountId, accountCode, type);

                    foreach (XmlNode instrumentNode in accountNode.ChildNodes[0].ChildNodes)
                    {
                        Guid          instrumentId      = new Guid(instrumentNode.Attributes["ID"].Value);
                        decimal       lotBalance        = decimal.Parse(instrumentNode.Attributes["LotBalance"].Value);
                        decimal       quantity          = decimal.Parse(instrumentNode.Attributes["Quantity"].Value);
                        decimal       buyQuantity       = decimal.Parse(instrumentNode.Attributes["BuyQuantity"].Value);
                        string        buyAveragePrice   = instrumentNode.Attributes["BuyAveragePrice"].Value;
                        decimal       buyMultiplyValue  = decimal.Parse(instrumentNode.Attributes["BuyMultiplyValue"].Value);
                        decimal       sellQuantity      = decimal.Parse(instrumentNode.Attributes["SellQuantity"].Value);
                        string        sellAveragePrice  = instrumentNode.Attributes["SellAveragePrice"].Value;
                        decimal       sellMultiplyValue = decimal.Parse(instrumentNode.Attributes["SellMultiplyValue"].Value);
                        decimal       sellLot           = decimal.Parse(instrumentNode.Attributes["SellLot"].Value);
                        decimal       buyLot            = decimal.Parse(instrumentNode.Attributes["BuyLot"].Value);
                        decimal       sellSumEl         = decimal.Parse(instrumentNode.Attributes["SellSumEl"].Value);
                        decimal       buySumEl          = decimal.Parse(instrumentNode.Attributes["BuySumEl"].Value);
                        InstrumentGNP instrumentGNP     = new InstrumentGNP(instrumentId);
                        instrumentGNP.LotBalance        = lotBalance;
                        instrumentGNP.Quantity          = quantity;
                        instrumentGNP.BuyQuantity       = buyQuantity;
                        instrumentGNP.BuyAveragePrice   = buyAveragePrice;
                        instrumentGNP.BuyMultiplyValue  = buyMultiplyValue;
                        instrumentGNP.SellQuantity      = sellQuantity;
                        instrumentGNP.SellAveragePrice  = sellAveragePrice;
                        instrumentGNP.SellMultiplyValue = sellMultiplyValue;
                        instrumentGNP.SellLot           = sellLot;
                        instrumentGNP.BuyLot            = buyLot;
                        instrumentGNP.SellSumEl         = sellSumEl;
                        instrumentGNP.BuySumEl          = buySumEl;

                        accountGNP.InstrumentGNPs.Add(instrumentGNP);
                    }
                    accountGroupGNP.AccountGNPs.Add(accountGNP);
                }
                accountGroups.Add(accountGroupGNP);
            }

            return(accountGroups);
        }
        public static List<AccountGroupGNP> GetGroupNetPosition()
        {
            List<AccountGroupGNP> accountGroups = new List<AccountGroupGNP>();
            try
            {
                string xmlPath = GetCommandXmlPath("NetPosition");
                XmlDocument doc = new XmlDocument();
                doc.Load(xmlPath);
                XmlNode netXmlNode = doc.ChildNodes[1].ChildNodes[0];

                foreach (XmlNode groupNode in netXmlNode.ChildNodes)
                {
                    Guid groupId = new Guid(groupNode.Attributes["ID"].Value);
                    string groupCode = groupNode.Attributes["Code"].Value;
                    AccountGroupGNP accountGroupGNP = new AccountGroupGNP(groupId, groupCode);

                    foreach (XmlNode accountNode in groupNode.ChildNodes[0].ChildNodes)
                    {
                        Guid accountId = new Guid(accountNode.Attributes["ID"].Value);
                        string accountCode = accountNode.Attributes["Code"].Value;
                        AccountType type = (AccountType)Enum.ToObject(typeof(AccountType), int.Parse(accountNode.Attributes["Type"].Value));
                        AccountGNP accountGNP = new AccountGNP(accountId, accountCode, type);

                        foreach (XmlNode instrumentNode in accountNode.ChildNodes[0].ChildNodes)
                        {
                            Guid instrumentId = new Guid(instrumentNode.Attributes["ID"].Value);
                            decimal lotBalance = decimal.Parse(instrumentNode.Attributes["LotBalance"].Value);
                            decimal quantity = decimal.Parse(instrumentNode.Attributes["Quantity"].Value);
                            decimal buyQuantity = decimal.Parse(instrumentNode.Attributes["BuyQuantity"].Value);
                            string buyAveragePrice = instrumentNode.Attributes["BuyAveragePrice"].Value;
                            decimal buyMultiplyValue = decimal.Parse(instrumentNode.Attributes["BuyMultiplyValue"].Value);
                            decimal sellQuantity = decimal.Parse(instrumentNode.Attributes["SellQuantity"].Value);
                            string sellAveragePrice = instrumentNode.Attributes["SellAveragePrice"].Value;
                            decimal sellMultiplyValue = decimal.Parse(instrumentNode.Attributes["SellMultiplyValue"].Value);

                            InstrumentGNP instrumentGNP = new InstrumentGNP(instrumentId);
                            instrumentGNP.LotBalance = lotBalance;
                            instrumentGNP.Quantity = quantity;
                            instrumentGNP.BuyQuantity = buyQuantity;
                            instrumentGNP.BuyAveragePrice = buyAveragePrice;
                            instrumentGNP.BuyMultiplyValue = buyMultiplyValue;
                            instrumentGNP.SellQuantity = sellQuantity;
                            instrumentGNP.SellAveragePrice = sellAveragePrice;
                            instrumentGNP.SellMultiplyValue = sellMultiplyValue;

                            accountGNP.InstrumentGNPs.Add(instrumentGNP);
                        }
                        accountGroupGNP.AccountGNPs.Add(accountGNP);
                    }
                    accountGroups.Add(accountGroupGNP);
                }
            }
            catch (Exception ex)
            {
            }

            return accountGroups;
        }
Beispiel #3
0
        private Dictionary <Guid, InstrumentGNP> BuildInstrumentGNPDict(Account account, List <Protocal.Commands.Transaction> trans, string[] blotterCodeSelecteds)
        {
            Dictionary <Guid, InstrumentGNP> instrumentGNPs = new Dictionary <Guid, InstrumentGNP>();

            foreach (Transaction tran in trans)
            {
                bool    isExistsOpenOrder;
                decimal buyQuantity, buyMultiplyValue, sellQuantity, sellMultiplyValue, sellLot, buyLot, sellSumEl, buySumEl;

                tran.GroupNetPositionForManager(blotterCodeSelecteds, out isExistsOpenOrder, out buyQuantity, out buyMultiplyValue, out sellQuantity, out sellMultiplyValue, out buyLot, out sellLot, out buySumEl, out sellSumEl);
                if (!isExistsOpenOrder)
                {
                    continue;
                }

                InstrumentGNP instrumentGNP;
                if (instrumentGNPs.ContainsKey(tran.InstrumentId))
                {
                    instrumentGNP = instrumentGNPs[tran.InstrumentId];
                }
                else
                {
                    instrumentGNP = new InstrumentGNP(tran.InstrumentId, tran.Instrument.NumeratorUnit, tran.Instrument.Denominator);
                    instrumentGNPs.Add(tran.InstrumentId, instrumentGNP);
                }
                instrumentGNP.BuyQuantity       += buyQuantity;
                instrumentGNP.BuyMultiplyValue  += buyMultiplyValue;
                instrumentGNP.SellQuantity      += sellQuantity;
                instrumentGNP.SellMultiplyValue += sellMultiplyValue;
                instrumentGNP.SellLot           += sellLot;
                instrumentGNP.BuyLot            += buyLot;
                instrumentGNP.SellSumEl         += sellSumEl;
                instrumentGNP.BuySumEl          += buySumEl;
                if (account.Type == AccountType.Company)
                {
                    instrumentGNP.AddQuotation(sellQuantity - buyQuantity);
                    instrumentGNP.AddLotBalance(sellLot - buyLot);
                }
                else
                {
                    instrumentGNP.AddQuotation(buyQuantity - sellQuantity);
                    instrumentGNP.AddLotBalance(buyLot - sellLot);
                }
            }
            return(instrumentGNPs);
        }
        private void CalculateLotBalance(string exchangeCode)
        {
            int i = 0;
            RootGNP rootGNP = this._GroupNetPositionModel.RootGNPs[0];
            foreach (AccountGroupGNP groupGNP in this._GroupNetPositionModel.RootGNPs[0].AccountGroupGNPs)
            {
                foreach (AccountGNP accountGNP in groupGNP.AccountGNPs)
                {
                    DetailGNP detailGNP = new DetailGNP();
                    detailGNP.AccountId = accountGNP.Id;
                    foreach (InstrumentGNP instrumentGNP in accountGNP.InstrumentGNPs)
                    {
                        InstrumentClient instrument = this._App.ExchangeDataManager.GetExchangeSetting(exchangeCode).Instruments.Values.SingleOrDefault(P => P.Id == instrumentGNP.Id);
                        if (instrument == null) continue;
                        instrumentGNP.Instrument = instrument;
                        detailGNP.InstrumentId = instrument.Id;

                        string summaryGroupCode = instrument.SummaryGroupId == null ? "Other":instrument.SummaryGroupCode;

                        if (!this._AllColumns.Contains(instrumentGNP.InstrumentCode))
                        {
                            string key = "Item" + instrumentGNP.InstrumentCode;
                            decimal totalSum = this._GroupNetPositionModel.RootGNPs[0].Columns[key] == null ? decimal.Zero : (decimal)this._GroupNetPositionModel.RootGNPs[0].Columns[key];
                            decimal groupSum = groupGNP.Columns[key] == null ? decimal.Zero : (decimal)groupGNP.Columns[key];

                            rootGNP.Columns[key] = totalSum + instrumentGNP.LotBalance;
                            groupGNP.Columns[key] = groupSum + instrumentGNP.LotBalance;
                            accountGNP.Columns[key] = instrumentGNP.LotBalance;
                            detailGNP.Columns[key] = instrumentGNP.Detail;
                            instrumentGNP.ColumnIndex = i;
                            instrumentGNP.SummaryGroupCode = summaryGroupCode;

                            this._AllColumns.Add(instrumentGNP.InstrumentCode, instrumentGNP);
                            i++;
                        }
                        else
                        {
                            InstrumentGNP item = (InstrumentGNP)this._AllColumns[instrumentGNP.InstrumentCode];
                            string key = "Item" + item.InstrumentCode;
                            decimal totalSum = rootGNP.Columns[key] == null ? decimal.Zero : (decimal)rootGNP.Columns[key];
                            decimal groupSum = groupGNP.Columns[key] == null ? decimal.Zero : (decimal)groupGNP.Columns[key];

                            rootGNP.Columns[key] = totalSum + instrumentGNP.LotBalance;
                            groupGNP.Columns[key] = groupSum + instrumentGNP.LotBalance;
                            accountGNP.Columns[key] = instrumentGNP.LotBalance;
                            detailGNP.Columns[key] = instrumentGNP.Detail;
                        }

                        //Summary Group LotBalance
                        if (!this._SummaryColumns.Contains(summaryGroupCode))
                        {
                            InstrumentGNP summaryGNP = new InstrumentGNP();
                            summaryGNP.Instrument = instrument;
                            summaryGNP.IsSummaryGroup = true;
                            summaryGNP.ColumnIndex = i;
                            summaryGNP.SummaryGroupCode = summaryGroupCode;

                            string key = "Item" + summaryGNP.SummaryGroupCode;
                            decimal totalSum = rootGNP.Columns[key] == null ? decimal.Zero : (decimal)rootGNP.Columns[key];
                            decimal groupSum = groupGNP.Columns[key] == null ? decimal.Zero : (decimal)groupGNP.Columns[key];

                            rootGNP.Columns[key] = totalSum + instrumentGNP.LotBalance;
                            groupGNP.Columns[key] = groupSum + instrumentGNP.LotBalance;
                            accountGNP.Columns[key] = instrumentGNP.LotBalance;

                            this._SummaryColumns.Add(summaryGroupCode, summaryGNP);
                            this._AllColumns.Add(summaryGroupCode, summaryGNP);
                            i++;
                        }
                        else
                        {
                            InstrumentGNP summaryGNP = (InstrumentGNP)this._SummaryColumns[summaryGroupCode];
                            string key = "Item" + summaryGroupCode;
                            decimal totalSum = rootGNP.Columns[key] == null ? decimal.Zero : (decimal)rootGNP.Columns[key];
                            decimal groupSum = groupGNP.Columns[key] == null ? decimal.Zero : (decimal)groupGNP.Columns[key];

                            rootGNP.Columns[key] = totalSum + instrumentGNP.LotBalance;
                            groupGNP.Columns[key] = groupSum + instrumentGNP.LotBalance;
                            accountGNP.Columns[key] = instrumentGNP.LotBalance;
                        }
                    }
                    accountGNP.DetailGNPs.Add(detailGNP);
                }
            }
        }