forked from DigitalRuby/ExchangeSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatsOption.cs
74 lines (65 loc) · 3.37 KB
/
StatsOption.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
71
72
73
74
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using CommandLine;
using ExchangeSharp;
using ExchangeSharpConsole.Options.Interfaces;
namespace ExchangeSharpConsole.Options
{
[Verb("stats", HelpText = "Show stats from 4 exchanges.\n" +
"This is a great way to see the price, order book and other useful stats.")]
public class StatsOption : BaseOption, IOptionWithInterval
{
public override async Task RunCommand()
{
var marketSymbol = "BTC-USD";
var marketSymbol2 = "XXBTZUSD";
IExchangeAPI
apiCoinbase = await ExchangeAPI.GetExchangeAPIAsync(ExchangeName.Coinbase),
apiGemini = await ExchangeAPI.GetExchangeAPIAsync(ExchangeName.Gemini),
apiKraken = await ExchangeAPI.GetExchangeAPIAsync(ExchangeName.Kraken),
apiBitfinex = await ExchangeAPI.GetExchangeAPIAsync(ExchangeName.Bitfinex);
//TODO: Make this multi-threaded and add parameters
Console.WriteLine("Use CTRL-C to stop.");
while (true)
{
var ticker = await apiCoinbase.GetTickerAsync(marketSymbol);
var orders = await apiCoinbase.GetOrderBookAsync(marketSymbol);
var askAmountSum = orders.Asks.Values.Sum(o => o.Amount);
var askPriceSum = orders.Asks.Values.Sum(o => o.Price);
var bidAmountSum = orders.Bids.Values.Sum(o => o.Amount);
var bidPriceSum = orders.Bids.Values.Sum(o => o.Price);
var ticker2 = await apiGemini.GetTickerAsync(marketSymbol);
var orders2 = await apiGemini.GetOrderBookAsync(marketSymbol);
var askAmountSum2 = orders2.Asks.Values.Sum(o => o.Amount);
var askPriceSum2 = orders2.Asks.Values.Sum(o => o.Price);
var bidAmountSum2 = orders2.Bids.Values.Sum(o => o.Amount);
var bidPriceSum2 = orders2.Bids.Values.Sum(o => o.Price);
var ticker3 = await apiKraken.GetTickerAsync(marketSymbol2);
var orders3 = await apiKraken.GetOrderBookAsync(marketSymbol2);
var askAmountSum3 = orders3.Asks.Values.Sum(o => o.Amount);
var askPriceSum3 = orders3.Asks.Values.Sum(o => o.Price);
var bidAmountSum3 = orders3.Bids.Values.Sum(o => o.Amount);
var bidPriceSum3 = orders3.Bids.Values.Sum(o => o.Price);
var ticker4 = await apiBitfinex.GetTickerAsync(marketSymbol);
var orders4 = await apiBitfinex.GetOrderBookAsync(marketSymbol);
var askAmountSum4 = orders4.Asks.Values.Sum(o => o.Amount);
var askPriceSum4 = orders4.Asks.Values.Sum(o => o.Price);
var bidAmountSum4 = orders4.Bids.Values.Sum(o => o.Amount);
var bidPriceSum4 = orders4.Bids.Values.Sum(o => o.Price);
Console.Clear();
Console.WriteLine("GDAX: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker.Last,
ticker.Volume.QuoteCurrencyVolume, askAmountSum, askPriceSum, bidAmountSum, bidPriceSum);
Console.WriteLine("GEMI: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker2.Last,
ticker2.Volume.QuoteCurrencyVolume, askAmountSum2, askPriceSum2, bidAmountSum2, bidPriceSum2);
Console.WriteLine("KRAK: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker3.Last,
ticker3.Volume.QuoteCurrencyVolume, askAmountSum3, askPriceSum3, bidAmountSum3, bidPriceSum3);
Console.WriteLine("BITF: {0,13:N}, {1,15:N}, {2,8:N}, {3,13:N}, {4,8:N}, {5,13:N}", ticker4.Last,
ticker4.Volume.QuoteCurrencyVolume, askAmountSum4, askPriceSum4, bidAmountSum4, bidPriceSum4);
Thread.Sleep(IntervalMs);
}
}
public int IntervalMs { get; set; }
}
}