public async Task <IActionResult> UpdateRealAssets(string exchangeId)
        {
            var userId = HttpContext.User.GetUserId();

            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest("User not found"));
            }

            var userAssets = await _exchangeFactory.GetExchange(exchangeId).GetRealBalances(userId);

            var originalAssets = _assetRepository.GetByUserAndExchange(userId, exchangeId).Where(o => o.TradingMode == TradingMode.Real);

            foreach (var asset in userAssets)
            {
                var reservedFromAsset = originalAssets.Where(o => o.Currency == asset.Currency && o.StrategyId != null).Sum(o => o.Amount);
                var originalFreeAsset = originalAssets.FirstOrDefault(o => o.Currency == asset.Currency && o.StrategyId == null);

                if (originalFreeAsset == null)
                {
                    if (asset.Amount != reservedFromAsset) // In order to NOT create empty asset
                    {
                        asset.Amount = asset.Amount - reservedFromAsset;
                        _assetRepository.AddNotSave(asset);
                    }
                }
                else
                {
                    originalFreeAsset.Amount = asset.Amount - reservedFromAsset;
                    _assetRepository.EditNotSave(originalFreeAsset);
                }
            }
            _assetRepository.Save();
            return(Ok());
        }
        public async Task <Result> PutOrder(TradeOrder order, string strategyId, OrderType orderType)
        {
            var strategy = _strategyRepository.GetById(strategyId);

            if (strategy.TradingMode == TradingMode.Real)
            {
                var soldAsset = GetSoldAsset(order, strategyId, orderType);
                if (soldAsset == null || soldAsset.Amount < order.Amount)
                {
                    return(new Result(false, "Insufficient funds for " + soldAsset.Currency));
                }
                var exchange = _exchangeFactory.GetExchange(order.Exchange);
                if (exchange == null)
                {
                    return(new Result(false, "Exchange not found"));
                }
                var uuid = await exchange.PutOrder(order, orderType, strategy.UserId);

                if (uuid == null)
                {
                    return(new Result(false, "Exchange unable to create order"));
                }
                return(new Result(true, ManageAssets(soldAsset, order, orderType, uuid)));
            }
            else if (strategy.TradingMode == TradingMode.BackTesting)
            {
                return(new Result(true, ManageAssets(null, order, orderType, "")));
            }
            else
            {
                var soldAsset = GetSoldAsset(order, strategyId, orderType);
                if (soldAsset == null || soldAsset.Amount < order.Amount)
                {
                    return(new Result(false, "Insufficient funds for" + soldAsset.Currency));
                }
                return(new Result(true, ManageAssets(soldAsset, order, orderType, "")));
            }
        }