Ejemplo n.º 1
0
        private bool TryStart()
        {
            var waitEvent    = new ManualResetEvent(false);
            var waitDelegate = new Action <StateChange>((state) =>
            {
                if (state.NewState == ConnectionState.Connected ||
                    (state.NewState == ConnectionState.Disconnected &&
                     state.OldState == ConnectionState.Connecting))
                {
                    waitEvent.Set();
                }
            });

            connection.StateChanged += waitDelegate;
            connection.Start();

            waitEvent.WaitOne();
            connection.StateChanged -= waitDelegate;

            if (connection.State == ConnectionState.Connected)
            {
                proxy.Invoke("SubscribeToSummaryDeltas");
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        private bool TryStart()
        {
            var waitEvent    = new ManualResetEvent(false);
            var waitDelegate = new Action <StateChange>((state) =>
            {
                if (state.NewState == ConnectionState.Connected ||
                    (state.NewState == ConnectionState.Disconnected &&
                     state.OldState == ConnectionState.Connecting))
                {
                    waitEvent.Set();
                }
            });

            connection.StateChanged += waitDelegate;
            try
            {
                connection.Start().Wait();
            }
            catch (Exception ex)
            {
                log.Write(LogVerbosity.Debug, ex.ToString());
            }
            waitEvent.WaitOne();
            connection.StateChanged -= waitDelegate;

            if (connection.State == ConnectionState.Connected)
            {
                // subscribe to all market deltas
                proxy.Invoke("SubscribeToSummaryDeltas");

                // TODO: re-add all other subscriptions (if there are any)
                IEnumerable <BittrexExchangeDeltasRegistration> marketRegistrations;
                marketRegistrations = registrations.OfType <BittrexExchangeDeltasRegistration>();
                foreach (var registration in marketRegistrations)
                {
                    SubscribeToExchangeDeltas(registration.MarketName);
                }

                return(true);
            }
            return(false);
        }
Ejemplo n.º 3
0
        private bool TryStart()
        {
            var waitEvent    = new ManualResetEvent(false);
            var waitDelegate = new Action <StateChange>((state) =>
            {
                if (state.NewState == ConnectionState.Connected ||
                    (state.NewState == ConnectionState.Disconnected &&
                     state.OldState == ConnectionState.Connecting))
                {
                    waitEvent.Set();
                }
            });

            connection.StateChanged += waitDelegate;
            connection.Start();

            waitEvent.WaitOne();
            connection.StateChanged -= waitDelegate;
            return(connection.State == ConnectionState.Connected);
        }