private bool InnerLoginAndAuthenticate(string userName, string password, ExchangeSystem exchangeSystem, bool authenticateOnly, out Guid userID, out string errorMsg)
        {
            try
            {
                ParticipantServices.ParticipantServices participantServices = (ParticipantServices.ParticipantServices)Application["ParticipantServices"];
                userID = participantServices.Login(userName, password);
                if (userID == Guid.Empty)
                {
                    errorMsg = "User name not exists or password is invalid.";
                    return(false);
                }

                SecurityServices.SecurityServices securityServices = (SecurityServices.SecurityServices)Application["SecurityServices"];
                Guid programID    = new Guid(ConfigurationSettings.AppSettings["DealingConsole"]);
                Guid permissionID = new Guid(ConfigurationSettings.AppSettings["Run"]);
                bool isAuthrized  = securityServices.CheckPermission(userID, programID, permissionID, "", "", userID, out errorMsg);
                if (isAuthrized == false)
                {
                    userID = Guid.Empty;
                    return(false);
                }

                Token token = new Token(userID, UserType.System, AppType.DealingConsole);
                token.SessionID       = this.Context.Session.SessionID;
                token.ExchangeSystem  = exchangeSystem;
                this.Session["Token"] = token;
                bool success = this.StateServer.Login(token);
                if (success == false)
                {
                    userID   = Guid.Empty;
                    errorMsg = "Login to stateServer failure.";
                    return(false);
                }

                if (!authenticateOnly)
                {
                    FormsAuthentication.SetAuthCookie(userID.ToString(), false);

                    //Prevent be kickout
                    Hashtable sessionIDs = (Hashtable)this.Context.Application["SessionIDs"];
                    sessionIDs         = Hashtable.Synchronized(sessionIDs);
                    sessionIDs[userID] = this.Context.Session.SessionID;
                }

                return(true);
            }
            catch (Exception exception)
            {
                AppDebug.LogEvent("DealingConsole", exception.ToString(), EventLogEntryType.Error);
                throw;
            }
        }
Example #2
0
    /// <summary>
    /// Gets the current exchange rate of USD and RMB and converts according to the selection given.
    /// </summary>
    /// <param name="inputValue"></param>
    private async void GetExchangeResult(double inputValue)
    {
        ExchangeSystem eSystem = new ExchangeSystem();
        ExchangeRate   eRate   = await eSystem.GetExchangeRate();

        if (conversionSelection == 1)
        {
            double newUSD = Math.Round((eRate.rates.USD / eRate.rates.CNY) * inputValue, 3);
            double newCNY = Math.Round((eRate.rates.CNY / eRate.rates.CNY) * inputValue, 3);
            string result = $"{newCNY}RMB : {newUSD}USD";
            NewResult?.Invoke(this, new ResultModel(result));
        }
        else if (conversionSelection == 0)
        {
            double newUSD = Math.Round((eRate.rates.USD / eRate.rates.USD) * inputValue, 3);
            double newCNY = Math.Round((eRate.rates.CNY / eRate.rates.USD) * inputValue, 3);
            string result = $"{newUSD}USD : {newCNY}RMB";
            NewResult?.Invoke(this, new ResultModel(result));
        }
        else
        {
            return;
        }
    }
Example #3
0
        public Instrument(DataRow instrumentRow)
        {
            this.id = (Guid)instrumentRow["ID"];
            this.code = (string)instrumentRow["Code"];
            this.originCode = (string)instrumentRow["OriginCode"];
            this.numeratorUnit = (int)instrumentRow["NumeratorUnit"];
            this.denominator = (int)instrumentRow["Denominator"];
            this.isSinglePrice = (bool)instrumentRow["IsSinglePrice"];
            this.originType = (OriginType)(byte)instrumentRow["OriginType"];
            this.alertVariation = (int)instrumentRow["AlertVariation"];
            this.normalWaitTime = (int)instrumentRow["NormalWaitTime"];
            this.alertWaitTime = (int)instrumentRow["AlertWaitTime"];
            this.isActive = (bool)instrumentRow["IsActive"];

            this.originInactiveTime = (int)instrumentRow["OriginInactiveTime"];
            this.isPriceEnabled = (bool)instrumentRow["IsPriceEnabled"];
            this.isAutoEnablePrice = (bool)instrumentRow["IsAutoEnablePrice"];
            if (instrumentRow["ExternalExchangeCode"] != DBNull.Value)
            {
                this.exchangeSystem = (ExchangeSystem)Enum.Parse(typeof(ExchangeSystem), (string)(instrumentRow["ExternalExchangeCode"]), true);
            }
            else
            {
                this.exchangeSystem = ExchangeSystem.Local;
            }
            this.lastPriceEnabledTime = this.isPriceEnabled ? DateTime.Now : DateTime.MinValue;

            this.originQReceived = null;
            this.originQProcessed = null;
            this.quotePolicyDetails = new ArrayList();
            this.isTrading = false;
            this.scheduleID = null;
            this.lastOrigin = null;
        }
