Beispiel #1
0
        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 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 };
            }
        }