示例#1
0
 public void SetCurrentSession(FUTINFO.session sess, DateTime SrvTmLocal, int timeTolMS)
 {
     SessionNumber = sess.sess_id;
     if (CUtilTime.InTmInterval(SrvTmLocal, sess.begin, sess.end, timeTolMS))
     {
         SessionBegin = sess.begin;
         SessionEnd   = sess.end;
         SessionType  = EnmSessionTypes.SessDay;
         _client.GUIBox.UpdateSessionString(SessionBegin, SessionEnd);
     }
     else if (sess.eve_on == 1 && CUtilTime.InTmInterval(SrvTmLocal, sess.eve_begin, sess.eve_end, timeTolMS))
     {
         SessionBegin = sess.eve_begin;
         SessionEnd   = sess.eve_end;
         SessionType  = EnmSessionTypes.SessEvening;
         _client.GUIBox.UpdateSessionString(SessionBegin, SessionEnd);
     }
     else if (sess.mon_on == 1 && CUtilTime.InTmInterval(SrvTmLocal, sess.mon_begin, sess.mon_end, timeTolMS))
     {
         SessionBegin = sess.mon_begin;
         SessionEnd   = sess.mon_end;
         SessionType  = EnmSessionTypes.SessMorningAdditional;
         _client.GUIBox.UpdateSessionString(SessionBegin, SessionEnd);
     }
 }
        public void Update(FUTINFO.session sess)
        {
            // UpdateLatestRcvdSess(sess);



            m_listRawSession.Add(new CRawSession(sess));

            // Session is active. Possible to add and cancel orders
            DateTime SrvTmLocal = _client.ServerTimeLocal();


            int timeTolMS = 1000;



            Log("Update SrvTmLocal=" + SrvTmLocal + " begin=" + sess.begin + " end=" + sess.end + " state=" + sess.state +
                " eve_begin=" + sess.eve_begin + " eve_end=" + sess.eve_end + " eve_on" + sess.eve_on +
                " mon_begin=" + sess.mon_begin + " end=" + sess.mon_end + " mon_on=" + sess.mon_on +
                " IsSessionActive=" + _client.IsSessionActive);



            _interClearingState = (EnmFORTSInerClearingSate)sess.inter_cl_state;


            if (sess.state == (int)EnmFORTSSessionState.S1_SessionActiveTradeEnabled)
            {
                _client.GUIBox.SessionState = 1;

                Log("S1_SessionActiveTradeEnabled");

                //check time also
                if (CUtilTime.InTmInterval(SrvTmLocal, sess.begin, sess.end, timeTolMS) ||
                    (sess.eve_on == 1 && CUtilTime.InTmInterval(SrvTmLocal, sess.eve_begin, sess.eve_end, timeTolMS)) ||
                    (sess.mon_on == 1 && CUtilTime.InTmInterval(SrvTmLocal, sess.mon_begin, sess.mon_end, timeTolMS))
                    )
                {
                    Log("Is in interval");
                    m_curentSessionRaw = new CRawSession(sess);

                    m_currSession.SetCurrentSession(sess, SrvTmLocal, timeTolMS);


                    if (!_client.IsSessionActive)
                    {
                        _client.OnSessionActivate();
                        _client.IsSessionActive = true;
                        _client.SessionCurrent  = sess.sess_id;
                        //m_plaza2Connector.DtSessionCurrentBegin = sess.begin;

                        _sessionCurrentNum   = sess.sess_id;
                        _sessionCurrentBegin = sess.eve_begin;

                        Log("IsSessionActive = true;");


                        if (CUtilTime.InTmInterval(SrvTmLocal, sess.inter_cl_end, sess.end, timeTolMS))
                        {
                            _clientP2.OnIntradayClearingEnd();
                        }

                        if (CUtilTime.InTmInterval(SrvTmLocal, sess.end, sess.eve_begin, timeTolMS))
                        {
                            _clientP2.OnEveningClearingEnd();
                        }

                        if ((CUtilTime.InTmInterval(SrvTmLocal, sess.mon_begin, sess.mon_end, timeTolMS) && sess.mon_on == 1) ||
                            (CUtilTime.InTmInterval(SrvTmLocal, sess.begin, sess.end, timeTolMS) && sess.mon_on == 0))
                        {
                            _client.OnNightEnded();
                        }
                    }

                    if (!_client.IsPossibleToCancelOrders)
                    {
                        _client.IsPossibleToCancelOrders = true;
                        _client.OnEnableCancellOrders();
                    }
                }
            }

            else     //session is not active
            {
                if (sess.sess_id < m_currSession.SessionNumber)
                {
                    Log("sess.sess_id < m_currSession.SessionNumber exiting");
                    return;
                }


                _client.GUIBox.SessionState = 0;

                int s1 = _client.SessionCurrent;
                int s2 = sess.sess_id;


                Log("else...");
                //not possible to add orders
                if (_client.IsSessionActive)
                {
                    _client.OnSessionDeactivate();
                    _client.IsSessionActive = false;
                }



                //... but possible to cancel orders
                if (sess.state == (int)EnmFORTSSessionState.S0_SessionWasSet || sess.state == (int)EnmFORTSSessionState.S2_SessionNotActiveTradeDisabled)
                {
                    Log("EnmSessionState.S0_SessionWasSet || sess.state == S2_SessionNotActiveTradeDisabled");

                    if (!_client.IsPossibleToCancelOrders)
                    {
                        _client.IsPossibleToCancelOrders = true;
                        _client.OnEnableCancellOrders();
                    }



                    if (CUtilTime.InTmInterval(SrvTmLocal, sess.inter_cl_begin, sess.inter_cl_end, timeTolMS))
                    {
                        _client.OnIntradeyClearingBegin();
                    }


                    if (CUtilTime.InTmInterval(SrvTmLocal, sess.end, sess.eve_begin, timeTolMS))
                    {
                        _clientP2.OnEveningClearingBegin();
                    }

                    if ((SrvTmLocal > sess.eve_end && SrvTmLocal < sess.mon_begin && sess.mon_on == 1) ||
                        (SrvTmLocal > sess.eve_end && SrvTmLocal < sess.begin && sess.mon_on == 0))
                    {
                        _client.OnNightStarted();
                    }
                }
                else if (sess.state == (int)EnmFORTSSessionState.S4_SessionExpired)
                {
                    if (CUtilTime.InTmInterval(SrvTmLocal, sess.end, sess.eve_begin, timeTolMS))
                    {
                        _client.OnDaySessionExpired();
                    }

                    //if session online end expired than day session finished
                    if (_client.IsSessionOnline)
                    {
                        OnSessionExpired(sess);
                    }
                }

                else //not possible cancell orders
                {
                    Log("not possible cancell orders");
                    if (_client.IsPossibleToCancelOrders)
                    {
                        _client.IsPossibleToCancelOrders = false;
                        _client.OnDisableCancellOrders();
                    }
                }
            }


            foreach (CBotBase bt in _client.ListBots)
            {
                bt.Recalc("", EnmBotEventCode.OnSessionUpdate, null);
            }



            UpateLstSessions(sess);
            // UpdateDBSession(sess);
        }