Example #4
0
        public Instrument(XmlNode instrument)
        {
            this.id = XmlConvert.ToGuid(instrument.Attributes["ID"].Value);
            this.originCode = instrument.Attributes["OriginCode"].Value;
            this.code = instrument.Attributes["Code"].Value;
            this.numeratorUnit = XmlConvert.ToInt32(instrument.Attributes["NumeratorUnit"].Value);
            this.denominator = XmlConvert.ToInt32(instrument.Attributes["Denominator"].Value);
            this.isSinglePrice = XmlConvert.ToBoolean(instrument.Attributes["IsSinglePrice"].Value);
            this.originType = (OriginType)XmlConvert.ToByte(instrument.Attributes["OriginType"].Value);
            this.alertVariation = XmlConvert.ToInt32(instrument.Attributes["AlertVariation"].Value);
            this.normalWaitTime = XmlConvert.ToInt32(instrument.Attributes["NormalWaitTime"].Value);
            this.alertWaitTime = XmlConvert.ToInt32(instrument.Attributes["AlertWaitTime"].Value);
            this.isActive = XmlConvert.ToBoolean(instrument.Attributes["IsActive"].Value);

            this.originInactiveTime = XmlConvert.ToInt32(instrument.Attributes["OriginInactiveTime"].Value);
            this.isPriceEnabled = XmlConvert.ToBoolean(instrument.Attributes["IsPriceEnabled"].Value);
            this.isAutoEnablePrice = XmlConvert.ToBoolean(instrument.Attributes["IsAutoEnablePrice"].Value);
            if (instrument.Attributes["ExternalExchangeCode"] != null)
            {
                this.exchangeSystem = (ExchangeSystem)Enum.Parse(typeof(ExchangeSystem), instrument.Attributes["ExternalExchangeCode"].Value);
            }
            this.lastPriceEnabledTime = this.isPriceEnabled ? DateTime.Now : DateTime.MinValue;

            this.originQReceived = null;
            this.originQProcessed = null;
            this.quotePolicyDetails = new ArrayList();
            this.isTrading = false;
            this.scheduleID = null;
            this.lastOrigin = null;
        }
