예제 #1
0
파일: Option.aspx.cs 프로젝트: kiquenet/B4F
    protected void bntSave_Click(object sender, EventArgs e)
    {
        try
        {
            Page.Validate();
            bool valid = Page.IsValid;
            int instrumentID = InstrumentID;
            bool blnSaveSuccess = false;

            if (valid)
            {
                OptionDetails optionDetails = new OptionDetails();

                optionDetails.DerivativeMasterID = DerivativeMasterID;
                optionDetails.InstrumentName = null;
                //optionDetails.ISIN = tbISIN.Text;
                optionDetails.OptionType = (OptionTypes)Convert.ToInt32(rblOptionType.SelectedValue);
                optionDetails.StrikePrice = dbStrikePrice.Value;
                //if (mlvExpiry.ActiveViewIndex == 0)
                    optionDetails.SetExpiryDate(ppExpiry.SelectedPeriod);
                //else
                //    optionDetails.ExpiryDate = ucExpiryDate.SelectedDate;

                InstrumentEditAdapter.SaveOption(ref instrumentID, ref blnSaveSuccess, optionDetails);
                Session["instrumentid"] = instrumentID;
                Response.Redirect("Option.aspx");
            }
        }
        catch (Exception ex)
        {
            elbErrorMessage.Text = Utility.GetCompleteExceptionMessage(ex) + "<br />";
        }
    }
예제 #2
0
        public static void SaveOption(ref int instrumentID, ref bool blnSaveSuccess, OptionDetails optionDetails)
        {
            if (!SecurityManager.IsCurrentUserInRole("Data Mtce: Instrument Edit"))
                throw new System.Security.SecurityException("You are not authorized to update instrument details.");

            IDalSession session = NHSessionFactory.CreateSession();

            try
            {
                Option option = null;
                if (instrumentID != 0)
                    option = (Option)InstrumentMapper.GetTradeableInstrument(session, instrumentID);
                else
                {
                    IDerivativeMaster master = session.GetTypedList<DerivativeMaster, IDerivativeMaster>(optionDetails.DerivativeMasterID).FirstOrDefault();
                    if (master == null)
                        throw new ApplicationException("The derivative master is mandatory.");
                    option = new Option(master);
                }

                if (option == null)
                    throw new ApplicationException("The instrument could not be found.");

                if (option.Master == null)
                    throw new ApplicationException("The turbo needs a master.");

                if (instrumentID == 0 && option.Master.Series != null && option.Master.Series.Count > 0)
                {
                    if ((from a in option.Master.Series.Cast<IOption>()
                         where a.StrikePrice.Quantity == optionDetails.StrikePrice
                         && a.OptionType == optionDetails.OptionType
                         && a.ExpiryDate.Year == optionDetails.ExpiryDate.Year
                         && a.ExpiryDate.Month == optionDetails.ExpiryDate.Month
                         select a).Count() > 0)
                        throw new ApplicationException("This turbo already exists");
                }

                option.OptionType = optionDetails.OptionType;
                option.StrikePrice = new Price(optionDetails.StrikePrice, option.CurrencyNominal, option);
                option.ExpiryDate = optionDetails.ExpiryDate;
                option.Isin = optionDetails.ISIN;
                if (!string.IsNullOrEmpty(optionDetails.InstrumentName))
                    option.Name = optionDetails.InstrumentName;
                else
                {
                    CultureInfo american = new CultureInfo("en-US");

                    option.Name = string.Format("{0} {1} {2} {3}",
                        option.Master.DerivativeSymbol,
                        (option.OptionType == OptionTypes.Call ? "C" : "P"),
                        option.ExpiryDate.ToString("MMM yyyy", american).ToUpper(),
                        option.StrikePrice.Quantity.ToString("F", american));
                }

                if (option.Validate())
                {
                    blnSaveSuccess = InstrumentMapper.Update(session, option);
                    instrumentID = option.Key;
                }
            }
            finally
            {
                session.Close();
            }
        }
예제 #3
0
        public static OptionDetails GetOptionDetails(int instrumentId)
        {
            IDalSession session = NHSessionFactory.CreateSession();
            IOption opt = (IOption)InstrumentMapper.GetTradeableInstrument(session, instrumentId);
            OptionDetails returnValue = new OptionDetails();

            if (opt != null)
            {
                returnValue.Key = opt.Key;
                returnValue.InstrumentName = opt.Name;
                returnValue.ISIN = opt.Isin;
                returnValue.DerivativeMasterID = opt.Master.Key;
                returnValue.OptionType = opt.OptionType;
                returnValue.ExpiryDate = opt.ExpiryDate;
                if (opt.StrikePrice != null && opt.StrikePrice.IsNotZero)
                    returnValue.StrikePrice = opt.StrikePrice.Quantity;
            }
            session.Close();
            return returnValue;
        }