public static object UpdateTBMAConfig(SessionInfo sessioninfo, MA_TBMA_CONFIG record) { try { LookupBusiness _lookupbusiness = new LookupBusiness(); var updated = _lookupbusiness.UpdateTBMAConfig(sessioninfo, record); return(new { Result = "OK" }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public MA_TBMA_CONFIG GetTBMAConfig(SessionInfo sessioninfo) { try { MA_TBMA_CONFIG query = new MA_TBMA_CONFIG(); using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { query = unitOfWork.MA_TBMA_CONFIGRepository.All().FirstOrDefault(); } return(query); } catch (DataServicesException ex) { throw this.CreateException(ex, null); } }
public static object SendFIReport(SessionInfo sessioninfo, string IDs) { try { string[] TrnsID = IDs.Split(','); DealBusiness _dealBusiness = new DealBusiness(); LookupBusiness _lookupBusiness = new LookupBusiness(); MA_TBMA_CONFIG config = _lookupBusiness.GetTBMAConfig(sessioninfo); Guid productID = _lookupBusiness.GetProductAll().FirstOrDefault(p => p.LABEL == ProductCode.BOND.ToString()).ID; List <DA_TRN> trns = _dealBusiness.GetDealInternalByProcessDate(sessioninfo.Process.CurrentDate) .Where(a => a.PRODUCT_ID.Value == productID && TrnsID.Contains(a.ID.ToString()) && a.DA_TMBA_EXTENSION.SEND_DATE == null).ToList(); var validateTBMA_NAME = (from o1 in trns where string.IsNullOrEmpty(o1.MA_COUTERPARTY.TBMA_NAME) select o1.MA_COUTERPARTY.SNAME).Distinct().ToArray(); //verify required info if (validateTBMA_NAME.Length > 0) { throw CreateException(new Exception(), "TBMA_NAME can't be empty. Please input TBMA_NAME on counterparty " + string.Join(",", validateTBMA_NAME)); } if (config == null) { throw CreateException(new Exception(), "Cannot get configurations. Please contact administrator"); } foreach (DA_TRN trn in trns) { _dealBusiness.CreatingTBMAReportFile(sessioninfo, trn, config); } Guid[] TrnsIDSend = trns.Select(t => t.ID).ToArray(); _dealBusiness.UpdateFISendReport(sessioninfo, TrnsIDSend); return(new { Result = "OK", Message = String.Format("Sending report completed") }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public MA_TBMA_CONFIG UpdateTBMAConfig(SessionInfo sessioninfo, MA_TBMA_CONFIG config) { using (EFUnitOfWork unitOfWork = new EFUnitOfWork()) { var foundConfig = unitOfWork.MA_TBMA_CONFIGRepository.All().FirstOrDefault(p => p.ID == config.ID); if (foundConfig == null) { throw this.CreateException(new Exception(), Messages.DATA_NOT_FOUND); } else { foundConfig.TBMA_CAL_PASSWORD = config.TBMA_CAL_PASSWORD; foundConfig.TBMA_CAL_USERNAME = config.TBMA_CAL_USERNAME; foundConfig.TBMA_RPT_PATH = config.TBMA_RPT_PATH; foundConfig.TBMA_RPT_PREFIX = config.TBMA_RPT_PREFIX; foundConfig.TBMA_RPT_TRADERID = config.TBMA_RPT_TRADERID; unitOfWork.Commit(); } } return(config); }
public static object CallTBMA(string instrumentid, string setdate, double yield, double cprice, string ytype, bool y2p) { try { MA_TBMA_CONFIG config = LookupUIP.GetTBMAConfig(SessionInfo); string username, userpassword, token, Key, ErrorMessage; username = config.TBMA_CAL_USERNAME; userpassword = config.TBMA_CAL_PASSWORD; MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, new Guid(instrumentid)); if (ins == null) { throw new Exception("Instrument is not found"); } LoggingHelper.Info("TBMA Calculation Service has been called by " + SessionInfo.UserLogon); //Step 1 Create new instant object ThaiBMACalc.ThaiBMA_Claculation_Service calc = new ThaiBMACalc.ThaiBMA_Claculation_Service(); //Service Object ThaiBMACalc.BondFactor BF = new ThaiBMACalc.BondFactor(); //input object ThaiBMACalc.AuthenHeader header = new ThaiBMACalc.AuthenHeader(); //authen object //Step 2 Get token Authen.ThaiBMA_Calculation_Auth authen = new Authen.ThaiBMA_Calculation_Auth(); token = authen.GetToken(username); //Step 3 Get Key for access Key = GetKey.getKeyLogin(token, username, userpassword); header.key = Key; header.username = username; //Step 4 Set auhen value calc.AuthenHeaderValue = header; //Step 5 Set input value to object BF.Symbol = ins.LABEL; BF.SettlementDate = DateTime.ParseExact(setdate, "dd/MM/yyyy", null); BF.TradeDateAndTime = System.DateTime.Now; BF.Yield = yield; BF.Percent_Price = cprice; BF.isYield2Price = y2p; BF.isCallPutOption = false; BF.Unit = 1; BF.PriceType = ThaiBMACalc.PriceType.Clean; if (ins.LABEL.StartsWith("ILB")) { BF.isILB = true; } if (ytype == "DM") { BF.YieldType = ThaiBMACalc.YieldType.DM; } else { BF.YieldType = ThaiBMACalc.YieldType.YTM; } //Step 6 Call calc method ThaiBMACalc.CalculationOutput result = calc.BondCalculation(BF); ThaiBMACalc.ServiceError sresult = (ThaiBMACalc.ServiceError)result.ServiceResult; //Error while calling service if (sresult != null && !sresult.Result) { ErrorMessage = sresult.ErrorMessage; string ErrorNo = sresult.ErrorNo; bool rtn = sresult.Result; string attime = sresult.TimeStamp.ToString(); LoggingHelper.Error("ThaiBMA service is fail. " + ErrorMessage); return(new { Result = "ERROR", Message = "ThaiBMA service is fail. " + ErrorMessage }); } if ((result.CalcError == null) && (result.CalcResult != null)) { ThaiBMACalc.CalcResult myResult = (ThaiBMACalc.CalcResult)result.CalcResult; //Calculation Result double RGrossPrice = 0; double RCleanPrice = 0; double RYield = 0; if (myResult.Symbol.StartsWith("ILB")) { RCleanPrice = (double)myResult.Percent_Unadjusted_CleanPrice; RYield = (double)myResult.Percent_RealYield; RGrossPrice = (double)myResult.Percent_Unadjusted_GrossPrice; } else { RYield = ytype == "DM" ? (double)myResult.Percent_DM : (double)myResult.Percent_Yield; RCleanPrice = (double)myResult.Percent_CleanPrice; RGrossPrice = (double)myResult.Percent_GrossPrice; } return(new { Result = "OK", gprice = RGrossPrice, cprice = RCleanPrice, yield = RYield }); //.... and more } else { Type error = result.CalcError.GetType(); IList <PropertyInfo> props = new List <PropertyInfo>(error.GetProperties()); string errmsg = string.Join(",", props.Where(p => p.GetValue(result.CalcError, null).ToString() != "").Select(p => p.GetValue(result.CalcError, null)).ToList()); LoggingHelper.Error("ThaiBMA Caculation is fail. " + errmsg); return(new { Result = "ERROR", Message = "ThaiBMA Caculation is fail. " + errmsg }); } } catch (Exception ex) { LoggingHelper.Error("ThaiBMA service is fail. " + ex.Message); return(new { Result = "ERROR", Message = ex.Message }); } }
public static object Update(MA_TBMA_CONFIG record) { return(LookupUIP.UpdateTBMAConfig(SessionInfo, record)); }