WampSharp无法连接到Poloniex

本文关键字:Poloniex 连接 WampSharp | 更新日期: 2023-09-27 17:58:14

以下是我使用WampSharp:最新预发布版本的非常简单的代码

        var channelFactory = new DefaultWampChannelFactory();
        var channel = channelFactory.CreateMsgpackChannel("wss://api.poloniex.com", "realm1");
        await channel.Open();
        var realmProxy = channel.RealmProxy;
        Console.WriteLine("Connection established");
        int received = 0;
        IDisposable subscription = null;
        subscription =
            realmProxy.Services.GetSubject("ticker")
                      .Subscribe(x =>
            {
                Console.WriteLine("Got Event: " + x);
                received++;
                if (received > 5)
                {
                    Console.WriteLine("Closing ..");
                    subscription.Dispose();
                }
            });
        Console.ReadLine();

虽然不起作用,但订阅中的代码从未运行过。在CreateJsonChannel上也尝试过,但也不起作用。

有什么想法吗?

WampSharp无法连接到Poloniex

您的代码运行良好。只要去掉Console.ReadLine——它会阻塞WebSocket线程,因此WampSharp无法获得任何进一步的消息。您可以将Console.ReadLine添加到Main中。

另请参阅博客文章。