forked from DigitalRuby/ExchangeSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTickerOption.cs
50 lines (44 loc) · 1.15 KB
/
TickerOption.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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CommandLine;
using ExchangeSharp;
using ExchangeSharpConsole.Options.Interfaces;
namespace ExchangeSharpConsole.Options
{
[Verb("ticker", HelpText = "Gets the ticker for the selected exchange.")]
public class TickerOption : BaseOption, IOptionPerExchange, IOptionWithMarketSymbol
{
public override async Task RunCommand()
{
using var api = await GetExchangeInstanceAsync(ExchangeName);
try
{
IEnumerable<KeyValuePair<string, ExchangeTicker>> tickers;
if (!string.IsNullOrWhiteSpace(MarketSymbol))
{
var ticker = await api.GetTickerAsync(MarketSymbol);
tickers = new List<KeyValuePair<string, ExchangeTicker>>
{
new KeyValuePair<string, ExchangeTicker>(MarketSymbol, ticker)
};
}
else
{
tickers = await api.GetTickersAsync();
}
foreach (var ticker in tickers)
{
Console.WriteLine(ticker.ToString());
}
WaitInteractively();
}
catch (Exception ex)
{
Console.Error.WriteLine(ex);
}
}
public string ExchangeName { get; set; }
public string MarketSymbol { get; set; }
}
}