forked from DigitalRuby/ExchangeSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebSocketsTradesOption.cs
37 lines (32 loc) · 1.03 KB
/
WebSocketsTradesOption.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CommandLine;
using ExchangeSharp;
using ExchangeSharpConsole.Options.Interfaces;
namespace ExchangeSharpConsole.Options
{
[Verb("ws-trades", HelpText =
"Connects to the given exchange websocket and keeps printing the trades from that exchange.\n" +
"If market symbol is not set then uses all.")]
public class WebSocketsTradesOption : BaseOption, IOptionPerExchange, IOptionWithMultipleMarketSymbol
{
public override async Task RunCommand()
{
async Task<IWebSocket> GetWebSocket(IExchangeAPI api)
{
var symbols = await ValidateMarketSymbolsAsync(api, MarketSymbols.ToArray(), true);
return await api.GetTradesWebSocketAsync(message =>
{
Console.WriteLine($"{message.Key}: {message.Value}");
return Task.CompletedTask;
}, symbols
);
}
await RunWebSocket(ExchangeName, GetWebSocket);
}
public string ExchangeName { get; set; }
public IEnumerable<string> MarketSymbols { get; set; }
}
}