Example #1
0
 public TWSTickGenericEventArgs(TWSClient client, int requestId, IBTickType tickType, double value)
     : base(client)
 {
     RequestId = requestId;
     TickType  = tickType;
     Value     = value;
 }
Example #2
0
 public TWSTickStringEventArgs(TWSClient client, int requestId, IBTickType tickType, string value)
     : base(client)
 {
     RequestId = requestId;
     TickType  = tickType;
     Value     = value;
 }
Example #3
0
 public TWSMarketDataEventArgs(TWSClient client,
                               TWSMarketDataSnapshot snapshot, IBTickType tickType)
     : base(client)
 {
     TickType = tickType;
     Snapshot = snapshot;
 }
Example #4
0
        void TickSizeHandler(TickSizeMessage message)
        {
            int        contractId = message.RequestId;
            IBTickType type       = (IBTickType)message.Field;
            dynamic    size       = message.Size;

            //Debug.WriteLine("ZEUS - TickSizeHandler: " + contractId + ", " + type + ", " + size);

            Market currentMarket = Contracts[contractId].Item2;

            currentMarket.Timestamp = Now;

            bool send = false;

            if (type == IBTickType.BidSize)
            {
                currentMarket.BidSize = size;
                send = true;
            }
            else if (type == IBTickType.AskSize)
            {
                currentMarket.AskSize = size;
                send = true;
            }

            if (send)
            {
                Ether.Send(currentMarket);
            }
        }
Example #5
0
 public TWSTickPriceEventArgs(TWSClient client, int requestId, IBTickType tickType,
                              double price, int size, int canAutoExecute)
     : base(client)
 {
     RequestId      = requestId;
     TickType       = tickType;
     Price          = price;
     Size           = size;
     CanAutoExecute = canAutoExecute;
 }
Example #6
0
 public TWSTickOptionComputationEventArgs(TWSClient client, int reqId, IBTickType tickType,
                                          double impliedVol, double delta, double modelPrice, double pvDividend)
     : base(client)
 {
     RequestId  = reqId;
     TickType   = tickType;
     ImpliedVol = impliedVol;
     Delta      = delta;
     ModelPrice = modelPrice;
     PVDividend = pvDividend;
 }
Example #7
0
 public void HandleMarketDataChange(int reqId, IBTickType tickType, double price, int size, int canAutoExecute)
 {
     // TODO: Don't forget to lock the socket
     _enc.Encode(ClientMessage.TickPrice);
     _enc.Encode(TWSServer.PROTOCOL_VERSION);
     _enc.Encode(reqId);
     _enc.Encode((int)tickType);
     _enc.Encode(price);
     _enc.Encode(size);
     _enc.Encode(canAutoExecute);
 }
Example #8
0
        public object ConnectData(int TopicId, ref Array Strings, ref bool GetNewValues)
        {
            if (Strings.Length != 2)
            {
                throw new Exception("Error: Must supply ContractId and TickType!");
            }

            string   contractKey = Strings.GetValue(0) as string;                                                           // The key in OM.
            Contract cc          = XLOM.Get <Contract>(contractKey);
            int      contractId  = cc.Id;
            string   contractCcy = cc.Currency;

            IBTickType tickType = (IBTickType)Enum.Parse(typeof(IBTickType), Strings.GetValue(1) as string, true);

            // If we're not already subscribed to this contract, crank up TWSSource.
            if (!(TopicsToContractIds.ContainsKey(TopicId) && TopicsToTickTypes.ContainsKey(TopicId)))
            {
                TopicsToContractIds.Add(TopicId, contractId);
                TopicsToTickTypes.Add(TopicId, tickType);

                if (!ContractsToMarkets.ContainsKey(contractId))
                {
                    ContractsToMarkets.Add(contractId, new Market(DateTimeOffset.UtcNow, contractId, -1, -1));
                    ContractsUpdated.Add(contractId, true);

                    XL_RTD.DataSource.Subscribe(cc);
                    XL_RTD.Ether.AsObservable <Market>().Where(x => x.ContractId == contractId).Subscribe(x =>
                    {
                        ContractsToMarkets[x.ContractId] = x;
                        ContractsUpdated[x.ContractId]   = true;

                        try
                        {
                            RTDCallback.UpdateNotify();
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.StackTrace);
                        }
                    },
                                                                                                          e =>
                    {
                        Debug.WriteLine(e.ToString());
                    });
                }
            }

            return("(WAITING)");
        }
