forked from Marfusios/bitfinex-client-websocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BitfinexWebsocketClientTests.cs
81 lines (64 loc) · 2.51 KB
/
BitfinexWebsocketClientTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Threading;
using System.Threading.Tasks;
using Bitfinex.Client.Websocket.Client;
using Bitfinex.Client.Websocket.Requests;
using Bitfinex.Client.Websocket.Responses;
using Bitfinex.Client.Websocket.Websockets;
using Xunit;
namespace Bitfinex.Client.Websocket.Tests.Integration
{
public class BitfinexWebsocketClientTests
{
private static readonly string API_KEY = "your_api_key";
private static readonly string API_SECRET = "";
[Fact]
public async Task PingPong()
{
var url = BitfinexValues.ApiWebsocketUrl;
using (var communicator = new BitfinexWebsocketCommunicator(url))
{
PongResponse received = null;
var receivedEvent = new ManualResetEvent(false);
using (var client = new BitfinexWebsocketClient(communicator))
{
client.Streams.PongStream.Subscribe(pong =>
{
received = pong;
receivedEvent.Set();
});
await communicator.Start();
client.Send(new PingRequest() {Cid = 123456});
receivedEvent.WaitOne(TimeSpan.FromSeconds(30));
Assert.NotNull(received);
Assert.Equal(123456, received.Cid);
Assert.True(DateTime.UtcNow.Subtract(received.Ts).TotalSeconds < 15);
}
}
}
[SkippableFact]
public async Task Authentication()
{
Skip.If(string.IsNullOrWhiteSpace(API_SECRET));
var url = BitfinexValues.ApiWebsocketUrl;
using (var communicator = new BitfinexWebsocketCommunicator(url))
{
AuthenticationResponse received = null;
var receivedEvent = new ManualResetEvent(false);
using (var client = new BitfinexWebsocketClient(communicator))
{
client.Streams.AuthenticationStream.Subscribe(auth =>
{
received = auth;
receivedEvent.Set();
});
await communicator.Start();
client.Authenticate(API_KEY, API_SECRET);
receivedEvent.WaitOne(TimeSpan.FromSeconds(30));
Assert.NotNull(received);
Assert.True(received.IsAuthenticated);
}
}
}
}
}