Ejemplo n.º 1
0
        public void MarketsListTest()
        {
            var marketsRequest = new MarketsRequest("stock");

            Assert.Equal(13, marketsRequest.Response.Markets.Data.Count);

            marketsRequest = new MarketsRequest("futures");
            Assert.Equal(5, marketsRequest.Response.Markets.Data.Count);
        }
Ejemplo n.º 2
0
        public override async Task <MarketsResponse> GetMarkets(MarketsRequest request, ServerCallContext context)
        {
            var result = new MarketsResponse();

            try
            {
                if (request.OptionalAssetPairIdCase == MarketsRequest.OptionalAssetPairIdOneofCase.None || string.IsNullOrEmpty(request.AssetPairId))
                {
                    var response = await _walletApiV2Client.GetMarketsAsync();

                    result.Body = new MarketsResponse.Types.Body();
                    result.Body.Markets.AddRange(_mapper.Map <List <MarketsResponse.Types.MarketModel> >(response));
                }
                else
                {
                    var response = await _walletApiV2Client.GetMarketsByAssetPairIdAsync(request.AssetPairId);

                    if (response != null)
                    {
                        result.Body = new MarketsResponse.Types.Body();
                        result.Body.Markets.Add(_mapper.Map <MarketsResponse.Types.MarketModel>(response));
                    }
                }

                return(result);
            }
            catch (ApiExceptionV2 ex)
            {
                if (ex.StatusCode == 400)
                {
                    result.Error = new ErrorResponseBody
                    {
                        Code    = ErrorCode.NotFound,
                        Message = ex.Response.Replace("\"", string.Empty)
                    };

                    return(result);
                }

                throw;
            }
        }
Ejemplo n.º 3
0
        public override async Task <MarketsResponse> GetMarkets(MarketsRequest request, ServerCallContext context)
        {
            var session = SessionFromContext(context);

            var prices = await GetPrices(new PricesRequest(), context);

            var result = new MarketsResponse();


            var pairs = await _marketDataService.GetAssetPairsByTenant(session.TenantId);

            foreach (var pair in pairs)
            {
                var price = prices.Prices.FirstOrDefault(e => e.AssetPairId == pair.Id.ToString());
                if (price != null)
                {
                    var ask = !string.IsNullOrEmpty(price.Ask) ? decimal.Parse(price.Ask) : 0m;
                    var bid = !string.IsNullOrEmpty(price.Bid) ? decimal.Parse(price.Bid) : 0m;

                    var item = new MarketsResponse.Types.MarketModel()
                    {
                        AssetPair      = price.AssetPairId,
                        Ask            = price.Ask,
                        Bid            = price.Bid,
                        High           = Math.Max(ask, bid).ToString(CultureInfo.InvariantCulture),
                        LastPrice      = price.Ask,
                        Low            = Math.Min(ask, bid).ToString(CultureInfo.InvariantCulture),
                        PriceChange24H = price.PriceChange24H,
                        Volume24H      = price.VolumeBase24H
                    };

                    result.Markets.Add(item);
                }
                else
                {
                    var item = new MarketsResponse.Types.MarketModel()
                    {
                        AssetPair      = pair.Symbol,
                        Ask            = "0",
                        Bid            = "0",
                        High           = "0",
                        LastPrice      = "0",
                        Low            = "0",
                        PriceChange24H = "0",
                        Volume24H      = "0"
                    };

                    result.Markets.Add(item);
                }
            }

            if (result.Markets.All(e => e.AssetPair != "BTCUSD"))
            {
                var item = new MarketsResponse.Types.MarketModel()
                {
                    AssetPair      = "BTCUSD",
                    Ask            = "0",
                    Bid            = "0",
                    High           = "0",
                    LastPrice      = "0",
                    Low            = "0",
                    PriceChange24H = "0",
                    Volume24H      = "0"
                };

                result.Markets.Add(item);
            }


            return(result);
        }
Ejemplo n.º 4
0
        public async Task <MarketsResponse> GetMarkets(MarketsRequest request)
        {
            var query = request.Hours.HasValue ? $"/{request.Hours}" : null;

            return(await GetResult <MarketsResponse>(PublicApiCall.GetMarkets, query));
        }