-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
Copy pathTradeHistoryOption.cs
65 lines (53 loc) · 1.59 KB
/
TradeHistoryOption.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
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CommandLine;
using ExchangeSharp;
using ExchangeSharpConsole.Options.Interfaces;
namespace ExchangeSharpConsole.Options
{
[Verb(
"trade-history",
HelpText = "Print trade history from an Exchange to output.\n"
+ "Example: trade-history -e Binance -s btcusdt --since \"2018-05-17\" --to \"2018-05-18\""
)]
public class TradeHistoryOption
: BaseOption,
IOptionPerExchange,
IOptionPerMarketSymbol,
IOptionWithStartDate,
IOptionWithEndDate
{
public override async Task RunCommand()
{
using var api = await GetExchangeInstanceAsync(ExchangeName);
Console.WriteLine($"Showing historical trades for exchange {ExchangeName}...");
DateTime? startDate = null;
DateTime? endDate = null;
if (!string.IsNullOrWhiteSpace(SinceDateString))
{
startDate = DateTime.Parse(SinceDateString).ToUniversalTime();
}
if (!string.IsNullOrWhiteSpace(ToDateString))
{
endDate = DateTime.Parse(ToDateString).ToUniversalTime();
}
await api.GetHistoricalTradesAsync(PrintTrades, MarketSymbol, startDate, endDate);
}
private static bool PrintTrades(IEnumerable<ExchangeTrade> trades)
{
foreach (var trade in trades)
{
Console.WriteLine(
$"Trade at timestamp {trade.Timestamp.ToLocalTime()}: "
+ $"{trade.Id}/{trade.Price}/{trade.Amount}"
);
}
return true;
}
public string ExchangeName { get; set; }
public string MarketSymbol { get; set; }
public string SinceDateString { get; set; }
public string ToDateString { get; set; }
}
}