Example #5
0
        internal Instrument(IDBRow instrumentRow)
        {
            this._id         = (Guid)instrumentRow["ID"];
            this._currencyId = (Guid)instrumentRow["CurrencyID"];
            this._code       = (string)instrumentRow["Code"];
            _originCode      = instrumentRow.GetColumn <string>("OriginCode");

            this._isActive           = instrumentRow.GetColumn <bool>("IsActive");
            this._lastAcceptTimeSpan = instrumentRow.GetColumn <int>("LastAcceptTimeSpan");
            this._orderTypeMask      = instrumentRow.GetColumn <int>("OrderTypeMask");
            this._mit = instrumentRow.GetColumn <bool>("MIT");

            this.AutoAcceptMaxLot = instrumentRow.GetColumn <decimal>("AutoAcceptMaxLot");
            this.AutoCancelMaxLot = instrumentRow.GetColumn <decimal>("AutoCancelMaxLot");
            this._isAutoFill      = instrumentRow.GetColumn <bool>("IsAutoFill");

            this._maxMinAdjust = instrumentRow.GetColumn <int>("MaxMinAdjust");

            this._interestFormula  = (InterestFormula)instrumentRow.GetColumn <byte>("InterestFormula");
            this._interestYearDays = instrumentRow.GetColumn <int>("InterestYearDays");
            this._useSettlementPriceForInterest = instrumentRow.GetColumn <bool>("UseSettlementPriceForInterest");
            this.InactiveTime = instrumentRow.GetColumn <int>("OriginInactiveTime");

            this._isBetterPrice    = instrumentRow.GetColumn <bool>("IsBetterPrice");
            this._hitTimes         = instrumentRow.GetColumn <short>("HitTimes");
            this._penetrationPoint = instrumentRow.GetColumn <int>("PenetrationPoint");

            this._isPriceEnabled = instrumentRow.GetColumn <bool>("IsPriceEnabled");

            this.SpotPaymentTime = instrumentRow.GetColumn <DateTime?>("SpotPaymentTime");

            this._canPlacePendingOrderAtAnyTime = instrumentRow.GetColumn <bool>("CanPlacePendingOrderAtAnyTime");
            this._allowedSpotTradeOrderSides    = (AllowedOrderSides)instrumentRow.GetColumn <byte>("AllowedSpotTradeOrderSides");

            this.HitPriceVariationForSTP = instrumentRow.GetColumn <int>("HitPriceVariationForSTP");

            if (instrumentRow.ExistsColumn("ExternalExchangeCode"))
            {
                if (instrumentRow["ExternalExchangeCode"] != DBNull.Value)
                {
                    this._exchangeSystem = (ExchangeSystem)Enum.Parse(typeof(ExchangeSystem), (string)(instrumentRow["ExternalExchangeCode"]), true);
                }
            }

            this.AutoDQDelay      = TimeSpan.FromSeconds(instrumentRow.GetColumn <Int16>("AutoDQDelay"));
            this._summaryQuantity = instrumentRow.GetColumn <decimal>("SummaryQuantity");
            this.PLValueDay       = instrumentRow.GetColumn <Int16>("PLValueDay");

            if (instrumentRow.ExistsColumn("UseAlertLevel4WhenClosed"))
            {
                this.UseAlertLevel4WhenClosed = instrumentRow["UseAlertLevel4WhenClosed"] == DBNull.Value ? false : (bool)instrumentRow["UseAlertLevel4WhenClosed"];
            }
            if (instrumentRow.ExistsColumn("HolidayAlertDayPolicyID"))
            {
                Guid policyId = Guid.Empty;
                if (Guid.TryParse(instrumentRow["HolidayAlertDayPolicyID"].ToString(), out policyId))
                {
                    this.HolidayAlertDayPolicyId = policyId;
                }
            }
            if (instrumentRow.ExistsColumn("AcceptIfDoneVariation"))
            {
                this._acceptIfDoneVariation = instrumentRow.GetColumn <int>("AcceptIfDoneVariation");
            }
            if (instrumentRow.Contains("PlaceSptMktTimeSpan"))
            {
                _placeSptMktTimeSpan = TimeSpan.FromSeconds((int)instrumentRow["PlaceSptMktTimeSpan"]);
            }

            if (instrumentRow.Contains("FirstOrderTime"))
            {
                _firstOrderTime = (int)instrumentRow["FirstOrderTime"];
            }

            this.Update(instrumentRow);
        }
 public bool Authenticate(string userName, string password, ExchangeSystem exchangeSystem, out Guid userID, out string errorMsg)
 {
     return(this.InnerLoginAndAuthenticate(userName, password, exchangeSystem, true, out userID, out errorMsg));
 }
 public bool Authenticate(string userName, string password, ExchangeSystem exchangeSystem, out Guid userID, out string errorMsg)
 {
     return this.InnerLoginAndAuthenticate(userName, password, exchangeSystem, true, out userID, out errorMsg);
 }
        private bool InnerLoginAndAuthenticate(string userName, string password, ExchangeSystem exchangeSystem, bool authenticateOnly, out Guid userID, out string errorMsg)
        {
            try
            {
                ParticipantServices.ParticipantServices participantServices = (ParticipantServices.ParticipantServices)Application["ParticipantServices"];
                userID = participantServices.Login(userName, password);
                if (userID == Guid.Empty)
                {
                    errorMsg = "User name not exists or password is invalid.";
                    return false;
                }

                SecurityServices.SecurityServices securityServices = (SecurityServices.SecurityServices)Application["SecurityServices"];
                Guid programID = new Guid(ConfigurationSettings.AppSettings["DealingConsole"]);
                Guid permissionID = new Guid(ConfigurationSettings.AppSettings["Run"]);
                bool isAuthrized = securityServices.CheckPermission(userID, programID, permissionID, "", "", userID, out errorMsg);
                if (isAuthrized == false)
                {
                    userID = Guid.Empty;
                    return false;
                }

                Token token = new Token(userID, UserType.System, AppType.DealingConsole);
                token.SessionID = this.Context.Session.SessionID;
                token.ExchangeSystem = exchangeSystem;
                this.Session["Token"] = token;
                bool success = this.StateServer.Login(token);
                if (success == false)
                {
                    userID = Guid.Empty;
                    errorMsg = "Login to stateServer failure.";
                    return false;
                }

                if (!authenticateOnly)
                {
                    FormsAuthentication.SetAuthCookie(userID.ToString(), false);

                    //Prevent be kickout
                    Hashtable sessionIDs = (Hashtable)this.Context.Application["SessionIDs"];
                    sessionIDs = Hashtable.Synchronized(sessionIDs);
                    sessionIDs[userID] = this.Context.Session.SessionID;
                }

                return true;
            }
            catch (Exception exception)
            {
                AppDebug.LogEvent("DealingConsole", exception.ToString(), EventLogEntryType.Error);
                throw;
            }
        }