private void updateList(List <ModelEntry> model, DataGridView bookEntries, int baseRow)
        {
            double totalSize = 0.0;
            int    cumSize   = 0;

            if (baseRow > 0)
            {
                var modelEntry = model[checked (baseRow - 1)];
                cumSize   = model[checked (baseRow - 1)].CumSize;
                totalSize = model[checked (baseRow - 1)].TotalPrice;
            }

            for (var i = baseRow; i < model.Count; i++)
            {
                ModelEntry modelEntry = model[i];
                checked { cumSize += modelEntry.Size; }
                modelEntry.CumSize    = cumSize;
                totalSize            += modelEntry.Price * (double)modelEntry.Size;
                modelEntry.TotalPrice = totalSize;

                double avgPrice = totalSize / (double)cumSize;

                if (i > checked (bookEntries.Rows.Count - 1))
                {
                    bookEntries.Rows.Add();
                }
                var row = bookEntries.Rows[i];
                row.Cells[(int)Cell.MarketMaker].Value = modelEntry.MarketMaker;
                row.Cells[(int)Cell.Price].Value       = PriceFormatter.FormatPrice(modelEntry.Price, mSecType, mTickSize);
                row.Cells[(int)Cell.Size].Value        = modelEntry.Size;
                row.Cells[(int)Cell.CumSize].Value     = cumSize;
                row.Cells[(int)Cell.AvgPrice].Value    = avgPrice;
            }
        }
        internal void Initialise(int numberOfRows, string secType, double tickSize)
        {
            this.mAsks = new List <ModelEntry>(numberOfRows);
            this.mBids = new List <ModelEntry>(numberOfRows);
            InProgress = true;

            mFormatPrice    = PriceFormatter.GetPriceFormatter(secType, tickSize);
            mFormatAvgPrice = PriceFormatter.GetPriceFormatter(secType, tickSize, true);
        }
Exemple #3
0
        private void startMarketData(ContractDetails contractData, bool snapshot)
        {
            var id = mNextTickerId++;

            logMessage($"Starting ticker: id={id}; {contractToString(contractData.Contract)}");

            mApi.reqMktData(id, contractData.Contract, "", snapshot, false, null);
            Ticker ticker = new Ticker(contractData)
            {
                ContractDetails = contractData,
                FormatPrice     = PriceFormatter.GetPriceFormatter(contractData.Contract.SecType, contractData.MinTick * contractData.PriceMagnifier),
                IsSnapshot      = true
            };

            mTickers.Add(ticker);
        }
Exemple #4
0
        public void tickPrice(int tickerId, int tickType, double price, TickAttrib attribs)
        {
            var cd = mTickers[tickerId].ContractDetails;

            switch (tickType)
            {
            case IBApi.TickType.ASK:
                showTickerValue(tickerId, TickerColumnAsk, PriceFormatter.FormatPrice(price, cd.Contract.SecType, cd.MinTick * cd.PriceMagnifier));
                break;

            case IBApi.TickType.BID:
                showTickerValue(tickerId, TickerColumnBid, PriceFormatter.FormatPrice(price, cd.Contract.SecType, cd.MinTick * cd.PriceMagnifier));
                break;

            case IBApi.TickType.LAST:
                showTickerValue(tickerId, TickerColumnLast, PriceFormatter.FormatPrice(price, cd.Contract.SecType, cd.MinTick * cd.PriceMagnifier));
                break;
            }
        }