#pragma warning disable S2699 // Tests should include assertions
        public async Task WebSocketClient_should_receive_Trade_updates()
#pragma warning restore S2699 // Tests should include assertions
        {
            var btcUsdSubscription = new TradeSubscription("Coinbase", "btc", "usd");

            await RunTestForSubscriptionType <Trade>(btcUsdSubscription);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose of all request objects
                if (m_tradeSubscription != null)
                {
                    m_tradeSubscription.OrderAdded         -= tradeSubscription_OrderAdded;
                    m_tradeSubscription.OrderBookDownload  -= tradeSubscription_OrderBookDownload;
                    m_tradeSubscription.OrderDeleted       -= tradeSubscription_OrderDeleted;
                    m_tradeSubscription.OrderFilled        -= tradeSubscription_OrderFilled;
                    m_tradeSubscription.OrderRejected      -= tradeSubscription_OrderRejected;
                    m_tradeSubscription.OrderUpdated       -= tradeSubscription_OrderUpdated;
                    m_tradeSubscription.OrderStatusUnknown -= tradeSubscription_OrderStatusUnknown;

                    m_tradeSubscription.Dispose();
                    m_tradeSubscription = null;
                }

                TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                TTAPI.Shutdown();
            }

            // only run shutdown once
            m_shutdownInProcess = true;
        }
Exemplo n.º 3
0
        }//InitComplete()

        /// <summary>
        /// Called by the Dispose() function.
        /// </summary>
        private void StopThread()
        {
            if (m_Dispatcher != null && (!m_Dispatcher.IsDisposed))
            {
                m_Dispatcher.Dispose();
            }
            if (m_TradeSubsciption != null)
            {
                if (Log != null)
                {
                    Log.NewEntry(LogLevel.Minor, "FillListener: {0} shutting down TradeSubscription.", this);
                }
                m_TradeSubsciption.OrderFilled      -= new EventHandler <TradingTechnologies.TTAPI.OrderFilledEventArgs>(TT_OrderFilled);
                m_TradeSubsciption.Rollover         -= new EventHandler <RolloverEventArgs>(TT_Rollover);
                m_TradeSubsciption.FillRecordAdded  -= new EventHandler <FillAddedEventArgs>(TT_RecordedFill);
                m_TradeSubsciption.AdminFillAdded   -= new EventHandler <FillAddedEventArgs>(TT_AdminFill);
                m_TradeSubsciption.AdminFillDeleted -= new EventHandler <FillDeletedEventArgs>(TT_AdminFillDeleted);

                m_TradeSubsciption.FillBookDownload -= new EventHandler <TradingTechnologies.TTAPI.FillBookDownloadEventArgs>(TT_FillListDownLoad);
                m_TradeSubsciption.FillListStart    -= new EventHandler <TradingTechnologies.TTAPI.FillListEventArgs>(TT_FillListStart);
                m_TradeSubsciption.FillListEnd      -= new EventHandler <TradingTechnologies.TTAPI.FillListEventArgs>(TT_FillListEnd);

                m_TradeSubsciption.Dispose();
                m_TradeSubsciption = null;
            }
        }//StopThread()
Exemplo n.º 4
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.");
        }
