Example #1
0
        private void InitPusher()
        {
            Logger.With("Subscribe", "private-bozp-" + _apiOtion.ObjectID)
            .Debug(PusherServiceEvents.InitPusher);

            _channel = _pusher.Subscribe("private-bozp-" + _apiOtion.ObjectID);
            _pusher.Connect();

            _pusher.ConnectionStateChanged += PusherConnectionStateChanged;
            _pusher.Error += PusherError;
            PusherBinding();
        }
Example #2
0
 public PusherSocket()
 {
     pusher = new Pusher("c0eef4118084f8164bec65e6253bf195", Consts.Pusher.Options);
     pusher.ConnectionStateChanged += ConnectionStateChanged;
     pusher.Connected += Connected;
     pusher.Connect();
 }
        private static void InitPusher()
        {
            _pusher = new Pusher("7899dd5cb232af88083d", new PusherOptions()
            {
                Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
            });
            _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            _pusher.Error += _pusher_Error;

            // Setup private channel
            _chatChannel             = _pusher.Subscribe("private-channel");
            _chatChannel.Subscribed += _chatChannel_Subscribed;

            // Inline binding!
            _chatChannel.Bind("client-my-event", (dynamic data) =>
            {
                Console.WriteLine("[" + data.name + "] " + data.message);
            });

            // Setup presence channel
            _presenceChannel                = (PresenceChannel)_pusher.Subscribe("presence-channel");
            _presenceChannel.Subscribed    += _presenceChannel_Subscribed;
            _presenceChannel.MemberAdded   += _presenceChannel_MemberAdded;
            _presenceChannel.MemberRemoved += _presenceChannel_MemberRemoved;

            _pusher.Connect();
        }
        public DisposablePusher(string pusherKey, ILog log)
        {
            _log    = log;
            _client = new Pusher(pusherKey);

            _log.WriteInfo(nameof(DisposablePusher), "", $"Connecting to application {pusherKey}...");
            _client.Connect();
            _log.WriteInfo(nameof(DisposablePusher), "", "Connected");
        }
Example #5
0
 public KunaSocketClient(KunaSocketClientOptions options) : base("KunaSocketClient", options)
 {
     _pusherClient = new Pusher("4b6a8b2c758be4e58868", new PusherOptions()
     {
         Encrypted = true, Endpoint = "pusher.kuna.io", ProtocolNumber = 7, Version = "3.0.0"
     });
     _pusherClient.Connect();
     _pusherClient.Error += _pusherClient_Error;
     _pusherClient.ConnectionStateChanged += _pusherClient_ConnectionStateChanged;
 }
Example #6
0
 private static void InitPusher()
 {
     _pusher = new Pusher("7899dd5cb232af88083d", new PusherOptions()
     {
         Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
     });
     _pusher.Connected += pusher_Connected;
     _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
     _pusher.Connect();
 }
Example #7
0
 private static void InitPusher()
 {
     _pusher = new Pusher("527784eba833ff169524", new PusherOptions()
     {
         Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
     });
     _pusher.Connected += pusher_Connected;
     _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
     _pusher.Connect();
 }
Example #8
0
 public ConsentReceiver()
 {
     pusher = new Pusher("3d986af38ba72547d258", new PusherOptions()
     {
         Cluster = "eu"
     });
     pusher.ConnectionStateChanged += pusher_ConnectionStateChanged;
     pusher.Error += pusher_Error;
     pusher.Connect();
 }
 public LiquidQuoineSocketClient(LiquidQuoineSocketClientOptions options) : base(options, null)
 {
     _currentUserId = options.UserId;
     Configure(options);
     log.Level     = LogVerbosity.Debug;
     _pusherClient = new Pusher(options.PushherAppId, new PusherOptions()
     {
         ProtocolNumber = 7, Version = "4.4.0"
     });
     _pusherClient.Connect();
 }
