Ejemplo n.º 1
0
        /// <summary>
        /// This is called asynchronously by the TTService worker thread.  It then creates and
        /// attaches a Dispatcher for itself, and calls the InitAPI() method.  This creates a
        /// queue for the TTService worker thread, which keeps it alive after processing requests.
        /// </summary>
        private void StartInitAPI()
        {
            if (m_Dispatcher == null)
            {
                m_Dispatcher = Dispatcher.AttachWorkerDispatcher();
            }
            m_Dispatcher.BeginInvoke(new Action(InitAPI));
            try
            {                       // this is a blocking statement, the thread will return here whenever a call is returned.
                m_Dispatcher.Run(); // This keeps the thread alive at the end of a return.
            }
            catch (Exception e)
            {
                if (m_Log != null)
                {
                    m_Log.NewEntry(LogLevel.Error, "StartInitAPI: Error. Failed to start TT API. {0}", e.Message);
                }
                if (m_AlertManager != null)
                {
                    m_AlertManager.RequestEmailAlert(AlertLevel.High, "StartInitAPI: Error. Failed to start TT API. {0}", e.Message);
                }

                Thread.Sleep(2000);             // worker should sleep, then try to restart.
                StartInitAPI();                 // try again.
            }
        }// StartInitAPI().
Ejemplo n.º 2
0
 /// <summary>
 /// Create and start the Dispatcher
 /// </summary>
 public void Start()
 {
     // Attach a WorkerDispatcher to the current thread
     m_disp = Dispatcher.AttachWorkerDispatcher();
     m_disp.BeginInvoke(new Action(Init));
     m_disp.Run();
 }
 /// <summary>
 /// Create and start the Dispatcher
 /// </summary>
 public void Start()
 {
     // Attach a WorkerDispatcher to the current thread
     m_disp = Dispatcher.AttachWorkerDispatcher();
     m_disp.BeginInvoke(new Action(Init));
     m_disp.Run();
 }
Ejemplo n.º 4
0
        public void SubscribeToInstrument(InstrumentDescriptor descriptor)
        {
            if (_dispatcher.InvokeRequired())
            {
                _dispatcher.BeginInvoke(() =>
                {
                    SubscribeToInstrument(descriptor);
                });
                return;
            }

            InstrumentLookupSubscription req = new InstrumentLookupSubscription(_apiSession, Dispatcher.Current, descriptor.ProductKey, descriptor.ContractName);

            req.Update += new EventHandler <InstrumentLookupSubscriptionEventArgs>(instrumentLookupRequest_Update);
            req.Start();
        }
Ejemplo n.º 5
0
        public void CreateOrderSubscription()
        {
            if (_dispatcher.InvokeRequired())
            {
                _dispatcher.BeginInvoke(() =>
                {
                    CreateOrderSubscription();
                });
                return;
            }

            Dispatcher dispatcher = Dispatcher.Current;

            Console.WriteLine("Creating Order Subscription...");

            _ts = new TradeSubscription(_apiSession, dispatcher);
            _ts.OrderBookDownload  += new EventHandler <OrderBookDownloadEventArgs>(ts_OrderBookDownload);
            _ts.OrderAdded         += new EventHandler <OrderAddedEventArgs>(ts_OrderAdded);
            _ts.OrderUpdated       += new EventHandler <OrderUpdatedEventArgs>(ts_OrderUpdated);
            _ts.OrderDeleted       += new EventHandler <OrderDeletedEventArgs>(ts_OrderDeleted);
            _ts.OrderFilled        += new EventHandler <OrderFilledEventArgs>(ts_OrderFilled);
            _ts.OrderStatusUnknown += new EventHandler <OrderStatusUnknownEventArgs>(ts_OrderStatusUnknown);
            _ts.OrderRejected      += new EventHandler <OrderRejectedEventArgs>(ts_OrderRejected);
            //ts.EnablePNL = true;
            //ts.ProfitLossChanged += new EventHandler<ProfitLossChangedEventArgs>(ts_ProfitLossChanged);
            _ts.Start();

            Console.WriteLine("Order Subscription created.");
        }
