public TWSTickEventArgs(TWSSubscription subscription, int field, double price, TickAttrib attribs = null)
     : this(subscription)
 {
     Field       = field;
     DoubleValue = price;
     Attribs     = attribs;
 }
Beispiel #2
0
 public void tickPrice(int tickerId, int field, double price, TickAttrib attribs)
 {
     try
     {
         TWSSubscription subscription = TWSSubscriptionManager.GetById(tickerId);
         if (subscription != null)
         {
             TWSTickEventArgs args = new TWSTickEventArgs(subscription, field, price, attribs);
             if (m_twsTickEventHandler != null)
             {
                 if (args.DoubleValue >= 0)
                 {
                     m_twsTickEventHandler(this, args);
                 }
                 else
                 {
                     Info(String.Format("Ignoring tick price: {0}", args.ToString()));
                 }
             }
         }
         else
         {
             Info(String.Format("Error - tick received for unknown ticker id {0}", tickerId));
         }
     }
     catch (Exception ex) { Error("Exception in tickPrice callback", ex); }
 }
        public TWSTickEventArgs(TWSSubscription subscription, int field, string value)
            : this(subscription)
        {
            Field       = field;
            StringValue = value;

            SaveDividendData();
        }
        public static TWSSubscription GetByTicker(string ticker)
        {
            TWSSubscription subscription = null;

            lock (s_lockObject)
            {
                s_tickerMap.TryGetValue(ticker, out subscription);
            }
            return(subscription);
        }
        public static TWSSubscription GetById(int requestId)
        {
            TWSSubscription subscription = null;

            lock (s_lockObject)
            {
                s_subscriptionMap.TryGetValue(requestId, out subscription);
            }
            return(subscription);
        }
 public TWSHistoricalDataEventArgs(TWSSubscription subscription, Bar bar)
 {
     Ticker = subscription.Ticker;
     Close  = bar.Close;
     Count  = bar.Count;
     High   = bar.High;
     Low    = bar.Low;
     Open   = bar.Open;
     Time   = bar.Time;
     Volume = bar.Volume;
     WAP    = bar.WAP;
 }
 public void UpdateSubscriptionInfo(TWSSubscription subscription)
 {
     if (subscription != null)
     {
         Ticker       = subscription.Ticker;
         ClientObject = subscription.ClientObject;
     }
     else
     {
         Ticker = "Unknown";
     }
 }
        public static TWSSubscription RemoveSubscription(string ticker)
        {
            TWSSubscription subscription = null;

            lock (s_lockObject)
            {
                subscription = GetByTicker(ticker);
                if (subscription != null)
                {
                    s_tickerMap.Remove(ticker);
                    s_subscriptionMap.Remove(subscription.RequestId);
                }
            }
            return(subscription);
        }
        public static TWSSubscription RemoveSubscription(int requestId)
        {
            TWSSubscription subscription = null;

            lock (s_lockObject)
            {
                subscription = GetById(requestId);
                if (subscription != null)
                {
                    s_subscriptionMap.Remove(subscription.RequestId);
                    if (subscription.SubscriptionType == TWSSubscription.TWSSubscriptionType.TickData)
                    {
                        s_tickerMap.Remove(subscription.Ticker);
                    }
                }
            }
            return(subscription);
        }
