示例#1
0
文件: Program.cs 项目: cadoogi/IBNet
 static void client_TickPrice(object sender, TickPriceEventArgs e)
 {
     Console.WriteLine("Price: " + e.Price + " Tick Type: " + EnumDescConverter.GetEnumDescription(e.TickType));
 }
示例#2
0
        void client_TickPrice(object sender, TickPriceEventArgs e)
        {
            Symbol symbol = null;
            TickData data;
            GotTickData listener = null;
            lock (_lockObject)
            {
                symbol = idToSymbol(e.TickerId);
                if (symbol == null)
                {
                    //	Not a watched symbol
                    return;
                }

                data = new TickData();
                data.time = GetAccountTime("price tick");
                data.price = (double)e.Price;

                if (data.price <= 0 &&
                    symbol.AssetClass != AssetClass.Future &&
                    symbol.AssetClass != AssetClass.Option &&
                    symbol.AssetClass != AssetClass.FuturesOption)
                {
                    //	GBP/USD was getting bid and ask ticks with a price of zero, so ignore these.
                    //	4/20/2010 - A user reported various forex symbols were getting negative prices, so these will also be ignored
                    return;
                }

                if (e.TickType == KRSTickType.BidPrice)
                {
                    //	Bid price
                    data.tickType = TickType.Bid;
                    lastBidSizes.TryGetValue(symbol, out data.size);
                    lastBidPrices[symbol] = (double)e.Price;
                }
                else if (e.TickType == KRSTickType.AskPrice)
                {
                    //	Ask price
                    data.tickType = TickType.Ask;
                    lastAskSizes.TryGetValue(symbol, out data.size);
                    lastAskPrices[symbol] = (double)e.Price;
                }
                else if (e.TickType == KRSTickType.LastPrice)
                {
                    //	Last price;
                    lastPrices[symbol] = (double)e.Price;

                    if (symbol.AssetClass == AssetClass.Index)
                    {
                        // Indexes don't come with volume ticks, so we can
                        // force this tick through instead of trying to match
                        // it up with a volume tick.
                        data.tickType = TickType.Trade;
                    }
                    else
                    {
                        return;
                    }
                }
                else if (e.TickType == KRSTickType.HighPrice)
                {
                    //	High price
                    data.tickType = TickType.HighPrice;
                }
                else if (e.TickType == KRSTickType.LowPrice)
                {
                    //	Low price
                    data.tickType = TickType.LowPrice;
                }
                else if (e.TickType == KRSTickType.ClosePrice)
                {
                    //	Close price
                    data.tickType = TickType.PreviousClose;
                }
                else if (e.TickType == Krs.Ats.IBNet.TickType.OpenPrice)
                {
                    data.tickType = TickType.OpenPrice;
                }
                else
                {
                    //	Unknown tick type
                    return;
                }
                listener = tickListener;
            }
            if (data.tickType != TickType.NotSet && listener != null)
            {
                listener(symbol, data);
            }
        }
        public void priceChangeTick(Object sender, TickPriceEventArgs e)
        {
            Product p = tickerIdsToProduct[e.TickerId];
            p.asOf = DateTime.UtcNow;
            log.Debug("Price change for " + p.symbol + " on " + e.TickType.ToString() + " New price = " + Convert.ToString(e.Price));

            switch (e.TickType)
            {
                case Krs.Ats.IBNet.TickType.BidPrice:
                    p.bid = Convert.ToDouble(e.Price);
                    if (BidUpdate != null)
                        BidUpdate(p);
                    break;
                case Krs.Ats.IBNet.TickType.AskPrice:
                    p.ask = Convert.ToDouble(e.Price);
                    if (AskUpdate != null)
                        AskUpdate(p);
                    break;
                case Krs.Ats.IBNet.TickType.LastPrice:
                    p.last = Convert.ToDouble(e.Price);
                    if (LastUpdate != null)
                        LastUpdate(p);
                    break;
                default:
                    break;
            }
        }
示例#4
0
        //////////////////////////////////////////////////////////////////////
        ////////////////////  TWS message event handlers /////////////////////
        //////////////////////////////////////////////////////////////////////

        void client_TickPrice(object sender, TickPriceEventArgs e)
        {
            //Console.WriteLine("Price: " + e.Price + " Tick Type: " + EnumDescConverter.GetEnumDescription(e.TickType));
            DateTime now = DateTime.Now;
            int secondFraction = (int)(now.Ticks % TimeSpan.TicksPerSecond / (TimeSpan.TicksPerSecond / 256));

            lock (capturingWriterLock)
            {
                capturingWriter.Write((byte)secondFraction); // record sub-second time (1/256th resolution)
                capturingWriter.Write((byte)e.TickType);  // kind of data (like bid, ask, last...)
                capturingWriter.Write((byte)e.TickerId);  // The Symbol ID (like AMD, INTC, INDU..)
                capturingWriter.Write((float)e.Price);    // The data - in this case price.
            }

            logger.Trace("{0} : {1} : {2} : {3}", e.TickType, symbols[e.TickerId].Symbol, e.TickerId, e.Price);
            totalCaptureEventsForDisplay++;
            lastRecievedUpdate = now;
        }