private async Task <List <T> > GetAllAsync <T, TY, TTy>(string path, TTy request) where T : ExchangeModel where TTy : ICollectionRequest { var stopwatch = new Stopwatch(); var total = 0; var count = 0; var returnModels = new List <T>(); do { using (var client = new ExchangeHttpClient(ExchangeConfig.RestUrl)) { stopwatch.Restart(); total += count; request.StartAt = total; var query = request.AsDictionary().BuildQueryString(); var response = await client.GetAsync <TY>(path, query, BitmexUtils.GetHttpAuthHeaders(ExchangeConfig.RestUrl, HttpMethod.GET, path, query, ExchangeConfig.UserConfig.Key, ExchangeConfig.UserConfig.Secret)); if (response == null) { throw new NullReferenceException(); } var models = response.Select(x => Mapper.Map <T>(x)).ToArray(); returnModels.AddRange(models); count = response.Length; if (count < request.Count) { count = 0; } if (stopwatch.Elapsed < TimeSpan.FromSeconds(1.01)) { await Task.Delay(TimeSpan.FromSeconds(1.5).Subtract(stopwatch.Elapsed)); } } } while (count > 0); return(returnModels); }
public OperacaoResource(ExchangeHttpClient httpClient) { _httpClient = httpClient; }