我正在尝试连接到 Poloniex。要连接,我正在使用 WynthShop 和以下代码:
public class Program
{
public static void Main(string[] args)
{
var channelFactory = new DefaultWampChannelFactory();
var channel = channelFactory.CreateJsonChannel("wss://api.poloniex.com", "realm1");
channel.Open().GetAwaiter().GetResult();
var tickerSubject = channel.RealmProxy.Services.GetSubject("ticker");
var cancellationTokenSource = new CancellationTokenSource();
using (var subscr = tickerSubject.Subscribe(evt =>
{
var currencyPair = evt.Arguments[0].Deserialize<string>();
var last = evt.Arguments[1].Deserialize<decimal>();
Console.WriteLine($"Currencypair: {currencyPair}, Last: {last}");
}))
{
Console.WriteLine("Press a key to exit");
Console.ReadKey();
cancellationTokenSource.Cancel();
}
}
}
但不幸的是,我收到错误“无法连接到远程服务器”。也许有人知道如何解决连接问题。我也尝试使用以下代码,但也无法连接:
public class Program
{
static void Main(string[] args)
{
var channelFactory = new DefaultWampChannelFactory();
var channel = channelFactory.CreateJsonChannel("wss://api.poloniex.com", "realm1");
Func<Task> connect = async () =>
{
//await Task.Delay(30000);
await channel.Open();
var tickerSubject = channel.RealmProxy.Services.GetSubject("ticker");
var subscription = tickerSubject.Subscribe(evt =>
{
var currencyPair = evt.Arguments[0].Deserialize<string>();
var last = evt.Arguments[1].Deserialize<decimal>();
Console.WriteLine($"Currencypair: {currencyPair}, Last: {last}");
},
ex => {
Console.WriteLine($"Oh no! {ex}");
});
};
WampChannelReconnector reconnector =
new WampChannelReconnector(channel, connect);
reconnector.Start();
Console.WriteLine("Press a key to exit");
Console.ReadKey();
}
}