Ejemplo n.º 1
0
        private void frmOrderBook_Load(object sender, EventArgs e)
        {
            ob = new OneUnified.IQFeed.OrderBook();

            lvBid.Columns[0].TextAlign = HorizontalAlignment.Center;
            lvBid.Columns[1].TextAlign = HorizontalAlignment.Right;
            lvBid.Columns[2].TextAlign = HorizontalAlignment.Right;
            lvBid.Columns[3].TextAlign = HorizontalAlignment.Right;
            lvBid.Columns[4].TextAlign = HorizontalAlignment.Center;
            lvBid.Columns[5].TextAlign = HorizontalAlignment.Right;

            for (int i = 1; i <= MaxRowsToShow; i++)
            {
                string[]     items = { "-", "-", "-", "-", "-", "-" };
                ListViewItem lvi   = new ListViewItem(items);
                lvBid.Items.Add(lvi);
            }

            lvAsk.Columns[0].TextAlign = HorizontalAlignment.Center;
            lvAsk.Columns[1].TextAlign = HorizontalAlignment.Right;
            lvAsk.Columns[2].TextAlign = HorizontalAlignment.Right;
            lvAsk.Columns[3].TextAlign = HorizontalAlignment.Right;
            lvAsk.Columns[4].TextAlign = HorizontalAlignment.Center;
            lvAsk.Columns[5].TextAlign = HorizontalAlignment.Right;

            for (int i = 1; i <= MaxRowsToShow; i++)
            {
                string[]     items = { "-", "-", "-", "-", "-", "-" };
                ListViewItem lvi   = new ListViewItem(items);
                lvAsk.Items.Add(lvi);
            }
        }
Ejemplo n.º 2
0
        private void frmOrderBook_Load(object sender, EventArgs e)
        {
            //Console.WriteLine("frmOrderBook_Load");

            ob = new OneUnified.IQFeed.OrderBook();

            lvOrderBookView2.Columns[1].TextAlign = HorizontalAlignment.Center;
            lvOrderBookView2.Columns[2].TextAlign = HorizontalAlignment.Center;
            lvOrderBookView2.Columns[3].TextAlign = HorizontalAlignment.Center;

            for (int i = 1; i <= MaxRowsToShow; i++)
            {
                string[]     items = { "", "-", "-", "-" };
                ListViewItem lvi   = new ListViewItem(items);
                lvOrderBookView2.Items.Add(lvi);
            }
        }