Example #10
0
        public WebsocketService(IExchangeMarketData exchangeMarketData, IEventBus eventBus)
        {
            //Injection
            _exchangeMarketData = exchangeMarketData ?? throw new ArgumentNullException(nameof(exchangeMarketData));
            _eventBus           = eventBus ?? throw new ArgumentNullException(nameof(eventBus));

            //Set delegates
            _updateAndDecodeExchangeState = CreateDecodeCallback(_exchangeMarketData);
            _updateExchangeState          = CreateCallback(_exchangeMarketData, _eventBus);



            //Bittrex
            _hubConnection = new HubConnection("https://socket.bittrex.com/signalr");
            _hubProxy      = _hubConnection.CreateHubProxy("c2");
            _hubConnection.Start().Wait();


            //Binance
            _binanceHubConnection = new BinanceSocketClient();


            //Bitstamp
            _bitstampHubConnection = new Pusher("de504dc5763aeef9ff52");
            _bitstampHubConnection.Connect();


            //Poloniex
            _poloniexHubConnection = new PoloniexChannel();
            _poloniexHubConnection.ConnectAsync().Wait();


            //Kucoin
            using (var client = new HttpClient())
            {
                var tokenAcquireUri = "https://kitchen.kucoin.com/v1/bullet/usercenter/loginUser?protocol=websocket&encrypt=true";
                using (HttpResponseMessage res = client.GetAsync(tokenAcquireUri).Result)
                {
                    using (HttpContent content = res.Content)
                    {
                        var jRes = JObject.Parse(
                            content.ReadAsStringAsync().Result
                            );
                        var bulletToken = jRes["data"]["bulletToken"].ToString();

                        _kucoinHubConnection = new WebSocket(
                            "wss://push1.kucoin.com/endpoint?bulletToken=" + bulletToken + "&format=json&resource=api");

                        _kucoinHubConnection.Connect();
                        var success = _kucoinHubConnection.Ping();
                    }
                }
            }
        }
Example #11
0
 private void _pusher_Error(object sender, PusherException error)
 {
     try
     {
         _pusher.Disconnect();
         Thread.Sleep(1000);
         _pusher.Connect();
     }
     catch
     { }
 }
Example #12
0
        public PusherHelper(string tradingpair, CommonLab.TradePair tp, string appkey = "de504dc5763aeef9ff52")
        {
            _tradingpair = tradingpair;

            _tradinginfo = new TradingInfo(SubscribeTypes.WSS, tradingpair, tp);
            Tp           = tp;
            _appkey      = appkey;
            _pusher      = new Pusher(_appkey);
            _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            _pusher.Error += _pusher_Error;
            _pusher.Connect();
        }
Example #13
0
        static Pusher InitializeResourcePusher()
        {
            var options = new PusherOptions
            {
                Encrypted = true,
                Cluster   = "eu"
            };

            Pusher = new Pusher("3e81de0297856b72df54", options);
            Pusher.Connect();
            return(Pusher);
        }
Example #14
0
 /// <summary>
 /// Inicializar gestor
 /// </summary>
 public CloudChannelManager()
 {
     m_channels = new Dictionary <string, IChannel>();
     _pusher    = new Pusher(PUSHER_APP_KEY, new PusherOptions
     {
         Authorizer = new PusherServerAuthorizer(Domotic.Cloud.CurrentDomain + "/pusher/authServer"),
         Cluster    = "us2",
         Encrypted  = true
     });
     _pusher.Connected += Pusher_Connected;
     _pusher.Error     += Pusher_Error;
     _pusher.ConnectionStateChanged += Pusher_ConnectionStateChanged;
     _pusher.Connect();
 }
Example #15
0
 public LiquidQuoineSocketClient(LiquidQuoineSocketClientOptions options) : base(options, null)
 {
     _currentUserId = options.UserId;
     // Configure(options);
     log.Level     = LogVerbosity.Debug;
     _pusherClient = new Pusher(options.PushherAppId, new PusherOptions()
     {
         ProtocolNumber = 7,
         Version        = "4.4.0",
         Endpoint       = options.BaseAddress
     });
     _pusherClient.Connect();
     _pusherClient.Error     += OnError;
     _pusherClient.Connected += OnConnected;
 }
        public PusherController(string request, OperationDelegate update)
        {
            _pusher = new Pusher(Utils.PusherKey, new PusherOptions
            {
                Cluster = "eu"
            });
            _pusher.Error += _pusher_Error;

            // Setup private channel
            var channel = _pusher.Subscribe("store");

            // Inline binding!
            channel.Bind(request, data => { update(data); });

            _pusher.Connect();
        }
        /// <summary>
        /// Initializes platform
        /// </summary>
        public void InitializePlatform()
        {
            _platformInfo = GetPlatformInfo();

            PusherSettings.Verbose = false;
            _options = new PusherOptions
            {
                Cluster   = _platformInfo.notifications.pusher.options.cluster,
                Encrypted = _platformInfo.notifications.pusher.options.encrypted == "true"
            };

            _client            = new Pusher(_platformInfo.notifications.pusher.key, _options);
            _client.Connected += EventConnected;
            _client.ConnectionStateChanged += EventStateChange;
            _client.Connect();
        }
