Exemplo n.º 1
0
        private async Task <double> GetAmountInBtc(IReadOnlyDictionary <string, decimal> values)
        {
            var data = await _rateCalculatorClient.GetMarketAmountInBaseAsync(
                values.Where(x => x.Value > 0 && x.Key != LykkeConstants.BitcoinAssetId).Select(x => new AssetWithAmount((double)x.Value, x.Key)),
                LykkeConstants.BitcoinAssetId, OrderAction.Sell);

            var result = data.Sum(x => x.To?.Amount ?? 0);

            if (values.ContainsKey(LykkeConstants.BitcoinAssetId))
            {
                result += (double)values[LykkeConstants.BitcoinAssetId];
            }

            return(result);
        }
        public async Task <IActionResult> Convert([FromBody] ConvertionRequest request)
        {
            var orderAction = BaseOrderExt.GetOrderAction(request.OrderAction);

            if (orderAction == null)
            {
                ModelState.AddModelError("OrderAction", request.OrderAction);
                return(BadRequest(ModelState));
            }

            var result = await _rateCalculator.GetMarketAmountInBaseAsync(request.AssetsFrom, request.BaseAssetId,
                                                                          orderAction.Value.ToRateCalculatorDomain());

            return(Ok(new ConvertionResponse {
                Converted = result.ToArray()
            }));
        }