public EntityResponse <List <OptionPositionInformation> > GetOptionPositions(OptionPositionsArguments optionPositionsArguments) { List <SZKingdomArgument> arguments = new List <SZKingdomArgument>(); if (optionPositionsArguments.CustomerCode == null && optionPositionsArguments.CustomerAccountCode == null) { return(EntityResponse <List <OptionPositionInformation> > .Error( ErrorCode.SZKingdomLibraryError, ErrorMessages.SZKingdom_CustAndAccCodeNull)); } arguments.Add(SZKingdomArgument.CustomerCode(optionPositionsArguments.CustomerCode)); arguments.Add(SZKingdomArgument.CustomerAccountCode(optionPositionsArguments.CustomerAccountCode)); arguments.Add(SZKingdomArgument.TradeAccount(optionPositionsArguments.TradeAccount)); arguments.Add(SZKingdomArgument.OptionNumber(optionPositionsArguments.OptionNumber)); arguments.Add(SZKingdomArgument.TradeUnit(optionPositionsArguments.TradeUnit)); arguments.Add(SZKingdomArgument.OptionSide(optionPositionsArguments.OptionSide)); arguments.Add(SZKingdomArgument.OptionCoveredFlag(optionPositionsArguments.OptionCoveredFlag)); arguments.Add(SZKingdomArgument.QueryPosition(optionPositionsArguments.QueryPosition)); EntityResponse <List <OptionPositionInformation> > result = _marketDataLibrary.ExecuteCommandList <OptionPositionInformation>(SZKingdomRequest.OptionPositions, arguments); return(result); }
public List <OptionPositionViewModel> GetOptionPositions(string customerCode, string accountCode) { OptionPositionsArguments arguments = new OptionPositionsArguments { CustomerCode = customerCode, CustomerAccountCode = accountCode }; EntityResponse <List <OptionPositionInformation> > optionPositions = _portfolioManager.GetOptionPositions(arguments); List <OptionPositionViewModel> result = Mapper.Map <List <OptionPositionInformation>, List <OptionPositionViewModel> >(optionPositions.Entity); return(result); }
public List <BasePortfolioItemGroupViewModel> GetPortfolioData(string customerCode, string accountCode, string tradeAccount) { #region Fetch data OptionPositionsArguments arguments = new OptionPositionsArguments { CustomerCode = customerCode, CustomerAccountCode = accountCode }; EntityResponse <List <OptionPositionInformation> > optionPositions = _portfolioManager.GetOptionPositions(arguments); EntityResponse <List <OptionableStockPositionInformation> > stockPositions = _portfolioManager.GetOptionalStockPositions(customerCode, accountCode, tradeAccount); if (!optionPositions.IsSuccess || !stockPositions.IsSuccess || optionPositions.Entity.Count == 0) { return(new List <BasePortfolioItemGroupViewModel>()); } IEnumerable <PortfolioOption> portfolioOptions = Mapper.Map <List <OptionPositionInformation>, List <PortfolioOption> >(optionPositions.Entity); IEnumerable <PortfolioStock> portfolioStocks = Mapper.Map <List <OptionableStockPositionInformation>, List <PortfolioStock> >(stockPositions.Entity); Dictionary <string, EntityResponse <OptionChain> > optionChains = new Dictionary <string, EntityResponse <OptionChain> >(); #endregion #region Fill additional information foreach (PortfolioOption portfolioItem in portfolioOptions) { EntityResponse <List <OptionBasicInformation> > optionBasicInformation = _marketDataProviderQueryable.GetOptionBasicInformation(optionNumber: portfolioItem.OptionNumber); if (optionBasicInformation.Entity == null || !optionBasicInformation.Entity.Any()) { continue; } OptionBasicInformation basicInfo = optionBasicInformation.Entity.Single(); DateTime expiryDate = basicInfo.ExpireDate; DateAndNumberOfDaysUntil expiry = _marketWorkTimeService.GetNumberOfDaysLeftUntilExpiry(expiryDate); portfolioItem.Expiry = expiry; portfolioItem.UnderlyingCode = basicInfo.OptionUnderlyingCode; portfolioItem.UnderlyingName = basicInfo.OptionUnderlyingName; portfolioItem.StrikePrice = basicInfo.StrikePrice; EntityResponse <OptionChain> optionChain; string underlying = portfolioItem.UnderlyingCode; if (optionChains.ContainsKey(underlying)) { optionChain = optionChains[underlying]; } else { optionChain = _marketDataService.GetOptionChain(underlying); optionChains.Add(underlying, optionChain); } if (optionChain == null) { continue; } Option option = optionChain.Entity[portfolioItem.OptionNumber]; if (option == null) { portfolioItem.UnderlyingCode = null; continue; } Greeks greeks = option.Greeks ?? new Greeks(); portfolioItem.LastPrice = (decimal)option.LatestTradedPrice; //optionChain.Entity.UnderlyingCurrentPrice; portfolioItem.PremiumMultiplier = option.RootPair.PremiumMultiplier; portfolioItem.Greeks = new PortfolioGreeks(portfolioItem.OptionAvailableQuantity, greeks, portfolioItem.OptionSide, portfolioItem.PremiumMultiplier); } portfolioOptions = portfolioOptions.Where(x => x.UnderlyingCode != null); foreach (PortfolioStock portfolioStock in portfolioStocks) { SecurityQuotation quote = _marketDataService.GetSecurityQuotation(portfolioStock.SecurityCode); portfolioStock.LastPrice = quote.LastPrice; portfolioStock.StockMarketValue = quote.LastPrice * portfolioStock.AvailableBalance; portfolioStock.Greeks = new PortfolioGreeks(portfolioStock.AdjustedAvailableQuantity, new Greeks() { Delta = 1 }, portfolioStock.OptionSide, 1); } #endregion IEnumerable <BasePortfolioItemGroup> groupedByStrategies = _strategyService.GetPortfolioItemsGroupedByStrategy(portfolioOptions, portfolioStocks); List <BasePortfolioItemGroupViewModel> result = Mapper.Map <IEnumerable <BasePortfolioItemGroup>, IEnumerable <BasePortfolioItemGroupViewModel> >(groupedByStrategies) .ToList(); return(result); }