Example #18
0
        /// <summary>
        /// Connect to jobs server
        /// </summary>
        /// <param name="listeners"></param>
        /// <param name="onError"></param>
        /// <param name="onStateChanged"></param>
        public static void connect(
            List <Listener> listeners,
            Action <PusherException> onError,
            Action <String> onStateChanged
            )
        {
            if (isConnecting)
            {
                return;
            }
            isConnecting = true;
            // Disconnect pusher, if it already connected
            //log.Info("Pusher connect 0");
            if (pusher != null)
            {
                Console.WriteLine("Pusher connect disconnect()");
                disconnect();
            }

            //log.Info("Pusher connect 1");
            JobsServer.listeners      = listeners;
            JobsServer.onError        = onError;
            JobsServer.onStateChanged = onStateChanged;

            // Create new pusher instance
            pusher = new Pusher(Credentials.SrvXT, new PusherOptions());
            // Set pusher connection changed event handler
            pusher.ConnectionStateChanged += onStateChanged_handler;
            // Set error event handler
            pusher.Error += onError_handler;

            //log.Info("Pusher connect 3");
            // Subscribe listeners to they channels
            Channel c;

            foreach (Listener l in listeners)
            {
                //log.Info("    Pusher connect 3.1");
                c = pusher.Subscribe(l.channel);
                c.Bind(l.evt, l.onMessage);
                channels.Add(c);
            }

            //log.Info("Pusher connect 4");
            // Connect to pusher
            pusher.Connect();
        }