Ejemplo n.º 6
0
        }//Dispose()

        //
        //
        #endregion//Public Methods


        #region Private Startup and Shutdown Methods
        // *****************************************************************
        // ****                     Private Methods                     ****
        // *****************************************************************
        /// <summary>
        /// Called from constructor to capture the PriceListener thread.  He is captured once
        /// he creates a Dispatcher and calls an invoke on himself.
        /// </summary>
        private void InitializeThread()
        {
            m_Dispatcher = TradingTechnologies.TTAPI.Dispatcher.AttachWorkerDispatcher();
            m_Dispatcher.BeginInvoke(new Action(InitComplete));

            m_Dispatcher.Run();                                                 // this tells thread to do this and wait.
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Create and start the Dispatcher
 /// </summary>
 public void Start()
 {
     cout("TengineTT::Start: Attaching dispatcher...");
     // Attach a WorkerDispatcher to the current thread
     m_disp = Dispatcher.AttachWorkerDispatcher();
     m_disp.BeginInvoke(new Action(Init));
     m_disp.Run();
 }
Ejemplo n.º 8
0
 public void SuscribeToInstrumentPrice(string ttInstrumentId, string instruType, string productName, string market, string priceType)
 {
     if (!_instrumentToSubscribe.ContainsKey(ttInstrumentId))
     {
         var newInstruSub = new InstruSubscription(priceType, instruType, productName, market, ttInstrumentId);
         _instrumentToSubscribe.Add(ttInstrumentId, newInstruSub);
         _instruQueue.Enqueue(newInstruSub);
         _disp.BeginInvoke(UpdateInstrumentSubscription);
         _disp.Run();
     }
 }
        /// <summary>
        /// Create and start the Dispatcher
        /// </summary>
        public void Start(TradingFrameworkUtility tfu)
        {
            util     = tfu;
            username = Properties.Settings.Default.USER;
            password = Properties.Settings.Default.PASSWORD;

            util.dbug_write("user is: {0}", username);
            // Attach a WorkerDispatcher to the current thread
            workDispatch = Dispatcher.AttachWorkerDispatcher();
            workDispatch.BeginInvoke(new Action(Init));
            workDispatch.Run();
        }
Ejemplo n.º 10
0
        }// Start()

        //
        //
        //
        public void Dispose()
        {
            if (m_isDisposing)
            {
                return;
            }
            m_isDisposing = true;

            m_Dispatcher.BeginInvoke(new Action(StopThread));
            m_Dispatcher.Run();

            m_TradeSubsciption.Dispose();
        }//Dispose()
Ejemplo n.º 11
0
        //
        // ****             Dispose()               ****
        /// <summary>
        /// Called by an external thread, invoke the StopThread method.
        /// </summary>
        public void Dispose()
        {
            if (m_isDisposing)
            {
                return;
            }
            m_isDisposing = true;

            try
            {
                m_Dispatcher.BeginInvoke(new Action(StopThread));
            }
            catch (Exception)
            {
            }
        }//Dispose()
