コード例 #1
0
        }//Shutdown()

        #endregion//Public Methods


        #region ActiveGrid Update Methods
        // *****************************************************************
        // ****                  Active Grid Methods                    ****
        // *****************************************************************
        //
        //
        /// <summary>
        /// This method should be called whenever the PositionBookChanges for a specific instrument.
        /// The instrument should have already triggered the PositionBookCreated event, but we double check just in case.
        /// Then, we proceed to acquire the lock for its fill book, extract data from it, and update all the cells.
        /// </summary>
        /// <param name="eventArgs"></param>
        private void ActiveGridUpdatePosition(FillHub.PositionBookChangedEventArgs eventArgs)
        {
            InstrumentName instrumentName = eventArgs.Instrument;

            if (!m_InstrumentInfos.ContainsKey(instrumentName.FullName))
            {
                return;
            }

            // Update info about the position book that changed.
            InstrumentRowData info = m_InstrumentInfos[instrumentName.FullName];
            IFillBook         positionBook;

            if (m_FillHub.TryEnterReadBook(instrumentName, out positionBook))
            {
                info.Position        = positionBook.NetPosition;
                info.StartingRealPnL = Math.Round(positionBook.RealizedStartingDollarGains, 2);
                info.RealPnL         = Math.Round(positionBook.RealizedDollarGains, 2);
                info.UnrealPnL       = Math.Round(positionBook.UnrealizedDollarGains(), 2);
                info.AverageCost     = Math.Round(positionBook.AveragePrice, info.MarketPriceDecimals);
                m_FillHub.ExitReadBook(instrumentName);
            }

            // Update the cells.
            UpdateActiveGridCell(instrumentName.FullName, "Position", info.Position, true);
            UpdateActiveGridCell(instrumentName.FullName, ColumnName_StartingRealPnL, info.StartingRealPnL, false);
            UpdateActiveGridCell(instrumentName.FullName, ColumnName_RealPnL, info.RealPnL, false);
            UpdateActiveGridCell(instrumentName.FullName, ColumnName_UnrealPnL, info.UnrealPnL, false);
            UpdateActiveGridCell(instrumentName.FullName, ColumnName_TotalPnL, info.TotalPnL, false);
            UpdateActiveGridCell(instrumentName.FullName, "AvePrice", info.AverageCost, false);

            // Update group pnl
            ActiveGridUpdateGroup(GetProductGroupKey(instrumentName));
        }//ActiveGridUpdatePosition()