Beispiel #10
0
 public void tickString(int tickerId, int field, string value)
 {
     try
     {
         TWSSubscription subscription = TWSSubscriptionManager.GetById(tickerId);
         if (subscription != null)
         {
             TWSTickEventArgs args = new TWSTickEventArgs(subscription, field, value);
             if (m_twsTickEventHandler != null)
             {
                 m_twsTickEventHandler(this, args);
             }
         }
         else
         {
             Info(String.Format("Error - tick received for unknown ticker id {0}", tickerId));
         }
     }
     catch (Exception ex) { Error("Exception in tickString callback", ex); }
 }
        public static TWSSubscription GetOrCreateSubscription(string ticker, QuoteType quoteType, TWSSubscription.TWSSubscriptionType subscriptionType, object clientObject = null, DateTime?date = null)
        {
            TWSSubscription oldSubscription = null;
            TWSSubscription newSubscription = null;

            lock (s_lockObject)
            {
                oldSubscription = GetByTicker(ticker);

                // for tick data, we reuse subscriptions; for other data, we always create a new subscription
                if ((subscriptionType == TWSSubscription.TWSSubscriptionType.TickData) && (oldSubscription != null))
                {
                    newSubscription = oldSubscription;
                }

                else
                {
                    newSubscription = new TWSSubscription(ticker, quoteType, subscriptionType, clientObject, date);

                    // if we already have a contract, we can use it
                    if (oldSubscription != null)
                    {
                        newSubscription.Contract = oldSubscription.Contract;
                    }

                    // subscription map is for all subscriptions
                    s_subscriptionMap.Add(newSubscription.RequestId, newSubscription);

                    // ticker map is for tick data only
                    if (subscriptionType == TWSSubscription.TWSSubscriptionType.TickData)
                    {
                        s_tickerMap.Add(ticker, newSubscription);
                    }
                }
            }

            return(newSubscription);
        }
 public TWSTickEventArgs(TWSSubscription subscription, int field, double impliedVolatility, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice)
     : this(subscription)
 {
     Field     = field;
     HasGreeks = true;
     if (impliedVolatility != Double.MaxValue)
     {
         ImpliedVol = impliedVolatility * 100.0;
     }
     if (delta != Double.MaxValue)
     {
         Delta = delta;
     }
     if (optPrice != Double.MaxValue)
     {
         OptionPrice = optPrice;
     }
     if (pvDividend != Double.MaxValue)
     {
         PresentValueDividend = pvDividend;
     }
     if ((gamma != Double.MaxValue) && (undPrice != Double.MaxValue))
     {
         Gamma = gamma * undPrice / 100.0;
     }
     if (vega != Double.MaxValue)
     {
         Vega = vega;
     }
     if (theta != Double.MaxValue)
     {
         Theta = theta;
     }
     if (undPrice != Double.MaxValue)
     {
         UnderlyingPrice = undPrice;
     }
 }
        public TWSTickEventArgs(TWSSubscription subscription)
        {
            Ticker           = subscription.Ticker;
            RequestId        = subscription.RequestId;
            SubscriptionType = subscription.SubscriptionType;
            ClientObject     = subscription.ClientObject;
            switch (subscription.Status)
            {
            case TWSSubscription.TWSSubscriptionStatus.Rejected:
                SubscriptionStatus = SubscriptionStatus.Rejected;
                break;

            case TWSSubscription.TWSSubscriptionStatus.New:
            case TWSSubscription.TWSSubscriptionStatus.Unsubscribed:
            case TWSSubscription.TWSSubscriptionStatus.AwaitingUnsubscribe:
                SubscriptionStatus = SubscriptionStatus.Unsubscribed;
                break;

            default:
                SubscriptionStatus = SubscriptionStatus.Subscribed;
                break;
            }
        }
Beispiel #14
0
 public void tickOptionComputation(int tickerId, int field, double impliedVolatility, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice)
 {
     try
     {
         // ignore Bid and Ask computations
         if ((field == TickType.MODEL_OPTION) || (field == TickType.DELAYED_MODEL_OPTION))
         {
             TWSSubscription subscription = TWSSubscriptionManager.GetById(tickerId);
             if (subscription != null)
             {
                 TWSTickEventArgs args = new TWSTickEventArgs(subscription, field, impliedVolatility, delta, optPrice, pvDividend, gamma, vega, theta, undPrice);
                 if (m_twsTickEventHandler != null)
                 {
                     m_twsTickEventHandler(this, args);
                 }
             }
             else
             {
                 Info(String.Format("Error - tick received for unknown ticker id {0}", tickerId));
             }
         }
     }
     catch (Exception ex) { Error("Exception in tickOptionComputation callback", ex); }
 }
 public TWSTickEventArgs(TWSSubscription subscription, int field, int size)
     : this(subscription)
 {
     Field    = field;
     IntValue = size;
 }