Exemplo n.º 5
0
        /// <summary>
        /// Event returning the status of a login attempt.
        /// </summary>
        void m_TTAPI_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e)
        {
            // Check for successful login
            if (!e.Status.IsSuccess)
            {
                // if an unsuccessful login, show the user why and allow them to try again
                MessageBox.Show("Login Unsuccessful.\r\n\r\nReason: " + e.Status.StatusMessage, "Error");
                return;
            }

            // subscribe to the trade subscription events
            m_tradeSubscription                     = new TradeSubscription(m_TTAPI.Session, Dispatcher.Current);
            m_tradeSubscription.OrderAdded         += new EventHandler <OrderAddedEventArgs>(tradeSubscription_OrderAdded);
            m_tradeSubscription.OrderBookDownload  += new EventHandler <OrderBookDownloadEventArgs>(tradeSubscription_OrderBookDownload);
            m_tradeSubscription.OrderDeleted       += new EventHandler <OrderDeletedEventArgs>(tradeSubscription_OrderDeleted);
            m_tradeSubscription.OrderFilled        += new EventHandler <OrderFilledEventArgs>(tradeSubscription_OrderFilled);
            m_tradeSubscription.OrderRejected      += new EventHandler <OrderRejectedEventArgs>(tradeSubscription_OrderRejected);
            m_tradeSubscription.OrderUpdated       += new EventHandler <OrderUpdatedEventArgs>(tradeSubscription_OrderUpdated);
            m_tradeSubscription.OrderStatusUnknown += new EventHandler <OrderStatusUnknownEventArgs>(tradeSubscription_OrderStatusUnknown);
            m_tradeSubscription.Start();

            // Login succeeded, update GUI
            this.btnConnect.Enabled = false;
            UpdateStatusBar("Login Status: " + e.Status.ToString());
        }
Exemplo n.º 6
0
        /// <summary>
        /// Called via my thread dispatcher to create the TradeSubscription object and start it.
        /// After which, the thread will sleep until further dispatcher actions are invoked.
        /// </summary>
        private void InitComplete()
        {
            if (Log != null)
            {
                Log.NewEntry(LogLevel.Major, "{0}: Listener thread started.", this);
            }
            // Subscribe to events.
            m_TradeSubsciption = new TradeSubscription(m_TTService.session, m_Dispatcher);
            if (m_TradeFilter != null)
            {
                m_TradeSubsciption.SetFilter(m_TradeFilter);
            }

            m_TradeSubsciption.OrderFilled      += new EventHandler <TradingTechnologies.TTAPI.OrderFilledEventArgs>(TT_OrderFilled);
            m_TradeSubsciption.Rollover         += new EventHandler <RolloverEventArgs>(TT_Rollover);
            m_TradeSubsciption.FillRecordAdded  += new EventHandler <FillAddedEventArgs>(TT_RecordedFill);
            m_TradeSubsciption.AdminFillAdded   += new EventHandler <FillAddedEventArgs>(TT_AdminFill);
            m_TradeSubsciption.AdminFillDeleted += new EventHandler <FillDeletedEventArgs>(TT_AdminFillDeleted);

            m_TradeSubsciption.FillBookDownload += new EventHandler <TradingTechnologies.TTAPI.FillBookDownloadEventArgs>(TT_FillListDownLoad);
            m_TradeSubsciption.FillListStart    += new EventHandler <TradingTechnologies.TTAPI.FillListEventArgs>(TT_FillListStart);
            m_TradeSubsciption.FillListEnd      += new EventHandler <TradingTechnologies.TTAPI.FillListEventArgs>(TT_FillListEnd);

            m_TradeSubsciption.Start();
        }//InitComplete()
Exemplo n.º 7
0
        /// <summary>
        /// Called via my thread dispatcher to create the TradeSubscription object and start it.
        /// After which, the thread will sleep until further dispatcher actions are invoked.
        /// </summary>
        private void InitComplete()
        {
            this.Log.NewEntry(LogLevel.Major, "{0}: Trade listener started.", m_Name);
            // Subscribe to events.
            m_TradeSubsciption                    = new TradeSubscription(m_TTService.session, m_Dispatcher);
            m_TradeSubsciption.OrderFilled       += new EventHandler <TradingTechnologies.TTAPI.OrderFilledEventArgs>(TT_OrderFilled);
            m_TradeSubsciption.OrderAdded        += new EventHandler <TradingTechnologies.TTAPI.OrderAddedEventArgs>(TT_OrderAdded);
            m_TradeSubsciption.OrderDeleted      += new EventHandler <TradingTechnologies.TTAPI.OrderDeletedEventArgs>(TT_OrderDeleted);
            m_TradeSubsciption.OrderBookDownload += new EventHandler <TradingTechnologies.TTAPI.OrderBookDownloadEventArgs>(TT_OrderBookDownload);
            m_TradeSubsciption.OrderRejected     += new EventHandler <OrderRejectedEventArgs>(TT_OrderRejected);

            m_TradeSubsciption.Start();
        }//InitComplete()
