-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProgram.cs
69 lines (61 loc) · 1.95 KB
/
Program.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
// <copyright file="Program.cs" company="Devexperts LLC">
// Copyright © 2022 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// </copyright>
using System;
using System.Threading;
using System.Threading.Tasks;
using DxFeed.Graal.Net.Api;
using DxFeed.Graal.Net.Events.Market;
namespace DxFeed.Graal.Net.Samples;
/// <summary>
/// Creates multiple event listener and subscribe to Quote and Trade events.
/// Use default DXFeed instance for that data feed address is defined by "dxfeed.system.properties" file.
/// </summary>
internal abstract class DxFeedSample
{
public static async Task Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine($@"
Usage:
<symbol>
Where:
symbol - Is security symbol (e.g. IBM, AAPL, SPX etc.).");
return;
}
var symbol = args[0];
TestQuoteListener(symbol);
TestQuoteAndTradeListener(symbol);
await Task.Delay(Timeout.Infinite);
}
private static void TestQuoteListener(string symbol)
{
var sub = DXFeed.GetInstance().CreateSubscription(typeof(Quote));
sub.AddEventListener(events =>
{
foreach (var e in events)
{
if (e is Quote quote)
{
Console.WriteLine($"Mid = {(quote.BidPrice + quote.AskPrice) / 2}");
}
}
});
sub.AddSymbols(symbol);
}
private static void TestQuoteAndTradeListener(string symbol)
{
var sub = DXFeed.GetInstance().CreateSubscription(typeof(Quote), typeof(Trade));
sub.AddEventListener(events =>
{
foreach (var e in events)
{
Console.WriteLine(e);
}
});
sub.AddSymbols(symbol);
}
}