Ejemplo n.º 12
0
        public void CreateMarketSubscription()
        {
            if (_dispatcher.InvokeRequired())
            {
                _dispatcher.BeginInvoke(() =>
                {
                    CreateMarketSubscription();
                });
                return;
            }

            Dispatcher dispatcher = Dispatcher.Current;

            Console.WriteLine("Creating MarketSubscription...");

            // Find each market and subscribe to products for that market
            foreach (MarketKey key in _apiSession.MarketCatalog.Markets.Keys)
            {
                Market market = _apiSession.MarketCatalog.Markets[key];
                currentMarkets.Add(key, market);
                ProductCatalogSubscription pcs = market.CreateProductCatalogSubscription(Dispatcher.Current);
                pcs.ProductsUpdated += new EventHandler <ProductCatalogUpdatedEventArgs>(pcs_ProductsUpdated);
                pcs.Start();
            }

            // Find all the fill feeds, order feeds, price feeds and localAutospreader order feed
            foreach (FillFeed feed in _apiSession.MarketCatalog.FillFeeds)
            {
                currentFillFeeds.Add(feed);
            }
            localAutospreaderOrderFeed = _apiSession.MarketCatalog.LocalAutospreaderEngineOrderFeed;
            foreach (OrderFeed feed in _apiSession.MarketCatalog.OrderFeeds)
            {
                currentOrderFeeds.Add(feed);
            }
            foreach (PriceFeed feed in _apiSession.MarketCatalog.PriceFeeds)
            {
                currentPriceFeeds.Add(feed);
            }

            // Subscribe to some events related to markets
            _apiSession.MarketCatalog.FeedStatusChanged     += new EventHandler <FeedStatusChangedEventArgs>(MarketCatalog_FeedStatusChanged);
            _apiSession.MarketCatalog.MarketsUpdated        += new EventHandler <MarketCatalogUpdatedEventArgs>(MarketCatalog_MarketsUpdated);
            _apiSession.MarketCatalog.TradingEnabledChanged += new EventHandler <TradingEnabledChangedEventArgs>(MarketCatalog_TradingEnabledChanged);

            Console.WriteLine("MarketSubscription created.");
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Create and start the Dispatcher
        /// </summary>
        public void Initialize()
        {
            if (CheckArchitecture())
            {
                // Attach a WorkerDispatcher to the current thread
                _disp = Dispatcher.AttachWorkerDispatcher();
                _disp.BeginInvoke(Init);
                _disp.Run();

                var delay = DateTime.Now.AddSeconds(30);

                while (DateTime.Now.CompareTo(delay) > 0)
                {
                    Dispose();
                }
            }
        }
Ejemplo n.º 14
0
        public void CreateFillSubscription()
        {
            if (_dispatcher.InvokeRequired())
            {
                _dispatcher.BeginInvoke(() =>
                {
                    CreateFillSubscription();
                });
                return;
            }

            Dispatcher dispatcher = Dispatcher.Current;

            Console.WriteLine("Creating Fill Subscription...");

            _fs = new FillsSubscription(_apiSession, dispatcher);
            _fs.FillListStart    += new EventHandler <FillListEventArgs>(fs_FillListStart);
            _fs.FillBookDownload += new EventHandler <FillBookDownloadEventArgs>(fs_FillBookDownload);
            _fs.FillListEnd      += new EventHandler <FillListEventArgs>(fs_FillListEnd);
            _fs.FillAdded        += new EventHandler <FillAddedEventArgs>(fs_FillAdded);
            _fs.FillDeleted      += new EventHandler <FillDeletedEventArgs>(fs_FillDeleted);
            _fs.FillAmended      += new EventHandler <FillAmendedEventArgs>(fs_FillAmended);
            _fs.Start();

            _ts = new TradeSubscription(_apiSession, dispatcher);
            _ts.FillBookDownload       += new EventHandler <FillBookDownloadEventArgs>(ts_FillBookDownload);
            _ts.FillListEnd            += new EventHandler <FillListEventArgs>(ts_FillListEnd);
            _ts.FillListStart          += new EventHandler <FillListEventArgs>(ts_FillListStart);
            _ts.FillAmended            += new EventHandler <FillAmendedEventArgs>(ts_FillAmended);
            _ts.FillRecordAdded        += new EventHandler <FillAddedEventArgs>(ts_FillRecordAdded);
            _ts.AdminFillAdded         += new EventHandler <FillAddedEventArgs>(ts_AdminFillAdded);
            _ts.AdminFillDeleted       += new EventHandler <FillDeletedEventArgs>(ts_AdminFillDeleted);
            _ts.Rollover               += new EventHandler <RolloverEventArgs>(ts_Rollover);
            _ts.TradeSubscriptionReset += new EventHandler <TradeSubscriptionResetEventArgs>(ts_TradeSubscriptionReset);
            //ts.EnablePNL = true;
            //ts.ProfitLossChanged += new EventHandler<ProfitLossChangedEventArgs>(ts_ProfitLossChanged);
            _ts.Start();

            Console.WriteLine("Fill Subscription created.");
        }