Пример #1
0
        public async Task <IActionResult> Get(string assetPairId = null)
        {
            if (string.IsNullOrWhiteSpace(assetPairId))
            {
                return(BadRequest());
            }

            var assetPair = await _assetsHelper.GetAssetPairAsync(assetPairId);

            if (assetPair == null || assetPair.IsDisabled)
            {
                return(NotFound());
            }

            var baseAsset = await _assetsHelper.GetAssetAsync(assetPair.BaseAssetId);

            var quotingAsset = await _assetsHelper.GetAssetAsync(assetPair.QuotingAssetId);

            if (baseAsset == null || baseAsset.IsDisabled ||
                quotingAsset == null || quotingAsset.IsDisabled)
            {
                return(NotFound());
            }

            if (!baseAsset.IsTradable || !quotingAsset.IsTradable)
            {
                return(BadRequest());
            }

            var result = await _orderBooksService.GetAsync(assetPairId);

            return(Ok(result.ToApiModel()));
        }
        public async Task <IActionResult> GetOrderBook(string assetPairId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var assetPair = _assetPairsReadModel.TryGetIfEnabled(assetPairId);

            if (assetPair == null)
            {
                return(NotFound());
            }

            var orderBooks = await _orderBooksService.GetAsync(assetPairId);

            return(Ok(orderBooks));
        }
Пример #3
0
        public async Task <double> GetBestPrice(string assetPairId, bool buy)
        {
            var assetPair = _assetPairsReadModelRepository.TryGet(assetPairId);

            if (assetPair == null)
            {
                return(0);
            }

            var orderBooks = (await _orderBooksService.GetAsync(assetPair)).ToArray();

            var price = GetBestPrice(orderBooks, assetPairId, buy);

            if (price > 0)
            {
                return(price);
            }

            return(GetBestPrice(orderBooks, assetPairId, !buy));
        }
Пример #4
0
        public async Task <IActionResult> Get(string assetPairId = null)
        {
            assetPairId = string.IsNullOrEmpty(assetPairId)
                ? null
                : assetPairId.ToUpper();

            AssetPair pair = null;

            if (!string.IsNullOrEmpty(assetPairId))
            {
                pair = await _assetPairs.GetItemAsync(assetPairId);
            }

            if (!string.IsNullOrEmpty(assetPairId) && pair == null)
            {
                return(NotFound($"Asset pair {assetPairId} not found"));
            }

            IEnumerable <IOrderBook> result = string.IsNullOrEmpty(assetPairId)
                ? await _orderBooksService.GetAllAsync()
                : await _orderBooksService.GetAsync(assetPairId);

            return(Ok(result.ToApiModel()));
        }
 public Task <IEnumerable <IOrderBook> > Get(string assetPairId)
 {
     return(_orderBooksService.GetAsync(assetPairId));
 }