Example #19
0
        public BitstampService()
        {
            _pusher = new Pusher("de504dc5763aeef9ff52");
            _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            _pusher.Error += _pusher_Error;

            // Setup private channel
            _chatChannel             = _pusher.Subscribe("live_orders");
            _chatChannel.Subscribed += _chatChannel_Subscribed;

            // Inline binding!
            _chatChannel.BindAll((string ch, dynamic data) =>
            {
                try
                {
                    Console.WriteLine(data["price"]);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine(data);
            });



            _pusher.Connect();

            string line;

            do
            {
                line = Console.ReadLine();

                if (line == "quit")
                {
                    break;
                }
                //else
                //    _chatChannel.Trigger("client-my-event", new { message = line, name = _name });
            } while (line != null);

            _pusher.Disconnect();
        }
        public LiquidQuoineSocketClient(LiquidQuoineSocketClientOptions options) : base(nameof(LiquidQuoineSocketClient), options, null)
        {
            authProvider = options.authenticationProvider;

            // Configure(options);
            log.Level     = LogVerbosity.Debug;
            _pusherClient = new Pusher(options.PushherAppId, new PusherOptions()
            {
                ProtocolNumber = 7,
                Version        = "4.4.0",
                Endpoint       = "tap.liquid.com",
                Encrypted      = true,
                Client         = "",
            });
            _pusherClient.ConnectionStateChanged += _pusherClient_ConnectionStateChanged;
            _pusherClient.Connected += _pusherClient_Connected;
            _pusherClient.Connect();
        }
Example #21
0
        /// <summary>
        /// connect to exchange
        /// установить соединение с биржей
        /// </summary>
        public void Connect()
        {
            if (string.IsNullOrWhiteSpace(_apiKeyPublic) ||
                string.IsNullOrWhiteSpace(_apiKeySecret) ||
                string.IsNullOrWhiteSpace(_clientId))
            {
                return;
            }
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            // check server availability for HTTP communication with it / проверяем доступность сервера для HTTP общения с ним
            Uri uri = new Uri("https://www.bitstamp.net");

            try
            {
                HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            }
            catch
            {
                LogMessageEvent("Сервер не доступен. Отсутствуюет интернет. ", LogMessageType.Error);
                return;
            }

            IsConnected = true;

            if (Connected != null)
            {
                Connected();
            }

            // start stream data through WebSocket / запускаем потоковые данные через WebSocket

            if (_pusher != null)
            {
                _pusher.UnbindAll();
                _pusher.Disconnect();
            }

            _pusher = new Pusher("de504dc5763aeef9ff52");
            _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            _pusher.Error += _pusher_Error;
            _pusher.Connect();
        }
Example #22
0
        protected override void StartImpl()
        {
            pusher = new Pusher(config.ApplicationKey, log);

            pusher.Connected += x =>
            {
                OnConnected();
                var channel = pusher.Subscribe("live_trades"); // for BTC/USD

                channel.Bind("trade", o => System.Console.WriteLine(o));
            };

            pusher.Error += (o, e) => OnStopped();

            pusher.Connect();


            // TODO
        }
Example #23
0
        /// <summary>
        /// Connects to Pusher and subscribes to the user's private channel.
        /// </summary>
        /// <param name="user"></param>
        private void SetupPusher(VpdbUserFull user)
        {
            // initialize pusher
            if (_pusher == null && user.ChannelConfig != null)
            {
                _pusher = new Pusher(user.ChannelConfig.ApiKey, new PusherOptions()
                {
                    Encrypted  = true,
                    Authorizer = new PusherAuthorizer(this, _crashManager, _logger)
                });
            }

            var isNewConnection       = _connectedApiEndpoint == null;
            var isSameConnection      = !isNewConnection && _connectedApiEndpoint.Equals(_settingsManager.Settings.Endpoint);
            var isDifferentConnection = !isNewConnection && !isSameConnection;

            if (isNewConnection && _pusher != null)
            {
                _logger.Info("Setting up Pusher...");

                _pusher.ConnectionStateChanged += PusherConnectionStateChanged;
                _pusher.Error += PusherError;

                _pusher.Connect();
            }

            if (isDifferentConnection)
            {
                _logger.Info("Unsubscribing from previous channel.");
                _userChannel.Unsubscribe();
            }

            if (_pusher != null && (isNewConnection || isDifferentConnection))
            {
                _logger.Info("Subscribing to user channel...");
                _userChannel             = _pusher.Subscribe("private-user-" + user.Id);
                _userChannel.Subscribed += PusherSubscribed;
            }

            _connectedApiEndpoint = _settingsManager.Settings.Endpoint;
        }
Example #24
0
        private async Task StartPusher()
        {
            if (_pusher != null)
            {
                return;
            }

            await Task.Factory.StartNew(() =>
            {
                _loggingService.WriteInformation($"Starting Pusher");

                _pusher        = new Pusher(_pusherApplicationKey);
                _pusher.Error += _pusher_Error;
                _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
                _pusher.Subscribe(_channel)
                .Bind("print-job", _pusher_ReadResponse);

                _pusher.Connect();

                _loggingService.WriteInformation($"Pusher is started");
            });
        }
Example #25
0
        public async Task <bool> ConnectAsync(string applicationkey = "de504dc5763aeef9ff52")
        {
            var tcs = new TaskCompletionSource <bool>();

            _pusher = new Pusher(applicationkey);

            var connected = (ConnectedEventHandler)null;
            var orders    = (SubscriptionEventHandler)null;
            var trades    = (SubscriptionEventHandler)null;

            orders = (sender) => {
                _orders.Subscribed -= orders;
                _orders.Bind("order_deleted", (d) => On(OrderDeleted, (d as JObject).AsOrder()));
                _orders.Bind("order_created", (d) => On(OrderCreated, (d as JObject).AsOrder()));
                _orders.Bind("order_changed", (d) => On(OrderChanged, (d as JObject).AsOrder()));
            };

            trades = (sender) => {
                _trades.Subscribed -= trades;
                _trades.Bind("trade", (d) => On(TradeOccured, (d as JObject).AsTrade()));
            };

            _pusher.Connected += connected = (sender) => {
                _pusher.Connected -= connected;

                _trades             = _pusher.Subscribe("live_trades");
                _trades.Subscribed += trades;

                _orders             = _pusher.Subscribe("live_orders");
                _orders.Subscribed += orders;
            };

            _pusher.ConnectionStateChanged += (s, e) => {
            };

            _pusher.Connect();

            return(await tcs.Task);
        }
Example #26
0
        public void PusherShouldNotSuccessfulyConnectWhenGivenAnInvalidAppKey()
        {
            // Arrange
            AutoResetEvent reset     = new AutoResetEvent(false);
            bool           connected = false;

            var pusher = new Pusher("Invalid");

            pusher.Connected += sender =>
            {
                connected = true;
                reset.Set();
            };

            // Act
            var connectionResult = pusher.Connect();

            reset.WaitOne(TimeSpan.FromSeconds(5));

            // Assert
            Assert.IsFalse(connected);
        }
Example #27
0
        private Task <bool> ConnectAsync(string applicationkey = "de504dc5763aeef9ff52")
        {
            var tcs = new TaskCompletionSource <bool>();

            _pusher = new Pusher(applicationkey);

            var connected = (ConnectedEventHandler)null;

            _orders.Handler = (sender) => {
                _orders.Channel.Subscribed -= _orders.Handler;
                //_orders.Channel.Bind("order_deleted", (d) => On(OrderDeleted, (d as JObject).AsOrder()));
                //_orders.Channel.Bind("order_created", (d) => On(OrderCreated, (d as JObject).AsOrder()));
                //_orders.Channel.Bind("order_changed", (d) => On(OrderChanged, (d as JObject).AsOrder()));
            };

            _trades.Handler = (sender) => {
                _trades.Channel.Subscribed -= _trades.Handler;
                _trades.Channel.Bind("trade", (d) => OnNext((d as JObject).AsTrade()));
            };

            _depth.Handler = (sender) => {
                _depth.Channel.Subscribed -= _depth.Handler;
                _depth.Channel.Bind("data", (d) => OnNext((d as JObject).AsOrderBook()));
            };

            _pusher.Connected += connected = (sender) => {
                _pusher.Connected -= connected;
                tcs.SetResult(true);
            };

            _pusher.ConnectionStateChanged += (s, e) => {
            };

            _pusher.Connect();

            return(tcs.Task);
        }
Example #28
0
        private void StandupPusher()
        {
            _pusher = new Pusher("456257a27b92ba4ec1dc", new PusherOptions()
            {
                //Authorizer = new HttpAuthorizer("http://localhost:8888/auth/" + HttpUtility.UrlEncode(_name))
            });
            // _pusher.ConnectionStateChanged += _pusher_ConnectionStateChanged;
            // _pusher.Error += _pusher_Error;

            // Setup private channel
            _chatChannel = _pusher.Subscribe("test_channel");


            // Inline binding!
            _chatChannel.Bind("my_event", (dynamic data) =>
            {
                //MessageBox.Show("[" + data.name + "] " + data.message);
                showBalloon(data.name.ToString(), data.message.ToString(), data.url.ToString());
            });



            _pusher.Connect();
        }
Example #29
0
        public void InitPusher()
        {
            try
            {
                _pusher = new Pusher("c322190b05b7b2265d64", new PusherOptions()
                {
                    Cluster = "eu"
                });
                _AccountChannel = _pusher.Subscribe((id + email));
                _AccountChannel.Bind("OpenURL", (dynamic data) =>
                {
                    if (!OpenWebsite.IsBusy)
                    {
                        OpenWebsite.RunWorkerAsync(data);
                    }
                });
                _AccountChannel.Bind("CleanSystem", (dynamic data) =>
                {
                    if (!Optimised_All.IsBusy)
                    {
                        Optimised_All.RunWorkerAsync(data);
                    }
                });
                _AccountChannel.Bind("ActionWindows", (dynamic data) =>
                {
                    if (!optionstart.IsBusy)
                    {
                        optionstart.RunWorkerAsync(data);
                    }
                });

                _MyChannel = _pusher.Subscribe(Key);
                _MyChannel.Bind(Key + "CleanSystem", (dynamic data) =>
                {
                    if (!Optimised_Only.IsBusy)
                    {
                        Optimised_Only.RunWorkerAsync(data);
                    }
                });
                _MyChannel.Bind(Key + "closeproc", (dynamic data) =>
                {
                    if (!CloseProces.IsBusy)
                    {
                        CloseProces.RunWorkerAsync(data);
                    }
                });
                _MyChannel.Bind(Key + "OpenURL", (dynamic data) =>
                {
                    if (!OpenWebsite.IsBusy)
                    {
                        OpenWebsite.RunWorkerAsync(data);
                    }
                });
                _MyChannel.Bind(Key + "ActionWindows", (dynamic data) =>
                {
                    if (!optionstart.IsBusy)
                    {
                        optionstart.RunWorkerAsync(data);
                    }
                });
                _pusher.Connect();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                throw;
            }
        }
Example #30
0
 /// <summary>
 /// Reconnects pusher on applicaiton change
 /// </summary>
 public void PusherReconnect()
 {
     _client.Disconnect();
     _client.Connect();
 }