/// <summary> /// Retrieves the current rate for each of a list of instruments /// </summary> /// <param name="instruments">the list of instruments to check</param> /// <returns>List of Price objects with the current price for each instrument</returns> public static async Task <List <Price> > GetRatesAsync(List <Instrument> instruments, string since = null) { StringBuilder requestBuilder = new StringBuilder(Server(EServer.Rates) + "prices?instruments="); foreach (var instrument in instruments) { requestBuilder.Append(instrument.instrument + ","); } string requestString = requestBuilder.ToString().Trim(','); requestString = requestString.Replace(",", "%2C"); // TODO: make sure this works if (!string.IsNullOrEmpty(since)) { requestString += "&since=" + since; } PricesResponse pricesResponse = await MakeRequestAsync <PricesResponse>(requestString); List <Price> prices = new List <Price>(); prices.AddRange(pricesResponse.prices); return(prices); }
public void HandlePricesRequest(PricesRequest request) { PricesResponse response = StoreManager.GetPricesResponse(); response.ResponseId = request.RequestId; Send(response); }
public override async Task <PricesResponse> GetPrices(PricesRequest request, ServerCallContext context) { var entities = _pricesReader.Get(PriceEntity.GetPk()); List <PriceUpdate> result; if (entities.Any()) { result = _mapper.Map <List <PriceUpdate> >(entities); } else { var marketData = await _marketDataClient.GetMarketDataAsync(new Empty()); result = _mapper.Map <List <PriceUpdate> >(marketData.Items.ToList()); } if (request.AssetPairIds.Any()) { result = result.Where(x => request.AssetPairIds.Contains(x.AssetPairId, StringComparer.InvariantCultureIgnoreCase)) .ToList(); } var response = new PricesResponse(); response.Payload.AddRange(result); return(response); }
public override Task <PricesResponse> GetPrices(PricesRequest request, ServerCallContext context) { var symbols = request.AssetPairIds.ToList(); var prices = _marketDataService.GetPrices(DefaultTenantId); IEnumerable <PriceEntity> data = prices; if (symbols.Any()) { data = data.Where(p => symbols.Contains(p.Symbol)); } var response = new PricesResponse { Prices = { data.Select(p => new PriceUpdate { AssetPairId = p.Symbol, Timestamp = Timestamp.FromDateTime(DateTime.SpecifyKind(p.LastUpdate, DateTimeKind.Utc)), Ask = p.Ask.HasValue ? p.Ask.ToString() : string.Empty, Bid = p.Ask.HasValue ? p.Bid.ToString() : string.Empty, PriceChange24H = "0", //todo: calculate 24h statistic and write to mynisql to use here VolumeBase24H = "0", VolumeQuote24H = "0" }) .ToList() } }; return(Task.FromResult(response)); }
public override Task <PricesResponse> GetPrices(PricesRequest request, ServerCallContext context) { var entities = _pricesReader.Get(PriceEntity.GetPk()); var result = new List <PriceUpdate>(); if (entities.Any()) { result = _mapper.Map <List <PriceUpdate> >(entities); } if (request.AssetPairIds.Any()) { result = result.Where(x => request.AssetPairIds.Contains(x.AssetPairId, StringComparer.InvariantCultureIgnoreCase)) .ToList(); } var response = new PricesResponse { Body = new PricesResponse.Types.Body() }; response.Body.Prices.AddRange(result); return(Task.FromResult(response)); }
private async Task GatherBTCAsync(CancellationToken cancellationToken) { var resultBTC = await Client.GetAsync("https://api.bitfinex.com/v2/ticker/tBTCUSD"); var test = new PricesResponse(); if (resultBTC.IsSuccessStatusCode) { // var response = JsonConvert.DeserializeObject<PricesResponse>(resultETH.Content.ReadAsStringAsync().Result); var response = resultBTC.Content.ReadAsStringAsync().Result; var data = Array.ConvertAll(response.Trim('[', ']').Split(','), s => float.Parse(s)); var ticker = ParseTicker(data); var asyncIndexResponseBTC = await EsClient.IndexAsync <string>("btc", "Currency", Guid.NewGuid().ToString(), ticker); string responseString = asyncIndexResponseBTC.Body; } }
public TicketItem(PricesResponse price) { this.Price = price; }