Exemplo n.º 8
0
        /// <summary>
        ///     Обработчик события получения списка счетов
        /// </summary>
        private void AccountResolved(AdapterEventArgs <AccountsReport> args)
        {
            args.MarkHandled();

            // Инициализируем счета
            if (args.Message.brokerage != null)
            {
                using (accountsLock.WriteLock())
                {
                    foreach (
                        var account in
                        from brokerage in args.Message.brokerage
                        from ss in brokerage.sales_series
                        from account in ss.account
                        select account)
                    {
                        Logger.Debug().PrintFormat("Account resolved: {0};{1};{2}", account.brokerage_account_id, account.account_id, account.name);
                        AddAccount(account.name);

                        accountCodesById[account.account_id] = account.name;
                        accountIdsByCode[account.name]       = account.account_id;
                    }
                }

                OnMessageReceived(
                    new InitResponseMessage
                {
                    OrderRouters = new Dictionary <string, string[]>
                    {
                        { ServiceCode, AvailableAccounts.ToArray() }
                    }
                });
            }

            // Подписываемся на счета
            var subscription = new TradeSubscription
            {
                publication_type   = (uint)TradeSubscription.PublicationType.ALL_AUTHORIZED,
                subscription_scope =
                {
                    (uint)TradeSubscription.SubscriptionScope.ORDERS,
                    (uint)TradeSubscription.SubscriptionScope.POSITIONS,
                    (uint)TradeSubscription.SubscriptionScope.COLLATERAL
                },
                subscribe = true,
                id        = adapter.GetNextRequestId()
            };

            adapter.SendMessage(subscription);
        }
Exemplo n.º 9
0
        public ApplicationViewModel()
        {
            InitialiseViewModel();

            LoggedIn = false;

            // This data structure is used to contain all the account info that we can bind to in our view, and will update automatically...
			_accounts = new ObservableCollection<IgPublicApiData.AccountModel>();
            _tradeSubscriptions = new ObservableCollection<IgPublicApiData.TradeSubscriptionModel>();
			_affectedDeals = new ObservableCollection<IgPublicApiData.AffectedDealModel>();

            WireCommands();   
        						
			_accountBalanceSubscription = new AccountBalanceSubscription(this);
			_tradeSubscription = new TradeSubscription(this);                     
        }
Exemplo n.º 10
0
        public ApplicationViewModel()
        {
            InitialiseViewModel();

            LoggedIn = false;

            // This data structure is used to contain all the account info that we can bind to in our view, and will update automatically...
            _accounts           = new ObservableCollection <IgPublicApiData.AccountModel>();
            _tradeSubscriptions = new ObservableCollection <IgPublicApiData.TradeSubscriptionModel>();
            _affectedDeals      = new ObservableCollection <IgPublicApiData.AffectedDealModel>();

            WireCommands();

            _accountBalanceSubscription = new AccountBalanceSubscription(this);
            _tradeSubscription          = new TradeSubscription(this);
        }
        private void Shutdown()
        {
            if (m_ts != null)
            {
                m_ts.OrderBookDownload  -= OnOrderBookDownload;
                m_ts.OrderAdded         -= OnOrderAdded;
                m_ts.OrderDeleted       -= OnOrderDeleted;
                m_ts.OrderFilled        -= OnOrderFilled;
                m_ts.OrderUpdated       -= OnOrderUpdated;
                m_ts.OrderPendingAction -= OnOrderPendingAction;
                m_ts.OrderRejected      -= OnOrderRejected;
                m_ts.Dispose();
                m_ts = null;
            }

            TTAPI.Shutdown();
        }
 private void OnSDKStatusUpdate(object sender, TTAPIStatusUpdateEventArgs e)
 {
     if (e.IsReady && m_ts == null)
     {
         lblStatus.Text           = "Authenticated.  Launching subscriptions...";
         m_ts                     = new TradeSubscription(m_dispatcher, false);
         m_ts.OrderBookDownload  += OnOrderBookDownload;
         m_ts.OrderAdded         += OnOrderAdded;
         m_ts.OrderDeleted       += OnOrderDeleted;
         m_ts.OrderFilled        += OnOrderFilled;
         m_ts.OrderUpdated       += OnOrderUpdated;
         m_ts.OrderPendingAction += OnOrderPendingAction;
         m_ts.OrderRejected      += OnOrderRejected;
         m_ts.Start();
     }
     else if (e.IsDown)
     {
         lblStatus.Text = $"SDK is down: {e.StatusMessage}";
     }
 }