Ejemplo n.º 3
0
        public void RedrawDisplay(OneUnified.IQFeed.OrderBook ob)
        {
            lock (ob) {
                if (ob.slAsk.Count > 0 && ob.slBid.Count > 0)
                {
                    int ix;

                    MarketMakerBidAsk mmbaBid = (MarketMakerBidAsk)ob.slBid.GetByIndex(0);
                    MarketMakerBidAsk mmbaAsk = (MarketMakerBidAsk)ob.slAsk.GetByIndex(0);

                    //double BidTop = mmbaBid.Bid;
                    //double AskTop = mmbaAsk.Ask;
                    //int BidTop = (int)Math.Round(100 * mmbaBid.Bid);
                    int BidTop = mmbaBid.Bid;
                    //int AskTop = (int)Math.Round(100 * mmbaAsk.Ask);
                    int AskTop = mmbaAsk.Ask;

                    int MidPrice = (BidTop + AskTop) / 2;
                    if (MidPrice != LastMidPrice)
                    {
                        HiPrice = MidPrice + NumRowsEachSide;
                        LoPrice = MidPrice - NumRowsEachSide;

                        slSizesBid.Clear();
                        slSizesAsk.Clear();
                        for (int i = LoPrice; i <= HiPrice; i++)
                        {
                            slSizesBid.Add(i, (int)0);
                            slSizesAsk.Add(i, (int)0);
                        }
                        LastMidPrice = MidPrice;
                    }
                    else
                    {
                        for (int i = LoPrice; i <= HiPrice; i++)
                        {
                            slSizesBid[i] = (int)0;
                            slSizesAsk[i] = (int)0;
                        }
                    }

                    ix = ob.slBidPrice.IndexOfKey(mmbaBid.Bid); // start at highest bid and work down
                    while (ix >= 0)
                    {
                        int val = (int)Math.Round(100 * (double)ob.slBidPrice.GetKey(ix));
                        if (val < LoPrice)
                        {
                            break;
                        }
                        if (val > HiPrice)
                        {
                            break;
                        }
                        slSizesBid[val] = (int)ob.slBidPrice.GetByIndex(ix);
                        ix--;
                    }

                    ix = ob.slAskPrice.IndexOfKey(mmbaAsk.Ask); // start at lowest ask and work up
                    while (ix < ob.slAskPrice.Count)
                    {
                        int val = (int)Math.Round(100 * (double)ob.slAskPrice.GetKey(ix));
                        if (val < LoPrice)
                        {
                            break;
                        }
                        if (val > HiPrice)
                        {
                            break;
                        }
                        slSizesAsk[val] = (int)ob.slAskPrice.GetByIndex(ix);
                        ix++;
                    }

                    /*
                     * foreach (MarketMakerBidAsk mmba in ob.slBid.Values) {
                     * int val = (int)Math.Round(100 * mmba.Bid);
                     * if (val < LoPrice) break;
                     * if (val > HiPrice) break;
                     * int size = (int)slSizes[val];
                     * slSizes[val] = size + mmba.BidSize;
                     * }
                     *
                     * foreach (MarketMakerBidAsk mmba in ob.slAsk.Values) {
                     * int val = (int)Math.Round(100 * mmba.Ask);
                     * if (val > HiPrice) break;
                     * if (val < LoPrice) break;
                     * int size = (int)slSizes[val];
                     * slSizes[val] = size + mmba.AskSize;
                     * }
                     */

                    for (int i = 1; i <= MaxRowsToShow; i++)
                    {
                        int    pr      = (int)slSizesBid.GetKey(i - 1);
                        double price   = (double)pr / 100.0;
                        int    sizeBid = (int)slSizesBid.GetByIndex(i - 1);
                        int    sizeAsk = (int)slSizesAsk.GetByIndex(i - 1);
                        int    j       = MaxRowsToShow - i;
                        lvOrderBookView2.Items[j].SubItems[1].Text      = (0 == sizeBid ? "" : sizeBid.ToString());
                        lvOrderBookView2.Items[j].SubItems[3].Text      = (0 == sizeAsk ? "" : sizeAsk.ToString());
                        lvOrderBookView2.Items[j].SubItems[2].Text      = price.ToString(PriceFormat);
                        lvOrderBookView2.Items[j].SubItems[2].ForeColor = (price == LastTradePrice) ? Color.Green : Color.Black;

                        /*
                         * if (pr == MidPrice) {
                         * lvOrderBookView2.Items[j].SubItems[1].Text = (0 == sizeBid ? "" : sizeBid.ToString());
                         * lvOrderBookView2.Items[j].SubItems[3].Text = (0 == sizeAsk ? "" : sizeAsk.ToString());
                         * }
                         * if (pr > MidPrice) {
                         * lvOrderBookView2.Items[j].SubItems[1].Text = "";
                         * lvOrderBookView2.Items[j].SubItems[3].Text = (0 == sizeBid ? "" : size.ToString());
                         * }
                         * if (pr < MidPrice) {
                         * lvOrderBookView2.Items[j].SubItems[1].Text = (0 == size ? "" : size.ToString());
                         * lvOrderBookView2.Items[j].SubItems[3].Text = "";
                         * }
                         * */
                    }
                }
                base.Refresh();
            }
        }