Example #9
0
 public TWSTickEFPEventArgs(TWSClient client, int requestId, IBTickType tickType, double basisPoints,
                            string formattedBasisPoints, double impliedFuturesPrice, int holdDays,
                            string futureExpiry, double dividendImpact, double dividendsToExpiry)
     : base(client)
 {
     RequestId            = requestId;
     TickType             = tickType;
     BasisPoints          = basisPoints;
     FormattedBasisPoints = formattedBasisPoints;
     ImpliedFuturesPrice  = impliedFuturesPrice;
     HoldDays             = holdDays;
     FutureExpiry         = futureExpiry;
     DividendImpact       = dividendImpact;
     DividendsToExpiry    = dividendsToExpiry;
 }
Example #10
0
        void TickPriceHandler(TickPriceMessage message)
        {
            int        contractId = message.RequestId;
            IBTickType type       = (IBTickType)message.Field;
            dynamic    price      = message.Price;

            //Debug.WriteLine("ZEUS - TickPriceHandler: " + contractId + ", " + type + ", " + price);

            Market currentMarket = Contracts[contractId].Item2;

            currentMarket.Timestamp = Now;

            bool send = false;

            if (type == IBTickType.BidPrice && price > 0)
            {                       // TODO(live-5) - true for EFPs?
                currentMarket.Bid = price;

                if (Math.Abs(price / currentMarket.Bid - 1) < 0.15M)
                {
                    send = true;
                }
            }
            else if (type == IBTickType.AskPrice && price > 0)
            {
                currentMarket.Ask = price;

                if (Math.Abs(price / currentMarket.Ask - 1) < 0.15M)
                {
                    send = true;
                }
            }
            else if (currentMarket.Mid.Equals(decimal.MinValue) && (type == IBTickType.ClosePrice || type == IBTickType.LastPrice))
            {
                currentMarket.Ask = currentMarket.Bid = (decimal)price;
                send = true;
            }
            else if (type == IBTickType.ClosePrice)
            {
                currentMarket.PreviousClose = (decimal)price;
                send = true;
            }

            if (send)
            {
                Ether.Send(currentMarket);
            }
        }
Example #11
0
    protected void OnTickOptionComputation(int reqId, IBTickType tickType,
                                           double impliedVol, double delta, double optionPrice, double pvDividend, double gamma, double vega, double theta, double underlyingPrice)
    {
      if (TickOptionComputation != null)
        TickOptionComputation(this, new TWSTickOptionComputationEventArgs(this) {
          RequestId = reqId,
          TickType = tickType,
          ImpliedVol = impliedVol,
          Delta = delta,
          OptionPrice = optionPrice,
          PVDividend = pvDividend,
          Gamma = gamma,
          Vega = vega,
          Theta = theta,
          UnderlyingPrice = underlyingPrice,
        });

      TWSMarketDataSnapshot record;
      if (!_marketDataRecords.TryGetValue(reqId, out record)) {
        OnError(String.Format("OnTickPrice: Error request id {0}", reqId));
        return;
      }

      switch (tickType) {
        case IBTickType.BidOption:
          record.BidImpliedVol = impliedVol;
          record.BidDelta = delta;
          break;
        case IBTickType.AskOption:
          record.AskImpliedVol = impliedVol;
          record.AskDelta = delta;
          break;
        case IBTickType.LastOption:
          record.ImpliedVol = impliedVol;
          record.Delta = delta;
          break;
        case IBTickType.ModelOption:
          record.ImpliedVol = impliedVol;
          record.Delta = delta;
          record.PVDividend = pvDividend;
          record.ModelPrice = optionPrice;
          break;
        default:
          throw new ArgumentException("Error tick type - " + tickType);
      }

      OnMarketData(record, tickType);
    }
