This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
/
CoinigyBalanceHandler.cs
53 lines (48 loc) · 1.86 KB
/
CoinigyBalanceHandler.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
using System.Threading.Tasks;
using CryptoGramBot.Configuration;
using CryptoGramBot.EventBus.Commands;
using CryptoGramBot.EventBus.Events;
using CryptoGramBot.Helpers;
using CryptoGramBot.Services.Exchanges;
using Enexure.MicroBus;
namespace CryptoGramBot.EventBus.Handlers.BalanceInfo
{
public class CoinigyBalanceHandler : IEventHandler<BalanceCheckEvent>
{
private readonly IMicroBus _bus;
private readonly CoinigyBalanceService _coinigyBalanceService;
private readonly CoinigyConfig _config;
public CoinigyBalanceHandler(
CoinigyBalanceService coinigyBalanceService,
CoinigyConfig config,
IMicroBus bus
)
{
_coinigyBalanceService = coinigyBalanceService;
_config = config;
_bus = bus;
}
public async Task Handle(BalanceCheckEvent @event)
{
if (@event.Exchange == null && !@event.UserRequested)
{
await _coinigyBalanceService.GetAllBalances();
await _coinigyBalanceService.GetBalance();
}
if (@event.UserRequested || @event.Exchange == Constants.CoinigyAccountBalance)
{
if (@event.CoinigyAccountId.HasValue)
{
var accountInfo = await _coinigyBalanceService.GetAccountBalance(@event.CoinigyAccountId.Value);
await _bus.SendAsync(new SendBalanceInfoCommand(accountInfo));
}
}
if (@event.Exchange == Constants.TotalCoinigyBalance && (@event.UserRequested))
{
await _coinigyBalanceService.GetAllBalances();
var balanceInformation = await _coinigyBalanceService.GetBalance();
await _bus.SendAsync(new SendBalanceInfoCommand(balanceInformation));
}
}
}
}