This repository was archived by the owner on Nov 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
100 lines (87 loc) · 3.47 KB
/
Program.cs
File metadata and controls
100 lines (87 loc) · 3.47 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
namespace ClientCsharp
{
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR.Client;
using Microsoft.Extensions.Logging;
public static class Program
{
private const string DaxIndex = "b6OQR";
private const string BearerToken = "YOUR-ACCESS-TOKEN"; // Only token, no prefix "Bearer "
private const string AccountNumber = "YOUR-ACCOUNT-NUMBER"; // Not the IBAN, but the number in the GET /accounts response
private const string StreamerUrl = "https://realtime.sandbox.binck.com/stream/v1"; // For production use https://realtime.binck.com/stream/v1
public static async Task Main()
{
if (BearerToken == "YOUR-ACCESS-TOKEN")
{
throw new ArgumentException("Enter a valid access token.");
}
HubConnection hubConnection = new HubConnectionBuilder()
.WithUrl(StreamerUrl,
options =>
options.AccessTokenProvider = () => Task.FromResult(BearerToken)
)
.ConfigureLogging(logging => { logging.AddConsole(); })
.Build();
hubConnection.On<OrderModel>("OrderStatus", n =>
{
Console.WriteLine($"OrderStatus: {n.AccountNumber} ### {n.Number}");
});
hubConnection.On<OrderModel>("OrderModified", n =>
{
Console.WriteLine($"OrderModified: {n.AccountNumber} ### {n.Number}");
});
hubConnection.On<OrderModel>("OrderExecution", n =>
{
Console.WriteLine($"OrderExecution: {n.AccountNumber} ### {n.Number}");
});
hubConnection.On<NewsMessageModel>("News", n =>
{
Console.WriteLine($"News: {n.PublishedDateTime} ### {n.Headline}");
});
hubConnection.On<QuoteListModel>("Quote", q =>
{
foreach (QuoteModel quote in q.Quotes)
{
Console.WriteLine($"Quote: {quote.QuoteDateTime} ### DAX {quote.QuoteType} {quote.Price}");
}
});
// Start the connection to the streamer
try
{
await hubConnection.StartAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
if (hubConnection.State == HubConnectionState.Disconnected)
{
Console.WriteLine(
"Connection is not active. Per token only one session is allowed. Could that be the reason?");
}
else
{
try
{
// Subscribe to the order events feed
await hubConnection.InvokeAsync("SubscribeOrders",
AccountNumber);
// Subscribe to the news feed
await hubConnection.InvokeAsync("SubscribeNews",
AccountNumber);
// Subscribe to instrument quotes
await hubConnection.InvokeAsync("SubscribeQuotes",
AccountNumber,
new[] { DaxIndex },
"TopOfBook");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Console.ReadLine();
}
}
}