Exemplo n.º 13
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.");
        }
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API 
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose of all request objects
                if (m_tradeSubscription != null)
                {
                    m_tradeSubscription.FillRecordAdded -= m_tradeSubscription_FillRecordAdded;
                    m_tradeSubscription.AdminFillAdded -= m_tradeSubscription_AdminFillAdded;
                    m_tradeSubscription.AdminFillDeleted -= m_tradeSubscription_AdminFillDeleted;
                    m_tradeSubscription.FillBookDownload -= m_tradeSubscription_FillBookDownload;
                    m_tradeSubscription.FillAmended -= m_tradeSubscription_FillAmended;
                    m_tradeSubscription.Dispose();
                    m_tradeSubscription = null;
                }

                TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                TTAPI.Shutdown();
            }

            // only run shutdown once
            m_shutdownInProcess = true;
        }
        void m_TTAPI_ConnectionStatusUpdate(object sender, ConnectionStatusUpdateEventArgs e)
        {
            if (e.Status.IsSuccess)
            {
                this.Enabled = true;

                // Update the Status Bar text.
                UpdateStatusBar("Drag a contract from X_TRADER to begin");

                m_tradeSubscription = new TradeSubscription(m_TTAPI.Session, Dispatcher.Current);
                m_tradeSubscription.FillRecordAdded  += new EventHandler <FillAddedEventArgs>(m_tradeSubscription_FillRecordAdded);
                m_tradeSubscription.AdminFillAdded   += new EventHandler <FillAddedEventArgs>(m_tradeSubscription_AdminFillAdded);
                m_tradeSubscription.AdminFillDeleted += new EventHandler <FillDeletedEventArgs>(m_tradeSubscription_AdminFillDeleted);
                m_tradeSubscription.FillBookDownload += new EventHandler <FillBookDownloadEventArgs>(m_tradeSubscription_FillBookDownload);
                m_tradeSubscription.FillAmended      += new EventHandler <FillAmendedEventArgs>(m_tradeSubscription_FillAmended);

                m_tradeSubscription.Start();
            }
            else
            {
                MessageBox.Show(String.Format("ConnectionStatusUpdate: {0}", e.Status.StatusMessage));
            }
        }
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose of all request objects
                if (m_tradeSubscription != null)
                {
                    m_tradeSubscription.FillRecordAdded  -= m_tradeSubscription_FillRecordAdded;
                    m_tradeSubscription.AdminFillAdded   -= m_tradeSubscription_AdminFillAdded;
                    m_tradeSubscription.AdminFillDeleted -= m_tradeSubscription_AdminFillDeleted;
                    m_tradeSubscription.FillBookDownload -= m_tradeSubscription_FillBookDownload;
                    m_tradeSubscription.FillAmended      -= m_tradeSubscription_FillAmended;
                    m_tradeSubscription.Dispose();
                    m_tradeSubscription = null;
                }

                TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                TTAPI.Shutdown();
            }

            // only run shutdown once
            m_shutdownInProcess = true;
        }