コード例 #2
0
        }//UpdateActiveGridCell()

        #endregion //ActiveGrid Update Methods


        #region ActiveGrid Creation Methods
        // *****************************************************************
        // ****             Active Grid Creation Methods                ****
        // *****************************************************************
        //
        //
        //
        private void ActiveGridAddNewRow(FillHub.PositionBookChangedEventArgs eventArgs)
        {
            InstrumentName instrumentName = eventArgs.Instrument;

            if (m_InstrumentInfos.ContainsKey(instrumentName.FullName) &&
                activeGrid1.RowExists(instrumentName.FullName))
            {   // We already have a row for this instrument!  Update its values.
                // Update things that depend on the the currency rate too... since this may have updated!  [04 Jun 2013]
                InstrumentRowData info = m_InstrumentInfos[instrumentName.FullName];
                IFillBook         positionBook;
                if (m_FillHub.TryEnterReadBook(instrumentName, out positionBook))
                {
                    info.StartingRealPnL = Math.Round(positionBook.RealizedStartingDollarGains, 2);
                    info.RealPnL         = Math.Round(positionBook.RealizedDollarGains, 2);
                    info.UnrealPnL       = Math.Round(positionBook.UnrealizedDollarGains(), 2);
                    m_FillHub.ExitReadBook(instrumentName);
                }

                SKACERO.ActiveRow row = activeGrid1.Items[instrumentName.FullName];
                row.SubItems[GetCellKey(instrumentName.FullName, ColumnName_StartingRealPnL)].Text = info.StartingRealPnL.ToString("0.00");
                row.SubItems[GetCellKey(instrumentName.FullName, ColumnName_RealPnL)].Text         = info.RealPnL.ToString("0.00");
                row.SubItems[GetCellKey(instrumentName.FullName, ColumnName_UnrealPnL)].Text       = info.UnrealPnL.ToString("0.00");
                row.SubItems[GetCellKey(instrumentName.FullName, "Expiry")].Text   = m_InstrumentInfos[instrumentName.FullName].ExpirationDate.ToString("yyyy-MM-dd");
                row.SubItems[GetCellKey(instrumentName.FullName, "Currency")].Text = info.CurrencyCode;
                row.SubItems[GetCellKey(instrumentName.FullName, "SortKey")].Text  = string.Format("{0}{1}{2}{3}", instrumentName.Product.Exchange, instrumentName.Product.Type.ToString(), instrumentName.Product.ProductName, m_InstrumentInfos[instrumentName.FullName].ExpirationDate.ToString("yyyyMMdd"));
                activeGrid1.Sort();                                                                 // sort again, now we've changed the SortKey.
                return;
            }

            //
            // Create all tables we need for each new instrument.
            //
            m_InstrumentInfos.Add(instrumentName.FullName, new InstrumentRowData(instrumentName));

            string strKey = instrumentName.Product.Exchange;

            if (!m_ExchangeGroups.ContainsKey(strKey))                                              // Exchange group
            {
                m_ExchangeGroups.Add(strKey, new List <string>());                                  // maintain an entry for each ex
            }
            if (!m_ExchangeGroups[strKey].Contains(instrumentName.FullName))
            {
                m_ExchangeGroups[strKey].Add(instrumentName.FullName);
                if (m_ExchangeGroups[strKey].Count >= m_MinMembersForExchangeGroupRow &&
                    (!activeGrid1.Items.ContainsKey(string.Format("{0}{1}", GroupRowNamePrefix, strKey))))
                {
                    CreateSummaryRows(strKey, instrumentName.Product.Exchange, string.Empty);
                }
            }
            strKey = GetProductGroupKey(instrumentName);                                            // Product group: construct the exch+prod group name.
            if (!m_ProductGroups.ContainsKey(strKey))                                               // first time this product group showed up!
            {
                m_ProductGroups.Add(strKey, new List <string>());                                   // create a place for this prod group to hold its membership list.
            }
            if (!m_ProductGroups[strKey].Contains(instrumentName.FullName))                         // If this instrument is not yet part of group, add him.
            {
                m_ProductGroups[strKey].Add(instrumentName.FullName);                               // add new member of group
                if ((m_ProductGroups[strKey].Count >= m_MinMembersForProductGroupRow) &&
                    (!activeGrid1.Items.ContainsKey(string.Format("{0}{1}", GroupRowNamePrefix, strKey))))
                {
                    CreateSummaryRows(strKey, string.Empty, instrumentName.Product.ProductName);    // need to add a new summary line
                }
            }

            //
            // Create the row.
            //
            SKACERO.ActiveRow aRow = new SKACERO.ActiveRow();
            aRow.Name = instrumentName.FullName;
            aRow.Text = instrumentName.FullName;                                                    // this will appear in the zeroth column of the row.
            for (int i = 1; i < this.activeGrid1.Columns.Count; i++)
            {
                SKACERO.ActiveRow.ActiveCell cell = new SKACERO.ActiveRow.ActiveCell(aRow, String.Empty);
                cell.Name         = GetCellKey(instrumentName.FullName, this.activeGrid1.Columns[i].Name);
                cell.DecimalValue = Decimal.Zero;
                cell.PreTextFont  = new Font("Arial", cell.Font.Size);
                cell.PostTextFont = new Font("Arial", cell.Font.Size);
                aRow.SubItems.Add(cell);
            }

            // Load constant cells
            aRow.SubItems[GetCellKey(instrumentName.FullName, "Expiry")].Text         = m_InstrumentInfos[instrumentName.FullName].ExpirationDate.ToString("yyyy-MM-dd");
            aRow.SubItems[GetCellKey(instrumentName.FullName, "SortKey")].Text        = string.Format("{0}{1}{2}{3}", instrumentName.Product.Exchange, instrumentName.Product.Type.ToString(), instrumentName.Product.ProductName, m_InstrumentInfos[instrumentName.FullName].ExpirationDate.ToString("yyyyMMdd"));
            aRow.SubItems[GetCellKey(instrumentName.FullName, ColumnName_Alias)].Text = instrumentName.SeriesName;

            // Load Exchange cell optionally
            strKey = instrumentName.Product.Exchange;
            if (IsSuppressRepetativeExchangeProductLabels && activeGrid1.Items.ContainsKey(string.Format("{0}{1}", GroupRowNamePrefix, strKey)))
            {
                aRow.SubItems[GetCellKey(instrumentName.FullName, "Exchange")].Text = string.Empty;
            }
            else
            {
                aRow.SubItems[GetCellKey(instrumentName.FullName, "Exchange")].Text = instrumentName.Product.Exchange;
            }

            // Load Product cell, optionally.
            strKey = GetProductGroupKey(instrumentName);
            if (IsSuppressRepetativeExchangeProductLabels && activeGrid1.Items.ContainsKey(string.Format("{0}{1}", GroupRowNamePrefix, strKey)))
            {
                aRow.SubItems[GetCellKey(instrumentName.FullName, "Product")].Text = string.Empty;
            }
            else
            {
                aRow.SubItems[GetCellKey(instrumentName.FullName, "Product")].Text = instrumentName.Product.ProductName;
            }

            // Set currency column as empty string.
            aRow.SubItems[GetCellKey(instrumentName.FullName, "Currency")].Text = string.Empty;

            // Add row to our collection
            this.activeGrid1.SuspendLayout();
            try
            {
                if (!this.activeGrid1.Items.ContainsKey(aRow.Name))
                {
                    this.activeGrid1.Items.Add(aRow);
                }
            }
            catch (Exception e)
            {
                if (Log != null)
                {
                    Log.NewEntry(LogLevel.Major, "ActiveGridAddNewRow: Failed to add new row with name {0}. Execption {1}", aRow.Name, e.Message);
                }
            }
            activeGrid1.Sort();
            this.activeGrid1.ResumeLayout();

            // Update the row
            ActiveGridUpdatePosition(eventArgs);
        }//ActiveGridAddNewRow()