コード例 #1
0
ファイル: Rest.cs プロジェクト: freirefx/rest-csharp-refimpl
        /// <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);
        }
コード例 #2
0
        public void HandlePricesRequest(PricesRequest request)
        {
            PricesResponse response = StoreManager.GetPricesResponse();

            response.ResponseId = request.RequestId;
            Send(response);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
ファイル: Gatherer.cs プロジェクト: oarset/gryptogather
        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;
            }
        }
コード例 #7
0
 public TicketItem(PricesResponse price)
 {
     this.Price = price;
 }