Exemplo n.º 17
0
        private void CreateTradeSubscription()
        {
            Message("Creating TradeSubscription...");

            /*
             * InstrumentLookupSubscription req = new InstrumentLookupSubscription(apiInstance.Session, Dispatcher.Current, new ProductKey(MarketKey.Cme, ProductType.Future, "HG"), "Dec13");
             * req.Update += new EventHandler<InstrumentLookupSubscriptionEventArgs>(req_Update);
             * req.Start();
             * // We now have a more generic method to subscribe to instruments:
             * SubscribeToInstrument(MarketKey.Cme, ProductType.Future, "HG", "Dec13");
             */

            SubscribeToInstrument("CME", "FUTURE", "HG", "Dec12");

            ts = new TradeSubscription(apiInstance.Session, Dispatcher.Current);
            ts.FillBookDownload       += new EventHandler <FillBookDownloadEventArgs>(ts_FillBookDownload);
            ts.FillListEnd            += new EventHandler <FillListEventArgs>(ts_FillListEnd);
            ts.FillListStart          += new EventHandler <FillListEventArgs>(ts_FillListStart);
            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.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.OrderStatusUnknown     += new EventHandler <OrderStatusUnknownEventArgs>(ts_OrderStatusUnknown);
            ts.OrderRejected          += new EventHandler <OrderRejectedEventArgs>(ts_OrderRejected);
            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();

            Message("TradeSubscription created.");
        }
        /// <summary>
        /// Dispose of all the TT API objects and shutdown the TT API 
        /// </summary>
        public void shutdownTTAPI()
        {
            if (!m_shutdownInProcess)
            {
                // Dispose of all request objects
                if (m_tradeSubscription != null)
                {
                    m_tradeSubscription.OrderAdded -= tradeSubscription_OrderAdded;
                    m_tradeSubscription.OrderBookDownload -= tradeSubscription_OrderBookDownload;
                    m_tradeSubscription.OrderDeleted -= tradeSubscription_OrderDeleted;
                    m_tradeSubscription.OrderFilled -= tradeSubscription_OrderFilled;
                    m_tradeSubscription.OrderRejected -= tradeSubscription_OrderRejected;
                    m_tradeSubscription.OrderUpdated -= tradeSubscription_OrderUpdated;
                    m_tradeSubscription.OrderStatusUnknown -= tradeSubscription_OrderStatusUnknown;

                    m_tradeSubscription.Dispose();
                    m_tradeSubscription = null;
                }

                TTAPI.ShutdownCompleted += new EventHandler(TTAPI_ShutdownCompleted);
                TTAPI.Shutdown();
            }

            // only run shutdown once
            m_shutdownInProcess = true;
        }
        void m_TTAPI_ConnectionStatusUpdate(object sender, ConnectionStatusUpdateEventArgs e)
        {
            if (e.Status.IsSuccess)
            {
                this.Enabled = true;

                // Update the Status Bar text.
                UpdateStatusBar("Drag a contract from X_TRADER to begin");

                m_tradeSubscription = new TradeSubscription(m_TTAPI.Session, Dispatcher.Current);
                m_tradeSubscription.FillRecordAdded += new EventHandler<FillAddedEventArgs>(m_tradeSubscription_FillRecordAdded);
                m_tradeSubscription.AdminFillAdded += new EventHandler<FillAddedEventArgs>(m_tradeSubscription_AdminFillAdded);
                m_tradeSubscription.AdminFillDeleted += new EventHandler<FillDeletedEventArgs>(m_tradeSubscription_AdminFillDeleted);
                m_tradeSubscription.FillBookDownload += new EventHandler<FillBookDownloadEventArgs>(m_tradeSubscription_FillBookDownload);
                m_tradeSubscription.FillAmended += new EventHandler<FillAmendedEventArgs>(m_tradeSubscription_FillAmended);

                m_tradeSubscription.Start();
            }
            else
            {
                MessageBox.Show(String.Format("ConnectionStatusUpdate: {0}", e.Status.StatusMessage));
            }
        }