Example #12
0
    protected void OnTickPrice(int reqId, IBTickType tickType, double price, int size, int canAutoExecute)
    {
      if (TickPrice != null)
        TickPrice(this, new TWSTickPriceEventArgs(this) {
          TickerId = reqId,
          TickType = tickType,
          Price = price,
          Size = size,
          CanAutoExecute = canAutoExecute
        });

      TWSMarketDataSnapshot record;
      if (!_marketDataRecords.TryGetValue(reqId, out record)) {
        OnError(String.Format("OnTickPrice: Error request id {0}", reqId));
        return;
      }
      //Console.WriteLine("Client: Received tick price msg for reqid " + reqId + ", symbol " + record.Contract.Symbol +
      //                  ", price: " + price);
      // Crap?
      if (record.Contract.SecurityType != IBSecurityType.Index &&
          record.Contract.SecurityType != IBSecurityType.Cash &&
          size == 0)
        return;

      switch (tickType) {
        case IBTickType.BidPrice:
          record.Bid = price;
          if (!_settings.IgnoreSizeInPriceTicks)
            record.BidSize = size;
          record.BidTimeStamp = DateTime.Now;
          break;
        case IBTickType.AskPrice:
          record.Ask = price;
          if (!_settings.IgnoreSizeInPriceTicks)
            record.AskSize = size;
          record.AskTimeStamp = DateTime.Now;
          break;
        case IBTickType.LastPrice:
          // Make sure we are allowed to generate trades from this event type
          if ((_settings.TradeGeneration & TradeGeneration.LastSizePrice) == 0)
            return;
          record.Last = price;
          if (!_settings.IgnoreSizeInPriceTicks)
            record.LastSize = size;
          record.TradeTimeStamp = DateTime.Now;
          break;
        case IBTickType.HighPrice:
          record.High = price;
          break;
        case IBTickType.LowPrice:
          record.Low = price;
          break;
        case IBTickType.ClosePrice:
          record.Close = price;
          break;
        case IBTickType.OpenPrice:
          record.Open = price;
          break;

        default:
          throw new ArgumentException("Error tick type - " + tickType);
      }
      OnMarketData(record, tickType);
    }
Example #13
0
    protected void OnTickSize(int reqId, IBTickType tickType, int size)
    {
      if (size == 0)
        return;

      if (TickSize != null)
        TickSize(this, new TWSTickSizeEventArgs(this) {
          TickerId = reqId,
          TickType = tickType,
          Size = size
        });

      TWSMarketDataSnapshot record;
      if (!_marketDataRecords.TryGetValue(reqId, out record)) {
        OnError(String.Format("OnTickPrice: Error request id {0}", reqId));
        return;
      }

      int recordSize = size;
      bool lastDupHit = false;

      switch (tickType) {
        case IBTickType.BidSize:
          if (record.BidSize == size && FilterDups(record.BidTimeStamp)) {
            lastDupHit = true;
            record.BidDups++;
            break;
          }
          record.BidSize = size;
          break;
        case IBTickType.AskSize:
          if (record.AskSize == size && FilterDups(record.AskTimeStamp)) {
            lastDupHit = true;
            record.AskDups++;
            break;
          }
          record.AskSize = size;
          break;
        case IBTickType.LastSize:
          // Make sure we are allowed to generate trades from this event type
          if ((_settings.TradeGeneration & TradeGeneration.LastSize) == 0)
            return;
          if (record.LastSize == size && FilterDups(record.TradeTimeStamp)) {
            lastDupHit = true;
            record.TradeDups++;
            break;
          }
          record.LastSize = size;
          break;
        case IBTickType.Volume:
          record.Volume = size;
          if ((_settings.TradeGeneration & TradeGeneration.Volume) != 0) {
            // Synthetic volume matches reported volume
            if (record.SyntheticVolume == size)
              break;

            // This is just plain wrong... we may want to raise some sort
            // of red flag here..?!?
            if (record.SyntheticVolume > size)
              break;

            // If we got to here, it means we need to generate a trade from volume changes
            // with the last price using the volume difference between
            // the reported volume and the synthetic one...
            record.LastSize = (size - record.SyntheticVolume);
          }
          break;
        default:
          throw new ArgumentException("Error tick type - " + tickType);
      }
      if (lastDupHit == false)
        OnMarketData(record, tickType);
    }
