public static object GetEditByID(Guid id) { try { DA_TRN trn = DealUIP.GetByID(id); MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, trn.MA_INSRUMENT.ID); var query = new { ID = trn.ID, TradeDate = trn.TRADE_DATE.HasValue ? trn.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty, SpotDate = trn.SPOT_DATE.HasValue ? trn.SPOT_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty, MaturityDate = trn.MATURITY_DATE.HasValue ? trn.MATURITY_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty, Counterparty = trn.CTPY_ID.ToString(), Portfolio = trn.PORTFOLIO_ID.ToString(), Instrument = trn.INSTRUMENT_ID.ToString(), BuySell = trn.FLAG_BUYSELL, CCY1 = trn.FIRST.CCY_ID.ToString(), SpotRate = trn.FIRST.RATE - (trn.FIRST.SWAP_POINT.HasValue ? trn.FIRST.SWAP_POINT : 0), SwapPoint = trn.FIRST.SWAP_POINT, Remark = trn.REMARK, flag_settle = trn.FLAG_SETTLE, Notional1 = Math.Abs(trn.FIRST.NOTIONAL.Value), Notional2 = Math.Abs(trn.SECOND.NOTIONAL.Value) }; return(new { Result = "OK", record = query, CCY = new { CURRENCY1 = ins.MA_CURRENCY.LABEL, CURRENCY2 = ins.MA_CURRENCY2.LABEL, CURRENCYID1 = ins.MA_CURRENCY.ID, CURRENCYID2 = ins.MA_CURRENCY2.ID, FLAG_MULTIPLY = ins.FLAG_MULTIPLY } }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object GetInstrument(Guid id) { try { MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, id); return(new { Result = "OK", Message = "", CCY = new { CURRENCY1 = ins.MA_CURRENCY.LABEL, CURRENCY2 = ins.MA_CURRENCY2.LABEL, CURRENCYID1 = ins.MA_CURRENCY.ID, CURRENCYID2 = ins.MA_CURRENCY2.ID, FLAG_MULTIPLY = ins.FLAG_MULTIPLY } }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object GetCCYByInstrumentID(Guid id) { try { MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, id); return(new { Result = "OK", record = new { id = ins.MA_CURRENCY.ID.ToString(), label = ins.MA_CURRENCY.LABEL } }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object GetLotSizeByInstrumentID(string ID) { try { MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, new Guid(ID)); if (!ins.LOT_SIZE.HasValue) { return new { Result = "ERROR", Message = "Instrument's lot size is empty." } } ; return(new { Result = "OK", lotsize = ins.LOT_SIZE }); } catch (Exception ex) { return(new { Result = "ERROR", Message = ex.Message }); } }
public static object GetEditByID(Guid id) { try { DA_TRN lastTrn1 = DealUIP.GetByID(id); DA_TRN lastTrn2 = DealUIP.GetFXSwapPair(SessionInfo, lastTrn1.INT_DEAL_NO, lastTrn1.VERSION, lastTrn1.ID); MA_INSTRUMENT ins = InstrumentUIP.GetByID(SessionInfo, lastTrn1.MA_INSRUMENT.ID); var NearLeg = lastTrn1.FLAG_NEARFAR == "N" ? lastTrn1 : lastTrn2; var FarLeg = lastTrn2.FLAG_NEARFAR == "F" ? lastTrn2 : lastTrn1; var query = new { TradeDate = lastTrn1.TRADE_DATE.HasValue ? lastTrn1.TRADE_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty, Counterparty = lastTrn1.CTPY_ID.ToString(), Portfolio = lastTrn1.PORTFOLIO_ID.ToString(), Instrument = lastTrn1.INSTRUMENT_ID.ToString(), ContractCcy = lastTrn1.FIRST.CCY_ID.ToString(), SpotDate = lastTrn1.SPOT_DATE.HasValue ? lastTrn1.SPOT_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty, SpotRate = lastTrn1.FIRST.RATE.Value - lastTrn1.FIRST.SWAP_POINT.Value, BSN = NearLeg.FLAG_BUYSELL, BSF = FarLeg.FLAG_BUYSELL, SetDateN = NearLeg.MATURITY_DATE.HasValue ? NearLeg.MATURITY_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty, SetDateF = FarLeg.MATURITY_DATE.HasValue ? FarLeg.MATURITY_DATE.Value.ToString(FormatTemplate.DATE_DMY_LABEL) : string.Empty, SwapPoitN = NearLeg.FIRST.SWAP_POINT, SwapPoitF = FarLeg.FIRST.SWAP_POINT, ContAmtN = Math.Abs(NearLeg.FIRST.NOTIONAL.Value), CountAmtN = Math.Abs(NearLeg.SECOND.NOTIONAL.Value), ContAmtF = Math.Abs(FarLeg.FIRST.NOTIONAL.Value), CountAmtF = Math.Abs(FarLeg.SECOND.NOTIONAL.Value), flag_settle = lastTrn1.FLAG_SETTLE, }; return(new { Result = "OK", record = query, productid2 = lastTrn2.ID.ToString(), CCY = new { CURRENCY1 = ins.MA_CURRENCY.LABEL, CURRENCY2 = ins.MA_CURRENCY2.LABEL, CURRENCYID1 = ins.MA_CURRENCY.ID, CURRENCYID2 = ins.MA_CURRENCY2.ID, FLAG_MULTIPLY = ins.FLAG_MULTIPLY } }); } catch (Exception ex) { 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 }); } }