コード例 #1
0
        static void Main(string[] args)
        {
            // to make the output a bit nicer we are going to do some console manipulation
            // this stuff is by no means any sort of requirement but should make it ewasy to understand what is happeneing
            Console.CursorVisible = false;
            ConsoleSpinner.SetSequence(4);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Starting Connection!");
            Console.ResetColor();
            ConsoleSpinner.Enable();

            // intantiate an insatance of the pusher client by passing the application key and the options we want to use (if any)
            // one of the more interesting options is the ability to change the serializer being used, in this instance we will use our own
            // by implimenting the ISerializer interface and setting the Serializer option
            _client = new PurePusherClient("de504dc5763aeef9ff52", new PurePusherClientOptions {
                DebugMode = false, Serializer = new MySerializer()
            });

            // lets hook up to some events
            _client.ConnectionStateChanged += _client_ConnectionStateChanged;

            // try and connect
            if (_client.Connect())
            {
                //	ConsoleSpinner.Disable();
                //	Console.SetCursorPosition(0, Console.CursorTop - 1);
                //	Console.WriteLine("Connected!        ");
                //	ConsoleSpinner.Enable();

                // we have a connection so lets subscribe to a channel
                var ethusdChannel = _client.Subscribe("live_trades_ethusd");
                // bind to the new channel and do something with the data
                ethusdChannel.Bind("trade", data => { OnTrade(data, "USD/ETH"); });

                Console.WriteLine("Waiting for data!");
            }
            else
            {
                // something is wrong we did not get a connection
                ConsoleSpinner.Disable();
                Console.WriteLine("Failed to connect!");
            }

            Console.ReadLine();
        }
コード例 #2
0
        protected override async Task GetExchangeDataAsync(CancellationToken ct)
        {
            var closed = false;

            Client = new PurePusherClient(TickerUrl, new PurePusherClientOptions
            {
                DebugMode = false
            });

            Client.Connected += sender =>
            {
                foreach (var asset in Assets)
                {
                    Client
                    .Subscribe($"live_trades_{asset.UrlSymbol}")
                    .Bind("trade", o => Update(o, asset.Name));
                }
            };
            Client.Error += (sender,
                             error) =>
            {
                Logger.Error(error);
                closed = true;
            };

            if (!Client.Connect( ))
            {
                return;
            }

            while (Client.Connection.State != WebSocketState.Closed)
            {
                if (UpTime > LastUpdateDuration &&
                    LastUpdateDuration > TimeSpan.FromHours(1) ||
                    closed)
                {
                    Client.Disconnect( );
                    break;
                }

                await Task.Delay(PollingRate, ct).ConfigureAwait(false);
            }
        }
コード例 #3
0
 public PrivateChannel(string channelName, PurePusherClient purePusherClient) : base(channelName, purePusherClient)
 {
 }
コード例 #4
0
 public Channel(string channelName, PurePusherClient purePusherClient)
 {
     _purePusherClient = purePusherClient;
     Name = channelName;
 }