public List <int> GetPositions(int folioId, PositionsToRequest positions)
        {
            var       results = new List <int>();
            Exception ex      = null;

            _context.Send(state => {
                using (var portfolio = CSMPortfolio.GetCSRPortfolio(folioId))
                {
                    if (portfolio is object)
                    {
                        if (!portfolio.IsLoaded())
                        {
                            ex = new PortfolioNotLoadedException();
                            return;
                        }

                        GetPositionsUI(folioId, positions, results);
                    }
                    else
                    {
                        ex = new PortfolioNotFoundException();
                        return;
                    }
                }
            }, null);

            if (ex == null)
            {
                return(results);
            }
            else
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
    public override void GetCell(CSMAccpostingData data, ref SSMCellValue value, SSMCellStyle style)
    {
        var    postingData = data.GetAccPosting();
        int    tradeId = 0, accountNameId = 0;
        int    REVALUATION = 11, IDB_NOSTRO = 33528;
        String strValue = "Could Not Get Value", tempString;

        style.kind = eMDataType.M_dNullTerminatedString;

        if (postingData != null)
        {
            if (postingData.fPostingType == REVALUATION)
            {
                CSMPosition pos = CSMPosition.GetCSRPosition(postingData.fPositionID);
                if (pos != null)
                {
                    CSMPortfolio port = pos.GetPortfolio();
                    if (port != null)
                    {
                        CSMAmFund fund = CSMAmFund.GetFundFromFolio(port);                          //GetHedgeFund()
                        if (fund != null)
                        {
                            strValue = GetAccountBookNameForFund(fund);
                        }
                    }
                }
            }
            else
            {
                accountNameId = postingData.fAccountNameID;
                tradeId       = postingData.fTradeID;

                if (tradeId != 0 && accountNameId != 0)
                {
                    if (accountNameId == IDB_NOSTRO)
                    {
                        strValue = GetNostroIDBAccountBook(postingData.fNostroAccountID, postingData.fAccountNumber);
                    }
                    else
                    {
                        tempString = CSxDataFacade.GetAccountBookName(postingData.fAccountingBookID);
                        if (tempString != null)
                        {
                            strValue = tempString.Substring(0, Math.Min(4, tempString.Length));
                        }
                    }
                }
            }
        }
        value.SetString(strValue);
    }
        private void GetPositionsUI(int folioId, PositionsToRequest positions, List <int> results)
        {
            using (var portfolio = CSMPortfolio.GetCSRPortfolio(folioId))
            {
                int positionCount = portfolio.GetTreeViewPositionCount();
                for (int i = 0; i < positionCount; i++)
                {
                    using (var position = portfolio.GetNthTreeViewPosition(i))
                    {
                        if (position.GetIdentifier() > 0) //Exclude Virtual FX positions
                        {
                            switch (positions)
                            {
                            case PositionsToRequest.All:
                                results.Add(position.GetIdentifier());
                                break;

                            case PositionsToRequest.Open:
                                if (position.GetInstrumentCount() != 0)
                                {
                                    results.Add(position.GetIdentifier());
                                }
                                break;
                            }
                        }
                    }
                }

                int childPortfolioCount = portfolio.GetChildCount();

                for (int i = 0; i < childPortfolioCount; i++)
                {
                    using (var childPortfolio = portfolio.GetNthChild(i))
                    {
                        GetPositionsUI(childPortfolio.GetCode(), positions, results);
                    }
                }
            }
        }
        private void ComputePortfolios(int skipPortfolio)
        {
            var portfolios = new HashSet <int>();

            foreach (var c in _portfolioSubscriptions.GetCells())
            {
                if (c.Portfolio is object)
                {
                    portfolios.Add(c.FolioId);
                }
            }

            foreach (var c in _positionSubscriptions.GetCells())
            {
                if (c.Position is object)
                {
                    portfolios.Add(c.Position.GetPortfolioCode());
                }
            }

            int FindRootLoadedPortfolio(CSMPortfolio portfolio)
            {
                var parentCode = portfolio.GetParentCode();

                using (var parentPortfolio = CSMPortfolio.GetCSRPortfolio(parentCode))
                {
                    if (parentPortfolio.IsLoaded())
                    {
                        return(FindRootLoadedPortfolio(parentPortfolio));
                    }
                    else
                    {
                        return(portfolio.GetCode());
                    }
                }
            }

            var rootPortfolios = new HashSet <int>();

            foreach (var id in portfolios)
            {
                using (var portfolio = CSMPortfolio.GetCSRPortfolio(id))
                {
                    if (portfolio.IsLoaded())
                    {
                        rootPortfolios.Add(FindRootLoadedPortfolio(portfolio));
                    }
                }
            }

            foreach (var id in rootPortfolios)
            {
                if (id == skipPortfolio)
                {
                    continue;
                }

                using (var portfolio = CSMPortfolio.GetCSRPortfolio(id))
                {
                    _computeCount++;

                    portfolio.Compute();
                }
            }

            _dataRefreshRequests++;
        }
 public PortfolioCellValue(int folioId, string column) : base(column)
 {
     FolioId   = folioId;
     Portfolio = CSMPortfolio.GetCSRPortfolio(folioId);
 }
Ejemplo n.º 6
0
        public override void GetCell(CSMAccPostingData data, ref SSMCellValue value, SSMCellStyle style)
        {
            using (var log = LogHelper.GetLogger(GetType().Name, MethodBase.GetCurrentMethod().Name))
            {
                style.kind = eMDataType.M_dNullTerminatedString;

                var accountData = data.GetAccPosting();
                var tradeId     = accountData.fTradeID;
                var accountId   = 0;



                SSMFinalPosting _fPosting = data.GetAccPosting();
                if (_fPosting != null)
                {
                    accountId = _fPosting.fAccountNameID;
                    if (_fPosting.fPostingType == 11)
                    {
                        CSMPosition pos = CSMPosition.GetCSRPosition(_fPosting.fPositionID);
                        if (pos != null)
                        {
                            CSMPortfolio port = pos.GetPortfolio();
                            if (port != null)
                            {
                                CSMAmFund fund = CSMAmFund.GetFundFromFolio(port);
                                if (fund != null)
                                {
                                    string accountBookName = GetAccountBookNameForFund(fund);
                                    value.SetString(accountBookName);
                                    return;
                                }
                            }
                        }
                        return;
                    }
                }

                if (tradeId == 0 || accountId == 0)
                {
                    return;
                }

                CSMTransaction trade = CSMTransaction.newCSRTransaction(tradeId);
                if (trade == null)
                {
                    return;
                }

                //Business Event
                int type = (int)trade.GetTransactionType();

                //Any Posting linked to the IDB Group should have account book 1000
                if (_fPosting.fAccountNameID == 33528)
                {
                    value.SetString(GetNostroIDBAccountBook(_fPosting.fID));
                    return;
                }
                int PostingId = _fPosting.fID;
                int NostroId  = _fPosting.fNostroAccountID;
                if (NostroId > 0)
                {
                    int EntityId = 0;
                    if (fDataLoaded == false)
                    {
                        LoadAccountEntities();
                    }
                    fNostroAndEntity.TryGetValue(NostroId, out EntityId);
                    if (IsIDBGroupEntity(EntityId))
                    {
                        value.SetString("1000");
                        return;
                    }
                }

                var cacheKey = string.Format("AccountBook_{0}", accountData.fID);
                var strValue = CacheManager.GetItem <string>(cacheKey);

                try
                {
                    if (!string.IsNullOrEmpty(strValue))
                    {
                        value.SetString(strValue);
                        return;
                    }

                    //if value is not cached already we loaded it
                    strValue = CSxDataFacade.GetAccountBookName(accountData.fAccountingBookID);



                    //Filter on the account defined in the config file
                    if (CSxIslamicInstrumentsHelperCLI.IsForbiddenAccountId(accountId))
                    {
                        var parentId = 0;
                        try
                        {
                            //parentId = CSxIslamicInstrumentsHelperCLI.GetParentTrade(tradeId);

                            //couponS and redemption sukuk are not taken in account in this function
                            parentId = CSxIdbTradeId.GetParentIDBMergingAllocatedTrade(type, tradeId);
                        }
                        catch (Exception)
                        {
                            log.WriteSystemError("Failed to check if tarde is merged");
                        }
                        // AccountExceptions.Contains(accountData.fAccountingBookID)
                        //FILTER on merged trades
                        if (parentId != 0)
                        {
                            try
                            {
                                var t = CSMTransaction.newCSRTransaction(tradeId);
                                if (t == null)
                                {
                                    throw new Exception("Failed to open trade");
                                }

                                var fid = 0;
                                //if(CSxIslamicInstrumentsHelperCLI.IsInterFundCashTransferBusinessEvent(type))
                                //{
                                //    var tr = CSMTransaction.newCSRTransaction(parentId);
                                //    if (tr == null)
                                //        throw new Exception("Failed to open trade");

                                //    fid = CSxIslamicInstrumentsHelperCLI.GetFundForEntity(tr.GetEntity());
                                //}
                                //else
                                //{
                                fid = CSxIslamicInstrumentsHelperCLI.GetFundForEntity(t.GetEntity());
                                //}


                                CSMAmFund f = CSMInstrument.GetInstance(fid);
                                if (f == null)
                                {
                                    throw new Exception("Failed to find fund for settlement entity");
                                }
                                strValue = CSxDataFacade.GetAccountBookIdForFolio(f.GetTradingPortfolio());
                            }
                            catch (Exception e)
                            {
                                log.WriteSystemError("Failed to get Account Book Id from Settlement Entity for merged trade {0} : {1}", tradeId, e.Message);
                            }
                        }
                        //if (strValue != null)
                        //{
                        //    //strValue = strValue.Substring(0, Math.Min(4, strValue.Length));
                        //    //we cache the value for next time
                        //    CacheManager.SetItem(cacheKey, strValue);

                        //}
                    }

                    if (strValue != null)
                    {
                        strValue = strValue.Substring(0, Math.Min(4, strValue.Length));
                        value.SetString(strValue);
                    }
                }
                catch (Exception e)
                {
                    log.WriteSystemError("Failed to get Account Book Name for trade {0} : {1}", tradeId, e.Message);

                    if (IDB.IslamicInstruments.CSxIslamicInstrumentsHelperCLI.IsInGUIMode())
                    {
                        MessageBox.Show("Failed to get Account Book Name for trade " + tradeId + " Error:" + e.Message);
                    }
                }
            }
        }
 public override object GetValue()
 {
     return(CSMPortfolio.GetPortfolioDate().GetDateTime());
 }
        public bool FetchDataFromCellsMisys(object objCommand, ref object objResult, ref object objError)
        {
            Logger.logBegin("FetchDataFromCellsMisys");

            const string cnst_CONDITION = "CONDITION:";
            string       strCommand     = objCommand == null ?  null : objCommand.ToString();

            try
            {
                if (string.IsNullOrEmpty(strCommand))
                {
                    throw new Exception("objCommand should not be NULL or empty");
                }

                /** check Command **/

                /*  ' format :
                 *  '   ROWS_LIMIT:0:0;Code/Name
                 *  '   ALLROWS;ColumnsName
                 *  '   CONDITION:COLUMN=A;ColumnName;NOSUB, Example: CONDITION:0=@FO_test;Income;NOSUB
                 *  '       NOSUB means don't get all sub information, other wise get all sub expanded rows
                 * */
                if (!TigerMarsUtil.RegularTest("^CONDITION:", strCommand))
                {
                    throw new Exception(string.Format("No supported Command, [{0}]", strCommand));
                }
                //objReflect.GetMember<object>(objDataSrcTmp,"")

                if (TigerMarsUtil.RegularTest("^" + cnst_CONDITION, strCommand))
                {
                    #region CONDITION MODE
                    //CONDITION:COLUMN=A;ColumnName;NOSUB, Example: CONDITION:0=@FO_test;Income;NOSUB
                    if (!TigerMarsUtil.RegularTest(@"CONDITION:\S+=\S{1,};\b\w+\b(;NOSUB){0,1}", strCommand))
                    {
                        objError = string.Format("RC should match CONDITION:\\b\\w+\\b=\\w+;\\b\\w+\\b(;NOSUB), Command:{0}", strCommand);
                        Logger.Error("FetchDataFromCellsMisys", (string)objError);
                        return(false);
                    }

                    string   strCmdNoHeader = strCommand.Replace(cnst_CONDITION, "");
                    string[] arrTargetField = strCmdNoHeader.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                    string   strTargetField = arrTargetField[1];
                    string[] arrCondition   = arrTargetField[0].Split(new string[] { "=" }, StringSplitOptions.RemoveEmptyEntries);

                    TreeList objTr = (TreeList)base.SourceControl;

                    CustomTreeList     objCTrlst     = (CustomTreeList)objTr;
                    object             objDataSrcTmp = objCTrlst.DataSource;
                    ReflectorForCSharp objReflect    = new ReflectorForCSharp();
                    CSMPortfolio       objPortC      = null;
                    CSMPosition        objPortCsub   = null;
                    //object objPortfolio = objReflect.GetMember<object>(objDataSrcTmp, "Portfolio");
                    //CSMPortfolio objPortC = (CSMPortfolio)objPortfolio;
                    //double dIncome = objPortC.GetIncome();
                    object         tmpData = objReflect.GetMember <object>(objTr, "Data");
                    UnboundData    unData = (UnboundData)tmpData;
                    VirtualDataRow objVDataRow = null;
                    bool           isFind = false;
                    string         strHeadName = "";
                    int            iLevel = -1;
                    double         dDat = 0.00;
                    string         strResult = "", strTmp = "";
                    for (int i = 0; i < unData.DataList.Count; i++)
                    {
                        objVDataRow = (VirtualDataRow)unData.DataList[i];
                        objPortC    = (CSMPortfolio)(objReflect.GetMember <object>(objVDataRow.VirtualNode, "Portfolio"));
                        iLevel      = objPortC.GetLevel();
                        if ((iLevel <= 1) && (isFind))
                        {
                            break;
                        }
                        strHeadName = objPortC.GetName() == null?"":objPortC.GetName().ToString();
                        if (!isFind)
                        {
                            /** Only the root level can be taken as comparison node **/
                            if (iLevel != 1)
                            {
                                continue;
                            }
                            if (!TigerMarsUtil.RegularTest(arrCondition[1], strHeadName))
                            {
                                continue;
                            }
                            else
                            {
                                isFind = true;
                            }
                        }

                        switch (strTargetField.ToUpper())
                        {
                        case "INCOME":
                            dDat   = objPortC.GetIncome() * 1000;
                            strTmp = dDat.ToString("0.");
                            break;

                        case "NAV":
                            dDat   = objPortC.GetNetAssetValue() * 1000;
                            strTmp = dDat.ToString("0.");
                            break;

                        case "RESULT":
                            dDat   = objPortC.GetResult() * 1000;
                            strTmp = dDat.ToString("0.");
                            break;

                        case "REALIZED":
                            dDat   = objPortC.GetRealised() * 1000;
                            strTmp = dDat.ToString("0.");
                            break;

                        case "BALANCE":
                            dDat   = objPortC.GetBalance() * 1000;
                            strTmp = dDat.ToString("0.");
                            break;

                        default:
                            throw new Exception(string.Format("Not supported field :[{0}]", strTargetField));
                        }
                        if (string.IsNullOrEmpty(strResult))
                        {
                            strResult = string.Format("[{0}{1}]", strHeadName, FormatStrWithTab(0, strTmp));
                        }
                        else
                        {
                            strResult = string.Format("{0}\n\r{1}", strResult, string.Format("[{0}{1}]", strHeadName, FormatStrWithTab(0, strTmp)));
                        }

                        for (int j = 0; j < objVDataRow.Children.Count; j++)
                        {
                            //objVDataRow.Children[j];
                            objPortCsub = (CSMPosition)objReflect.GetMember <object>(objVDataRow.Children[j], "Position");
                            strHeadName = objVDataRow.Children[j].ToString();
                            if (objPortCsub == null)
                            {
                                continue;
                            }
                            switch (strTargetField.ToUpper())
                            {
                            case "INCOME":
                                dDat   = objPortCsub.GetIncome() * 1000;
                                strTmp = dDat.ToString("0.");
                                break;

                            case "NAV":
                                dDat   = objPortCsub.GetNetAssetValue() * 1000;
                                strTmp = dDat.ToString("0.");
                                break;

                            case "RESULT":
                                dDat   = objPortCsub.GetResult() * 1000;
                                strTmp = dDat.ToString("0.");
                                break;

                            case "REALIZED":
                                dDat   = objPortCsub.GetRealised() * 1000;
                                strTmp = dDat.ToString("0.");
                                break;

                            case "BALANCE":
                                dDat   = objPortCsub.GetBalance() * 1000;
                                strTmp = dDat.ToString("0.");
                                break;

                            default:
                                throw new Exception(string.Format("Not supported field :[{0}]", strTargetField));
                            }
                            strResult = string.Format("{0}\n\r{1}", strResult, string.Format("[{0}    {1}]", strHeadName, FormatStrWithTab(0, strTmp)));
                        }
                        break;
                    }
                    objResult = strResult;
                    return(true);

                    #endregion //CONDTION MODE
                }

                objError = string.Format("Unsupported Command formatter:[{0}]", strCommand);
                return(false);
            }
            catch (Exception e)
            {
                objError = e.Message;
                Logger.Error("FetchDataFromCellsMisys", string.Format("Errors come across. Exception:[{0}]", e.Message), e);
                return(false);
            }
            finally
            {
                Logger.logEnd("FetchDataFromCellsMisys");
            }
        }