//[Fact] public async void BalanceTest() { var result = await _restClient.BalanceAsync(); Assert.NotEmpty(result); Assert.DoesNotContain(result, x => string.IsNullOrEmpty(x.Key)); }
private async Task DoTimer(ITimerTrigger timer, TimerTriggeredHandlerArgs args, CancellationToken ct) { var balance = await _b2C2RestClient.BalanceAsync(ct); using (var context = CreateContext()) { var ts = DateTime.UtcNow; var items = new List <BalanceEntity>(); foreach (var assetBalance in balance) { var assetName = assetBalance.Key; foreach (var assetMapping in _assetMappings) { assetName = assetName.Replace(assetMapping.Key, assetMapping.Value); } var item = new BalanceEntity { Asset = assetName, Timestamp = ts, Balance = assetBalance.Value }; items.Add(item); } context.Balances.AddRange(items); await context.SaveChangesAsync(ct); } }
private Task <IReadOnlyCollection <Balance> > ExecuteGetBalancesAsync() { return(WrapAsync <IReadOnlyCollection <Balance> >(async() => { IReadOnlyDictionary <string, decimal> balances = await _client.BalanceAsync(); return balances .Select(o => new Balance(ExchangeNames.External, o.Key, o.Value)) .ToArray(); })); }
public override async Task <GetBalanceResponse> GetBalance(GetBalanceRequest request, ServerCallContext context) { var balances = await _b2C2RestClient.BalanceAsync(context.CancellationToken); var result = new GetBalanceResponse { Timestamp = DateTime.UtcNow.ToTimestamp() }; result.AssetBalances.AddRange(Map(balances)); return(result); }
private async Task DoTimer(ITimerTrigger timer, TimerTriggeredHandlerArgs args, CancellationToken ct) { var balance = await _b2C2RestClient.BalanceAsync(ct); using (var context = CreateContext()) { var ts = DateTime.UtcNow; var items = balance.Select(e => new BalanceEntity { Asset = e.Key, Timestamp = ts, Balance = e.Value }).ToList(); context.Balances.AddRange(items); await context.SaveChangesAsync(ct); } }