Ejemplo n.º 4
0
        public void RedrawDisplay(OneUnified.IQFeed.OrderBook ob)
        {
            lock (ob) {
                //lock (htMMInfo.SyncRoot) {
                int     i;
                int     cumcnt;
                int     colorix;
                Color[] colors = { Color.LightYellow, Color.PaleGoldenrod, Color.Wheat, Color.Goldenrod, Color.DarkGoldenrod,
                                   Color.DarkKhaki,   Color.DarkOrange,
                                   Color.Orange,      Color.OrangeRed,     Color.Red,   Color.Crimson };
                // Color.LightGoldenrodYellow, , Color.LemonChiffon, Color.Cornsilk, Color.PeachPuff,
                //Color[] colors = { Color.Yellow, Color.Green, Color.Blue, Color.Purple, Color.Red };
                int    cntColors = colors.GetLength(0);
                double LastValue = 0;

                if (bUpdateDisplay)
                {
                    //Console.WriteLine("OrderBookRefreshTimer_Elapsed");
                    //bUpdateDisplay = false;

                    try {
                        i       = 0;
                        colorix = 0;
                        cumcnt  = 0;
                        foreach (MarketMakerBidAsk mmba in ob.slAsk.Values)
                        {
                            if (0 == i)
                            {
                                colorix   = 0;
                                LastValue = mmba.Ask;
                            }
                            else
                            {
                                if (LastValue != mmba.Ask)
                                {
                                    LastValue = mmba.Ask;
                                    colorix   = ++colorix % cntColors;
                                }
                            }
                            cumcnt += mmba.AskSize;
                            DisplayLine(lvAsk, i++, colors[colorix], mmba.MMID, mmba.AskInside, cumcnt, mmba.Ask, mmba.AskSize,
                                        new TimeSpan(mmba.LastStamp.Hour, mmba.LastStamp.Minute, mmba.LastStamp.Second));
                            if (i >= MaxRowsToShow)
                            {
                                break;
                            }
                        }
                        while (i < MaxRowsToShow)
                        {
                            DisplayLine(lvAsk, i++, Color.White, "", 0, 0, 0, 0, new TimeSpan(0));
                        }
                    }
                    catch (Exception e) {
                        Console.WriteLine("OrderBookRefreshTimer_Elapsed foreach problem ask\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}",
                                          e.Data, e.HelpLink, e.Message, e.Source, e.StackTrace, e.ToString());
                    }

                    try {
                        i       = 0;
                        colorix = 0;
                        cumcnt  = 0;
                        foreach (MarketMakerBidAsk mmba in ob.slBid.Values)
                        {
                            if (0 == i)
                            {
                                colorix   = 0;
                                LastValue = mmba.Bid;
                            }
                            else
                            {
                                if (LastValue != mmba.Bid)
                                {
                                    LastValue = mmba.Bid;
                                    colorix   = ++colorix % cntColors;
                                }
                            }
                            cumcnt += mmba.BidSize;
                            DisplayLine(lvBid, i++, colors[colorix], mmba.MMID, mmba.BidInside, cumcnt, mmba.Bid, mmba.BidSize,
                                        new TimeSpan(mmba.LastStamp.Hour, mmba.LastStamp.Minute, mmba.LastStamp.Second));
                            if (i >= MaxRowsToShow)
                            {
                                break;
                            }
                        }
                        while (i < MaxRowsToShow)
                        {
                            DisplayLine(lvBid, i++, Color.White, "", 0, 0, 0, 0, new TimeSpan(0));
                        }
                    }
                    catch (Exception e) {
                        Console.WriteLine("OrderBookRefreshTimer_Elapsed foreach problem bid\n{0}\n{1}\n{2}\n{3}\n{4}\n{5}",
                                          e.Data, e.HelpLink, e.Message, e.Source, e.StackTrace, e.ToString());
                    }
                }
                base.Refresh();
                //this.Refresh();
            }
        }