-
-
Notifications
You must be signed in to change notification settings - Fork 373
/
Copy pathBalancesOption.cs
70 lines (56 loc) · 1.61 KB
/
BalancesOption.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
70
using CommandLine;
using ExchangeSharpConsole.Options.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ExchangeSharpConsole.Options;
[Verb(
"balances",
HelpText = "Displays the account balances for an exchange."
)]
public class BalancesOption : BaseOption, IOptionPerExchange, IOptionWithKey
{
public override async Task RunCommand()
{
using var api = await GetExchangeInstanceAsync(ExchangeName);
api.LoadAPIKeys(KeyPath);
if (Mode.Equals("all", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("All Balances:");
var balances = await api.GetAmountsAsync();
foreach (var balance in balances)
{
Console.WriteLine($"{balance.Key}: {balance.Value}");
}
Console.WriteLine();
}
else if (Mode.Equals("trade", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Balances available for trading:");
var balances = await api.GetAmountsAvailableToTradeAsync();
foreach (var balance in balances)
{
Console.WriteLine($"{balance.Key}: {balance.Value}");
}
Console.WriteLine();
}
else
{
throw new ArgumentException($"Invalid mode: {Mode}");
}
}
public string ExchangeName { get; set; }
[Option(
'm',
"mode",
Required = true,
HelpText = "Mode of execution."
+ "\n\tPossible values are \"all\" or \"trade\"."
+ "\n\t\tall: Displays all funds, regardless if they are locked or not."
+ "\n\t\ttrade: Displays the funds that can be used, at the current moment, to trade."
)]
public string Mode { get; set; }
public string KeyPath { get; set; }
}