-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBitfinexOrderBookSourceTests.cs
More file actions
74 lines (63 loc) · 2.62 KB
/
BitfinexOrderBookSourceTests.cs
File metadata and controls
74 lines (63 loc) · 2.62 KB
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
using System;
using System.Threading.Tasks;
using Bitfinex.Client.Websocket;
using Bitfinex.Client.Websocket.Client;
using Bitfinex.Client.Websocket.Requests.Subscriptions;
using Bitfinex.Client.Websocket.Utils;
using Bitfinex.Client.Websocket.Websockets;
using Crypto.Websocket.Extensions.Core.OrderBooks;
using Crypto.Websocket.Extensions.OrderBooks.Sources;
using Xunit;
namespace Crypto.Websocket.Extensions.Tests.Integration
{
public class BitfinexOrderBookSourceTests
{
[Fact]
public async Task ConnectToSource_ShouldHandleOrderBookCorrectly()
{
var url = BitfinexValues.ApiWebsocketUrl;
using (var communicator = new BitfinexWebsocketCommunicator(url))
{
using (var client = new BitfinexWebsocketClient(communicator))
{
var pair = "BTCUSD";
var source = new BitfinexOrderBookSource(client);
var orderBook = new CryptoOrderBook(pair, source);
await communicator.Start();
client.Send(new BookSubscribeRequest(pair, BitfinexPrecision.P0, BitfinexFrequency.Realtime, "100"));
await Task.Delay(TimeSpan.FromSeconds(5));
Assert.True(orderBook.BidPrice > 0);
Assert.True(orderBook.AskPrice > 0);
Assert.NotEmpty(orderBook.BidLevels);
Assert.NotEmpty(orderBook.AskLevels);
}
}
}
[Fact]
public async Task AutoSnapshotReloading_ShouldWorkAfterTimeout()
{
var url = BitfinexValues.ApiWebsocketUrl;
using (var communicator = new BitfinexWebsocketCommunicator(url))
{
using (var client = new BitfinexWebsocketClient(communicator))
{
var pair = "LTCUSD";
var source = new BitfinexOrderBookSource(client)
{
LoadSnapshotEnabled = true
};
var orderBook = new CryptoOrderBook(pair, source)
{
SnapshotReloadTimeout = TimeSpan.FromSeconds(5),
SnapshotReloadEnabled = true
};
await Task.Delay(TimeSpan.FromSeconds(13));
Assert.True(orderBook.BidPrice > 0);
Assert.True(orderBook.AskPrice > 0);
Assert.NotEmpty(orderBook.BidLevels);
Assert.NotEmpty(orderBook.AskLevels);
}
}
}
}
}