void HandleTickSize(object sender, IB.TickSizeEventArgs e) { var symbol = default(Symbol); if (!_subscribedTickets.TryGetValue(e.TickerId, out symbol)) return; var tick = new Tick(); // in the event of a symbol change this will break since we'll be assigning the // new symbol to the permtick which won't be known by the algorithm tick.Symbol = symbol; var securityType = symbol.ID.SecurityType; tick.Quantity = AdjustQuantity(securityType, e.Size); tick.Time = GetBrokerTime(); if (securityType == SecurityType.Forex) { // forex exchange hours are specified in UTC-05 tick.Time = tick.Time.ConvertTo(TimeZones.NewYork, TimeZones.EasternStandard); } if (tick.Quantity == 0) return; switch (e.TickType) { case IB.TickType.BidSize: tick.TickType = TickType.Quote; _lastBidPrices.TryGetValue(symbol, out tick.BidPrice); _lastBidSizes[symbol] = tick.Quantity; tick.Value = tick.BidPrice; tick.BidSize = tick.Quantity; break; case IB.TickType.AskSize: tick.TickType = TickType.Quote; _lastAskPrices.TryGetValue(symbol, out tick.AskPrice); _lastAskSizes[symbol] = tick.Quantity; tick.Value = tick.AskPrice; tick.AskSize = tick.Quantity; break; case IB.TickType.LastSize: tick.TickType = TickType.Trade; decimal lastPrice; _lastPrices.TryGetValue(symbol, out lastPrice); _lastVolumes[symbol] = tick.Quantity; tick.Value = lastPrice; break; default: return; } lock (_ticks) if (tick.IsValid()) _ticks.Add(tick); }
void HandleTickSize(object sender, IB.TickSizeEventArgs e) { var symbol = default(SymbolCacheKey); if (!_subscribedTickets.TryGetValue(e.TickerId, out symbol)) return; var tick = new Tick(); tick.Symbol = symbol.Item2; tick.Quantity = AdjustQuantity(symbol.Item1, e.Size); tick.Time = GetBrokerTime(); if (tick.Quantity == 0) return; switch (e.TickType) { case IB.TickType.BidSize: tick.TickType = TickType.Quote; _lastBidPrices.TryGetValue(symbol, out tick.BidPrice); _lastBidSizes[symbol] = tick.Quantity; tick.Value = tick.BidPrice; break; case IB.TickType.AskSize: tick.TickType = TickType.Quote; _lastAskPrices.TryGetValue(symbol, out tick.AskPrice); _lastAskSizes[symbol] = tick.Quantity; tick.Value = tick.AskPrice; break; case IB.TickType.LastSize: tick.TickType = TickType.Trade; decimal lastPrice; _lastPrices.TryGetValue(symbol, out lastPrice); _lastVolumes[symbol] = tick.Quantity; tick.Value = lastPrice; break; default: return; } lock (_ticks) if (tick.IsValid()) _ticks.Add(tick); }
void HandleTickPrice(object sender, IB.TickPriceEventArgs e) { var symbol = default(SymbolCacheKey); if (!_subscribedTickets.TryGetValue(e.TickerId, out symbol)) return; var tick = new Tick(); tick.Symbol = symbol.Item2; tick.Time = GetBrokerTime(); tick.Value = e.Price; if (e.Price <= 0 && symbol.Item1 != SecurityType.Future && symbol.Item1 != SecurityType.Option) return; switch (e.TickType) { case IB.TickType.BidPrice: tick.TickType = TickType.Quote; tick.BidPrice = e.Price; _lastBidSizes.TryGetValue(symbol, out tick.Quantity); _lastBidPrices[symbol] = e.Price; break; case IB.TickType.AskPrice: tick.TickType = TickType.Quote; tick.AskPrice = e.Price; _lastAskSizes.TryGetValue(symbol, out tick.Quantity); _lastAskPrices[symbol] = e.Price; break; case IB.TickType.LastPrice: tick.TickType = TickType.Trade; tick.Value = e.Price; _lastPrices[symbol] = e.Price; break; case IB.TickType.HighPrice: case IB.TickType.LowPrice: case IB.TickType.ClosePrice: case IB.TickType.OpenPrice: default: return; } lock (_ticks) if (tick.IsValid()) _ticks.Add(tick); }
void HandleTickPrice(object sender, IB.TickPriceEventArgs e) { var symbol = default(SymbolCacheKey); if (!_subscribedTickets.TryGetValue(e.TickerId, out symbol)) return; var tick = new Tick(); // in the event of a symbol change this will break since we'll be assigning the // new symbol to the permtick which won't be known by the algorithm tick.Symbol = new Symbol(symbol.Item2); tick.Time = GetBrokerTime(); if (symbol.Item1 == SecurityType.Forex) { // forex exchange hours are specified in UTC-05 tick.Time = tick.Time.ConvertTo(TimeZones.NewYork, TimeZones.EasternStandard); } tick.Value = e.Price; if (e.Price <= 0 && symbol.Item1 != SecurityType.Future && symbol.Item1 != SecurityType.Option) return; switch (e.TickType) { case IB.TickType.BidPrice: tick.TickType = TickType.Quote; tick.BidPrice = e.Price; _lastBidSizes.TryGetValue(symbol, out tick.Quantity); _lastBidPrices[symbol] = e.Price; break; case IB.TickType.AskPrice: tick.TickType = TickType.Quote; tick.AskPrice = e.Price; _lastAskSizes.TryGetValue(symbol, out tick.Quantity); _lastAskPrices[symbol] = e.Price; break; case IB.TickType.LastPrice: tick.TickType = TickType.Trade; tick.Value = e.Price; _lastPrices[symbol] = e.Price; break; case IB.TickType.HighPrice: case IB.TickType.LowPrice: case IB.TickType.ClosePrice: case IB.TickType.OpenPrice: default: return; } lock (_ticks) if (tick.IsValid()) _ticks.Add(tick); }
void HandleTickSize(object sender, IB.TickSizeEventArgs e) { var symbol = default(SymbolCacheKey); if (!_subscribedTickets.TryGetValue(e.TickerId, out symbol)) return; var tick = new Tick(); // in the event of a symbol change this will break since we'll be assigning the // new symbol to the permtick which won't be known by the algorithm tick.Symbol = new Symbol(symbol.Item2); tick.Quantity = AdjustQuantity(symbol.Item1, e.Size); tick.Time = GetBrokerTime(); if (tick.Quantity == 0) return; switch (e.TickType) { case IB.TickType.BidSize: tick.TickType = TickType.Quote; _lastBidPrices.TryGetValue(symbol, out tick.BidPrice); _lastBidSizes[symbol] = tick.Quantity; tick.Value = tick.BidPrice; break; case IB.TickType.AskSize: tick.TickType = TickType.Quote; _lastAskPrices.TryGetValue(symbol, out tick.AskPrice); _lastAskSizes[symbol] = tick.Quantity; tick.Value = tick.AskPrice; break; case IB.TickType.LastSize: tick.TickType = TickType.Trade; decimal lastPrice; _lastPrices.TryGetValue(symbol, out lastPrice); _lastVolumes[symbol] = tick.Quantity; tick.Value = lastPrice; break; default: return; } lock (_ticks) if (tick.IsValid()) _ticks.Add(tick); }
private void HandleTickPrice(object sender, IB.TickPriceEventArgs e) { Symbol symbol; if (!_subscribedTickets.TryGetValue(e.TickerId, out symbol)) return; var price = Convert.ToDecimal(e.Price); var tick = new Tick(); // in the event of a symbol change this will break since we'll be assigning the // new symbol to the permtick which won't be known by the algorithm tick.Symbol = symbol; tick.Time = GetBrokerTime(); var securityType = symbol.ID.SecurityType; if (securityType == SecurityType.Forex) { // forex exchange hours are specified in UTC-05 tick.Time = tick.Time.ConvertTo(TimeZones.NewYork, TimeZones.EasternStandard); } tick.Value = price; if (e.Price <= 0 && securityType != SecurityType.Future && securityType != SecurityType.Option) return; switch (e.Field) { case IBApi.TickType.BID: tick.TickType = TickType.Quote; tick.BidPrice = price; _lastBidSizes.TryGetValue(symbol, out tick.Quantity); _lastBidPrices[symbol] = price; break; case IBApi.TickType.ASK: tick.TickType = TickType.Quote; tick.AskPrice = price; _lastAskSizes.TryGetValue(symbol, out tick.Quantity); _lastAskPrices[symbol] = price; break; case IBApi.TickType.LAST: tick.TickType = TickType.Trade; tick.Value = price; _lastPrices[symbol] = price; break; default: return; } lock (_ticks) if (tick.IsValid()) _ticks.Add(tick); }