Exemplo n.º 20
0
 /// <summary>
 ///     Отправить сообщение в сокет
 /// </summary>
 public void SendMessage(TradeSubscription msg) => SendMessageImpl(new ClientMsg {
     trade_subscription = { msg }
 });
 private void RegisterLightStreamerSubscriptions()
 {
     _accountBalanceSubscription         = new AccountDetailsTableListerner();
     _accountBalanceSubscription.Update += OnAccountUpdate;
     _tradeSubscription = new TradeSubscription(this);
 }
        public void req_Update(object sender, InstrumentLookupSubscriptionEventArgs e)
        {
            if (e.Instrument != null && e.Error == null)
            {
                // Create a TradeSubscription with an Instrument filter
                ts = new TradeSubscription(apiInstance.Session, Dispatcher.Current);

                TradeSubscriptionInstrumentFilter tsIF =
                       new TradeSubscriptionInstrumentFilter(apiInstance.Session, e.Instrument.Key, false, "instr");

                ts.SetFilter(tsIF);
                ts.OrderAdded += new EventHandler<OrderAddedEventArgs>(ts_OrderAdded);
                ts.OrderFilled += new EventHandler<OrderFilledEventArgs>(ts_OrderFilled);
                ts.OrderRejected += new EventHandler<OrderRejectedEventArgs>(ts_OrderRejected);
                ts.OrderDeleted += new EventHandler<OrderDeletedEventArgs>(ts_OrderDeleted);
                ts.OrderUpdated += new EventHandler<OrderUpdatedEventArgs>(ts_OrderUpdated);
                ts.Start();

                // Subscribe for Inside Market Data
                ps = new PriceSubscription(e.Instrument, Dispatcher.Current);
                ps.Settings = new PriceSubscriptionSettings(PriceSubscriptionType.InsideMarket);
                ps.FieldsUpdated += new FieldsUpdatedEventHandler(priceSub_FieldsUpdated);
                ps.Start();
            }
            else if (e.IsFinal)
            {
                // Instrument was not found and TT API has given up looking for it
                Console.WriteLine("Cannot find instrument: " + e.Error.Message);
                Dispose();
            }
        }
        /// <summary>
        /// Event returning the status of a login attempt.
        /// </summary>
        void m_TTAPI_AuthenticationStatusUpdate(object sender, AuthenticationStatusUpdateEventArgs e)
        {
            // Check for successful login
            if (!e.Status.IsSuccess)
            {
                // if an unsuccessful login, show the user why and allow them to try again
                MessageBox.Show("Login Unsuccessful.\r\n\r\nReason: " + e.Status.StatusMessage, "Error");
                return;
            }

            // subscribe to the trade subscription events
            m_TradeSubscription = new TradeSubscription(m_TTAPI.Session, Dispatcher.Current);
            m_TradeSubscription.OrderAdded += new EventHandler<OrderAddedEventArgs>(tradeSubscription_OrderAdded);
            m_TradeSubscription.OrderBookDownload += new EventHandler<OrderBookDownloadEventArgs>(tradeSubscription_OrderBookDownload);
            m_TradeSubscription.OrderDeleted += new EventHandler<OrderDeletedEventArgs>(tradeSubscription_OrderDeleted);
            m_TradeSubscription.OrderFilled += new EventHandler<OrderFilledEventArgs>(tradeSubscription_OrderFilled);
            m_TradeSubscription.OrderRejected += new EventHandler<OrderRejectedEventArgs>(tradeSubscription_OrderRejected);
            m_TradeSubscription.OrderUpdated += new EventHandler<OrderUpdatedEventArgs>(tradeSubscription_OrderUpdated);
            m_TradeSubscription.OrderStatusUnknown += new EventHandler<OrderStatusUnknownEventArgs>(tradeSubscription_OrderStatusUnknown);
            m_TradeSubscription.Start();

            // Login succeeded, update GUI
            this.btnConnect.Enabled = false;
            UpdateStatusBar("Login Status: " + e.Status.ToString());
        }
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {

                    // Shutdown all subscriptions
                    if (req != null)
                    {
                        req.Dispose();
                        req = null;
                    }
                    if (ps != null)
                    {
                        ps.Dispose();
                        ps = null;
                    }
                    if (ts != null)
                    {
                        ts.Dispose();
                        ts = null;
                    }

                    // Shutdown the Dispatcher
                    if (disp != null)
                    {
                        disp.BeginInvokeShutdown();
                        disp = null;
                    }

                    // Shutdown the TT API
                    if (apiInstance != null)
                    {
                        apiInstance.Shutdown();
                        apiInstance = null;
                    }
                }
            }

            disposed = true;
        }