class PortofolioService {

	public OrderInfo getOrderInfo(String login, String symbolCode, double quantity) {

		Objects.requireNonNull(symbolCode, "symbolCode is null");

		SymbolEntity selectedSymbol = symbolRepo.findById(symbolCode).get();

		if (selectedSymbol == null) {
			throw SymbolException.UNKNOWN(symbolCode);
		}

		PortofolioEntity portofolio = portofolioRepo.findByUserUsername(login);

		AssetEntity selectedAssetEntity = portofolio.getAsset(selectedSymbol.getCode());

		if (selectedAssetEntity == null) {
			selectedAssetEntity = new AssetEntity(portofolio, selectedSymbol, ZERO, portofolio.getCurrencyFor(selectedSymbol), ZERO);
		}

		String currencyCode = selectedAssetEntity.getCurrency().getCode();

		Rate q = rateService.getLatest(selectedSymbol.getCode(), currencyCode);

		AssetInfo selectedAsset = new AssetInfo(selectedAssetEntity.getSymbol(), selectedAssetEntity.getCurrency(),
				selectedAssetEntity.getQuantity().doubleValue());

		selectedAsset.setCurrentRate(q.getValue().doubleValue());

		final AssetInfo selectedCurrency;

		if (selectedAssetEntity.getCurrency().equals(portofolio.getBaseCurrency())) {
			selectedCurrency = new AssetInfo(portofolio.getBaseCurrency(), null, portofolio.getAmount().doubleValue());
		} else {
			AssetEntity currencyAE = portofolio.getAsset(selectedAssetEntity.getCurrency().getCode());
			selectedCurrency = new AssetInfo(currencyAE.getSymbol(), currencyAE.getCurrency(), currencyAE.getQuantity().doubleValue());
		}

		BigDecimal gainCost = null;

		if (quantity != 0) {
			gainCost = q.getValue().multiply(BigDecimal.valueOf(quantity));
		}

		return new OrderInfo(selectedAsset, selectedCurrency, gainCost);
	}

}