Example #14
0
        private void UpdateGridRow(TWSMarketDataSnapshot s, IBTickType t)
        {
            var record = _symbolDataMap[s.Contract];

            record.Snapshot = s;
            // Make sure we don't crash and burn on the first invocation
            if (record.PreviousSnapshot == null)
            {
                record.PreviousSnapshot = record.Snapshot;
            }

            var g = record.Grid;
            var r = record.Row;
            var p = record.PreviousSnapshot;

            try {
                UnHighlightCells(record);

                if (s.LastTimeStamp != p.LastTimeStamp)
                {
                    SetValue(record, IBGridColumn.UpdateTime, s.LastTimeStamp);
                }
                if (s.Last != p.Last)
                {
                    SetValue(record, IBGridColumn.LastPrice, s.Last);
                }
                if (s.LastSize != p.LastSize)
                {
                    SetValue(record, IBGridColumn.LastSize, s.LastSize);
                }
                if (s.Volume != p.Volume)
                {
                    SetValue(record, IBGridColumn.Volume, s.Volume);
                }
                if (s.VolumeEvents != p.VolumeEvents)
                {
                    SetValue(record, IBGridColumn.VolumeEvents, s.VolumeEvents);
                }
                if (s.VolumeMisses != p.VolumeMisses)
                {
                    SetValue(record, IBGridColumn.VolumeMisses, s.VolumeMisses);
                }

                if (s.TradeDups != p.TradeDups)
                {
                    SetValue(record, IBGridColumn.TradeDups, s.TradeDups);
                }
                if (s.BidDups != p.BidDups)
                {
                    SetValue(record, IBGridColumn.BidDups, s.BidDups);
                }
                if (s.AskDups != p.AskDups)
                {
                    SetValue(record, IBGridColumn.AskDups, s.AskDups);
                }

                if (s.Bid != p.Bid)
                {
                    SetValue(record, IBGridColumn.BidPrice, s.Bid);
                }
                if (s.Ask != p.Ask)
                {
                    SetValue(record, IBGridColumn.AskPrice, s.Ask);
                }
                if (s.BidSize != p.BidSize)
                {
                    SetValue(record, IBGridColumn.BidSize, s.BidSize);
                }
                if (s.AskSize != p.AskSize)
                {
                    SetValue(record, IBGridColumn.AskSize, s.AskSize);
                }
                if (s.Close != p.Close)
                {
                    SetValue(record, IBGridColumn.Close, s.Close);
                }
                if (s.High != p.High)
                {
                    SetValue(record, IBGridColumn.High, s.High);
                }
                if (s.Low != p.Low)
                {
                    SetValue(record, IBGridColumn.Low, s.Low);
                }
                if (s.SyntheticVolume != p.SyntheticVolume)
                {
                    SetValue(record, IBGridColumn.SyntheticVolume, s.SyntheticVolume);
                }
                if (s.TradeEvents != p.TradeEvents)
                {
                    SetValue(record, IBGridColumn.TradeEvents, s.TradeEvents);
                }
                if (s.BidEvents != p.BidEvents)
                {
                    SetValue(record, IBGridColumn.BidEvents, s.BidEvents);
                }
                if (s.AskEvents != p.AskEvents)
                {
                    SetValue(record, IBGridColumn.AskEvents, s.AskEvents);
                }

                if (s.Contract.SecurityType != IBSecurityType.Option &&
                    s.Contract.SecurityType != IBSecurityType.FutureOption)
                {
                    return;
                }

                if (s.AskImpliedVol != p.AskImpliedVol)
                {
                    SetValue(record, IBGridColumn.AskImpVol, s.AskImpliedVol);
                }
                if (s.BidImpliedVol != p.BidImpliedVol)
                {
                    SetValue(record, IBGridColumn.BidImpVol, s.BidImpliedVol);
                }
                if (s.AskDelta != p.AskDelta)
                {
                    SetValue(record, IBGridColumn.AskDelta, s.AskDelta);
                }
                if (s.BidDelta != p.BidDelta)
                {
                    SetValue(record, IBGridColumn.BidDelta, s.BidDelta);
                }
                if (s.Delta != p.Delta)
                {
                    SetValue(record, IBGridColumn.Delta, s.Delta);
                }
                if (s.ImpliedVol != p.ImpliedVol)
                {
                    SetValue(record, IBGridColumn.Volatility, s.ImpliedVol);
                }
                if (s.ModelPrice != p.ModelPrice)
                {
                    SetValue(record, IBGridColumn.Price, s.ModelPrice);
                }
                if (s.PVDividend != p.PVDividend)
                {
                    SetValue(record, IBGridColumn.PVDividend, s.PVDividend);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                record.PreviousSnapshot = record.Snapshot;
                record.Snapshot         = null;
            }
        }
Example #15
0
 protected void OnMarketData(TWSMarketDataSnapshot snapshot, IBTickType tickType)
 {
   if (MarketData != null)
     MarketData(this, new TWSMarketDataEventArgs(this)
       {
         Snapshot =  snapshot,
         TickType = tickType
       });
 }
Example #16
0
    private void OnTickGeneric(int reqId, IBTickType tickType, double value)
    {
      if (TickGeneric != null)
        TickGeneric(this, new TWSTickGenericEventArgs(this) {
          TickerId = reqId,
          TickType = tickType,
          Value = value,
        });

      TWSMarketDataSnapshot record;
      if (!_marketDataRecords.TryGetValue(reqId, out record)) {
        OnError(String.Format("OnTickPrice: Error request id {0}", reqId));
        return;
      }

      bool tickRecognized = false;
      switch (tickType) {
        case IBTickType.LastTimestamp:
          record.LastTimeStamp = DateTime.FromFileTime((long) value);
          tickRecognized = true;
          break;
      }

      if (tickRecognized)
        OnMarketData(record, tickType);
    }
Example #17
0
 private void OnTickString(int reqId, IBTickType tickType, string value)
 {
     if (TickString != null)
         TickString(this, new TWSTickStringEventArgs(this, reqId, tickType, value));
 }
Example #18
0
    private void UpdateGridRow(TWSMarketDataSnapshot s, IBTickType t)
    {
      var record = _symbolDataMap[s.Contract];

      record.Snapshot = s;
      // Make sure we don't crash and burn on the first invocation
      if (record.PreviousSnapshot == null)
        record.PreviousSnapshot = record.Snapshot;

      var g = record.Grid;
      var r = record.Row;
      var p = record.PreviousSnapshot;

      try {
        UnHighlightCells(record);

        if (s.LastTimeStamp != p.LastTimeStamp) SetValue(record, IBGridColumn.UpdateTime, s.LastTimeStamp);
        if (s.Last != p.Last) SetValue(record, IBGridColumn.LastPrice, s.Last);
        if (s.LastSize != p.LastSize) SetValue(record, IBGridColumn.LastSize, s.LastSize);
        if (s.Volume != p.Volume) SetValue(record, IBGridColumn.Volume, s.Volume);
        if (s.VolumeEvents != p.VolumeEvents) SetValue(record, IBGridColumn.VolumeEvents, s.VolumeEvents);
        if (s.VolumeMisses != p.VolumeMisses) SetValue(record, IBGridColumn.VolumeMisses, s.VolumeMisses);

        if (s.TradeDups != p.TradeDups) SetValue(record, IBGridColumn.TradeDups, s.TradeDups);
        if (s.BidDups != p.BidDups) SetValue(record, IBGridColumn.BidDups, s.BidDups);
        if (s.AskDups != p.AskDups) SetValue(record, IBGridColumn.AskDups, s.AskDups);

        if (s.Bid != p.Bid) SetValue(record, IBGridColumn.BidPrice, s.Bid);
        if (s.Ask != p.Ask) SetValue(record, IBGridColumn.AskPrice, s.Ask);
        if (s.BidSize != p.BidSize) SetValue(record, IBGridColumn.BidSize, s.BidSize);
        if (s.AskSize != p.AskSize) SetValue(record, IBGridColumn.AskSize, s.AskSize);
        if (s.Close != p.Close) SetValue(record, IBGridColumn.Close, s.Close);
        if (s.High != p.High) SetValue(record, IBGridColumn.High, s.High);
        if (s.Low != p.Low) SetValue(record, IBGridColumn.Low, s.Low);
        if (s.SyntheticVolume != p.SyntheticVolume) SetValue(record, IBGridColumn.SyntheticVolume, s.SyntheticVolume);
        if (s.TradeEvents != p.TradeEvents) SetValue(record, IBGridColumn.TradeEvents, s.TradeEvents);
        if (s.BidEvents != p.BidEvents) SetValue(record, IBGridColumn.BidEvents, s.BidEvents);
        if (s.AskEvents != p.AskEvents) SetValue(record, IBGridColumn.AskEvents, s.AskEvents);

        if (s.Contract.SecurityType != IBSecurityType.Option &&
            s.Contract.SecurityType != IBSecurityType.FutureOption)
          return;

        if (s.AskImpliedVol != p.AskImpliedVol) SetValue(record, IBGridColumn.AskImpVol, s.AskImpliedVol);
        if (s.BidImpliedVol != p.BidImpliedVol) SetValue(record, IBGridColumn.BidImpVol, s.BidImpliedVol);
        if (s.AskDelta != p.AskDelta) SetValue(record, IBGridColumn.AskDelta, s.AskDelta);
        if (s.BidDelta != p.BidDelta) SetValue(record, IBGridColumn.BidDelta, s.BidDelta);
        if (s.Delta != p.Delta) SetValue(record, IBGridColumn.Delta, s.Delta);
        if (s.ImpliedVol != p.ImpliedVol) SetValue(record, IBGridColumn.Volatility, s.ImpliedVol);
        if (s.ModelPrice != p.ModelPrice) SetValue(record, IBGridColumn.Price, s.ModelPrice);
        if (s.PVDividend != p.PVDividend) SetValue(record, IBGridColumn.PVDividend, s.PVDividend);
      }
      catch (Exception ex)
      {
        MessageBox.Show(ex.Message);
      }
      finally
      {
        record.PreviousSnapshot = record.Snapshot;
        record.Snapshot = null;
      }

    }
Example #19
0
 public TWSTickSizeEventArgs(TWSClient client, int requestId, IBTickType sizeTickType, int size)
     : base(client)
 {
     RequestId = requestId;
     TickType = sizeTickType;
     Size = size;
 }
Example #20
0
        protected void OnTickPrice(int reqId, IBTickType tickType, double price, int size, int canAutoExecute)
        {
            if (TickPrice != null)
                TickPrice(this, new TWSTickPriceEventArgs(this, reqId, tickType, price, size, canAutoExecute));

            TWSMarketDataSnapshot record;
            if (!_marketDataRecords.TryGetValue(reqId, out record)) {
                OnError(String.Format("OnTickPrice: Unknown request id {0}", reqId));
                return;
            }

            // Crap?
            if (record.Contract.SecType != IBSecType.IND &&
                record.Contract.SecType != IBSecType.CASH &&
                size == 0)
                return;

            switch (tickType) {
                case IBTickType.BID:
                    record.Bid = price;
                    if (!_settings.IgnoreSizeInPriceTicks)
                        record.BidSize = size;
                    record.BidTimeStamp = DateTime.Now;
                    break;
                case IBTickType.ASK:
                    record.Ask = price;
                    if (!_settings.IgnoreSizeInPriceTicks)
                        record.AskSize = size;
                    record.AskTimeStamp = DateTime.Now;
                    break;
                case IBTickType.LAST:
                    // Make sure we are allowed to generate trades from this event type
                    if ((_settings.TradeGeneration & TradeGeneration.LastSizePrice) == 0)
                        return;
                    record.Last = price;
                    if (!_settings.IgnoreSizeInPriceTicks)
                        record.LastSize = size;
                    record.TradeTimeStamp = DateTime.Now;
                    break;
                case IBTickType.HIGH:
                    record.High = price;
                    break;
                case IBTickType.LOW:
                    record.Low = price;
                    break;
                case IBTickType.CLOSE:
                    record.Close = price;
                    break;
                case IBTickType.OPEN:
                    record.Open = price;
                    break;

                default:
                    throw new ArgumentException("Unknown tick type - " + tickType);
            }
            OnMarketData(record, tickType);
        }
Example #21
0
        protected void OnTickOptionComputation(int reqId, IBTickType tickType, 
            double impliedVol, double delta, double modelPrice, double pvDividend)
        {
            if (TickOptionComputation != null)
                TickOptionComputation(this,
                                      new TWSTickOptionComputationEventArgs(this, reqId, tickType,
                                                                            impliedVol, delta, modelPrice, pvDividend));

            TWSMarketDataSnapshot record;
            if (!_marketDataRecords.TryGetValue(reqId, out record)) {
                OnError(String.Format("OnTickPrice: Unknown request id {0}", reqId));
                return;
            }

            switch (tickType)
            {
                case IBTickType.BID_OPTION:
                    record.BidImpliedVol = impliedVol;
                    record.BidDelta = delta;
                    break;
                case IBTickType.ASK_OPTION:
                    record.AskImpliedVol = impliedVol;
                    record.AskDelta = delta;
                    break;
                case IBTickType.LAST_OPTION:
                    record.ImpliedVol = impliedVol;
                    record.Delta = delta;
                    break;
                case IBTickType.MODEL_OPTION:
                    record.ImpliedVol = impliedVol;
                    record.Delta = delta;
                    record.PVDividend = pvDividend;
                    record.ModelPrice = modelPrice;
                    break;
                default:
                    throw new ArgumentException("Unknown tick type - " + tickType);
            }

            OnMarketData(record, tickType);
        }
Example #22
0
 public TWSTickEFPEventArgs(TWSClient client, int requestId, IBTickType tickType, double basisPoints, 
     string formattedBasisPoints, double impliedFuturesPrice, int holdDays,
     string futureExpiry, double dividendImpact, double dividendsToExpiry)
     : base(client)
 {
     RequestId = requestId;
     TickType = tickType;
     BasisPoints = basisPoints;
     FormattedBasisPoints = formattedBasisPoints;
     ImpliedFuturesPrice = impliedFuturesPrice;
     HoldDays = holdDays;
     FutureExpiry = futureExpiry;
     DividendImpact = dividendImpact;
     DividendsToExpiry = dividendsToExpiry;
 }
Example #23
0
 public TWSMarketDataEventArgs(TWSClient client, 
     TWSMarketDataSnapshot snapshot, IBTickType tickType)
     : base(client)
 {
     TickType = tickType;
     Snapshot = snapshot;
 }
Example #24
0
 private void OnTickEFP(int reqId, IBTickType tickType, double basisPoints, string formattedBasisPoints, 
     double impliedFuturesPrice, int holdDays, string futureExpiry,
     double dividendImpact, double dividendsToExpiry)
 {
     if (TickEFP != null)
         TickEFP(this, new TWSTickEFPEventArgs(this, reqId, tickType, basisPoints, formattedBasisPoints,
                                                impliedFuturesPrice, holdDays, futureExpiry,
                                                dividendImpact, dividendsToExpiry));
 }
Example #25
0
 private void OnTickEFP(int reqId, IBTickType tickType, double basisPoints, string formattedBasisPoints,
                        double impliedFuturesPrice, int holdDays, string futureExpiry,
                        double dividendImpact, double dividendsToExpiry)
 {
   if (TickEFP != null)
     TickEFP(this, new TWSTickEFPEventArgs(this) {
       TickerId = reqId,
       TickType = tickType,
       BasisPoints = basisPoints,
       FormattedBasisPoints = formattedBasisPoints,
       ImpliedFuturesPrice = impliedFuturesPrice,
       HoldDays = holdDays,
       FutureExpiry = futureExpiry,
       DividendImpact = dividendImpact,
       DividendsToExpiry = dividendsToExpiry
     });
 }
Example #26
0
 public TWSTickStringEventArgs(TWSClient client, int requestId, IBTickType tickType, string value)
     : base(client)
 {
     RequestId = requestId;
     TickType = tickType;
     Value = value;
 }
Example #27
0
 private void OnTickString(int reqId, IBTickType tickType, string value)
 {
   if (TickString != null)
     TickString(this, new TWSTickStringEventArgs(this) {
       RequestId = reqId,
       TickType = tickType,
       Value = value
     });
 }
Example #28
0
 private void WriteToLog(TextWriter file, DateTime ts, double last, int size, IBTickType tickType)
 {
     file.WriteLine("{0},{1},{2},{3}", ts.Ticks, last, size, (int)tickType);
 }
Example #29
0
 public TWSTickGenericEventArgs(TWSClient client, int requestId, IBTickType tickType, double value)
     : base(client)
 {
     RequestId = requestId;
     TickType = tickType;
     Value = value;
 }
Example #30
0
 public TWSTickSizeEventArgs(TWSClient client, int requestId, IBTickType sizeTickType, int size) : base(client)
 {
     RequestId = requestId;
     TickType  = sizeTickType;
     Size      = size;
 }
Example #31
0
 public TWSTickOptionComputationEventArgs(TWSClient client, int reqId, IBTickType tickType,
     double impliedVol, double delta, double modelPrice, double pvDividend)
     : base(client)
 {
     RequestId = reqId;
     TickType = tickType;
     ImpliedVol = impliedVol;
     Delta = delta;
     ModelPrice = modelPrice;
     PVDividend = pvDividend;
 }
Example #32
0
 public TWSTickPriceEventArgs(TWSClient client, int requestId, IBTickType tickType, 
     double price, int size, int canAutoExecute)
     : base(client)
 {
     RequestId = requestId;
     TickType = tickType;
     Price = price;
     Size = size;
     CanAutoExecute = canAutoExecute;
 }
 public void HandleMarketDataChange(int reqId, IBTickType tickType, double price, int size, int canAutoExecute)
 {
   // TODO: Don't forget to lock the socket
   _enc.Encode(ClientMessage.TickPrice);
   _enc.Encode(TWSServer.PROTOCOL_VERSION);
   _enc.Encode(reqId);
   _enc.Encode((int) tickType);
   _enc.Encode(price);
   _enc.Encode(size);
   _enc.Encode(canAutoExecute);
 }
Example #34
0
 private void WriteToLog(TextWriter file, DateTime ts, double last, int size, IBTickType tickType)
 {
   file.WriteLine("{0},{1},{2},{3}", ts.Ticks, last, size, (int) tickType);
 }