Ejemplo n.º 1
0
        private int MessageHandlerPos(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsPos.position p = new SchemeFortsPos.position(msg.Data);
                    for (int i = 0; i < Account.Positions.Count; i++)
                    {
                        if (Account.Positions[i].Instr.ID == p.isin_id)
                        {
                            if (p.pos == 0)
                            {
                                Account.Positions.RemoveAt(i);
                                return 0;
                            }
                            Account.Positions[i].Pos = p.pos;
                            Account.Positions[i].Price = p.waprice;
                            return 0;
                        }
                    }
                    if (p.pos != 0)
                    {
                        Account.Positions.Add(new AccountInfo.Position());
                        Account.Positions[Account.Positions.Count - 1].Pos = p.pos;
                        Account.Positions[Account.Positions.Count - 1].Price = p.waprice;
                        foreach (Instrument instr in Instruments)
                        {
                            if (instr.ID == p.isin_id)
                                Account.Positions[Account.Positions.Count - 1].Instr = instr;
                            return 0;
                        }
                        Account.Positions[Account.Positions.Count - 1].Instr = new Instrument();
                        Account.Positions[Account.Positions.Count - 1].Instr.ID = p.isin_id;
                    }
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    FutPosOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutPosReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
Ejemplo n.º 2
0
        private int MessageHandlerVM(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsVM.fut_vm p = new SchemeFortsVM.fut_vm(msg.Data);
                    for (int i = 0; i < Account.Positions.Count; i++)
                    {
                        if (Account.Positions[i].Instr.ID == p.isin_id)
                        {
                            Account.Positions[i].Profit = p.vm_real;
                        }
                    }
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    FutVMOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutVMReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
Ejemplo n.º 3
0
        private int MessageHandlerInfoSpot(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    if ((msg as ru.micexrts.cgate.message.StreamDataMessage).MsgIndex == 0) // session
                    {
                        SchemeFortsInfo.session sess = new SchemeFortsInfo.session(msg.Data);
                        if (Session.ID == sess.sess_id)
                        {
                            Session.State = sess.state;
                            Session.ClearingState = sess.inter_cl_state;
                        }
                        else if (Session.ID < sess.sess_id)
                        {
                            Session.ID = sess.sess_id;
                            Session.State = sess.state;
                            Session.ClearingState = sess.inter_cl_state;
                        }
                    }
                    else if ((msg as ru.micexrts.cgate.message.StreamDataMessage).MsgIndex == 1) // fut_sess_contents
                    {
                        SchemeFortsInfo.fut_sess_contents instr = new SchemeFortsInfo.fut_sess_contents(msg.Data);
                        for (int i = 0; i < Instruments.Count; i++)
                        {
                            if (instr.isin_id == Instruments[i].ID)
                            {
                                Instruments[i].SessionID = instr.sess_id;
                                Instruments[i].State = instr.state;
                                Instruments[i].FullName = instr.name;
                                Instruments[i].Name = instr.isin;
                                Instruments[i].ShortName = instr.short_isin;
                                Instruments[i].Start = instr.d_start;
                                Instruments[i].Expitation = instr.d_exp;
                                Instruments[i].LotVolume = instr.lot_volume;
                                Instruments[i].Points = instr.roundto;

                                return 0;
                            }
                        }

                        Instruments.Add(new Instrument());
                        Instruments[Instruments.Count - 1].ID = instr.isin_id;
                        Instruments[Instruments.Count - 1].SessionID = instr.sess_id;
                        Instruments[Instruments.Count - 1].State = instr.state;
                        Instruments[Instruments.Count - 1].FullName = instr.name;
                        Instruments[Instruments.Count - 1].Name = instr.isin;
                        Instruments[Instruments.Count - 1].ShortName = instr.short_isin;
                        Instruments[Instruments.Count - 1].Start = instr.d_start;
                        Instruments[Instruments.Count - 1].Expitation = instr.d_exp;
                        Instruments[Instruments.Count - 1].LotVolume = instr.lot_volume;
                        Instruments[Instruments.Count - 1].Points = instr.roundto;
                    }
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    SpotInfoOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisSpotInfoReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
Ejemplo n.º 4
0
        private int MessageHandlerPart(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsPart.part p = new SchemeFortsPart.part(msg.Data);

                    Account.ClientCode = p.client_code;
                    Account.BlockedMoney = p.money_blocked;
                    Account.FreeMoney = p.money_free;
                    Account.TotalMoney = p.money_amount;
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {

                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)    // REPLONLINE
                {
                    mtx.WaitOne();
                    FutPartOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutVMOnline && CurrInfoOnline && SpotInfoOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutPartReplState = ((P2ReplStateMessage)msg).ReplState;
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
Ejemplo n.º 5
0
        private void CheckConnectionInfo()
        {
            ErrorCode result;

            while (isWork)
            {
                #region Work
                try
                {
                    if (connFutInfo.State == State.Active)
                    {
                        #region Connection
                        result = connFutInfo.Process(10);
                        if (result != ErrorCode.Ok && result != ErrorCode.TimeOut)
                        {
                            errMessage = "Connection FutInfo Process Error " + result;
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                        }
                        #endregion
                        #region Listener
                        if (lisSpotInfo.State == State.Error)
                        {
                            SpotInfoOnline = false;
                            errMessage = "Listener SpotInfo Error";
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                            lisSpotInfo.Close();
                        }
                        else if (lisSpotInfo.State == State.Closed)
                        {
                            if (lisSpotInfoReplState == "")
                                lisSpotInfo.Open("mode=snapshot+online");
                            else
                                lisSpotInfo.Open("mode=snapshot+online;replstate=" + lisSpotInfoReplState);
                        }

                        if (lisCurrInfo.State == State.Error)
                        {
                            CurrInfoOnline = false;
                            errMessage = "Listener CurrInfo Error";
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                            lisCurrInfo.Close();
                        }
                        else if (lisCurrInfo.State == State.Closed)
                        {
                            if (lisCurrInfoReplState == "")
                                lisCurrInfo.Open("mode=snapshot+online");
                            else
                                lisCurrInfo.Open("mode=snapshot+online;replstate=" + lisCurrInfoReplState);
                        }

                        if (lisFutInfo.State == State.Error)
                        {
                            FutInfoOnline = false;
                            errMessage = "Listener FutInfo Error";
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                            lisFutInfo.Close();
                        }
                        else if (lisFutInfo.State == State.Closed)
                        {
                            if (lisFutInfoReplState == "")
                                lisFutInfo.Open("mode=snapshot+online");
                            else
                                lisFutInfo.Open("mode=snapshot+online;replstate=" + lisFutInfoReplState);
                        }

                        if (lisFutPos.State == State.Error)
                        {
                            FutPosOnline = false;
                            errMessage = "Listener FutPos Error";
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                            lisFutPos.Close();
                        }
                        else if (lisFutPos.State == State.Closed)
                        {
                            if (lisFutPosReplState == "")
                                lisFutPos.Open("mode=snapshot+online");
                            else
                                lisFutPos.Open("mode=snapshot+online;replstate=" + lisFutPosReplState);
                        }

                        if (lisFutPart.State == State.Error)
                        {
                            FutPartOnline = false;
                            errMessage = "Listener FutPart Error";
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                            lisFutPart.Close();
                        }
                        else if (lisFutPart.State == State.Closed)
                        {
                            if (lisFutPartReplState == "")
                                lisFutPart.Open("mode=snapshot+online");
                            else
                                lisFutPart.Open("mode=snapshot+online;replstate=" + lisFutPartReplState);
                        }

                        if (lisFutVM.State == State.Error)
                        {
                            FutVMOnline = false;
                            errMessage = "Listener FutVM Error";
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                            lisFutVM.Close();
                        }
                        else if (lisFutVM.State == State.Closed)
                        {
                            if (lisFutVMReplState == "")
                                lisFutVM.Open("mode=snapshot+online");
                            else
                                lisFutVM.Open("mode=snapshot+online;replstate=" + lisFutVMReplState);
                        }
                        #endregion
                    }
                    else if (connFutInfo.State == State.Closed)
                    {
                        #region ...
                        connFutInfo.Open();
                        #endregion
                    }
                    else if (connFutInfo.State == State.Error)
                    {
                        #region ...
                        CurrInfoOnline = false;
                        SpotInfoOnline = false;
                        FutInfoOnline = false;
                        FutPosOnline = false;
                        FutPartOnline = false;
                        FutVMOnline = false;
                        errMessage = "Connection FutInfo Error";
                        Status = MPlazaStatus.Error;
                        OnError(new ErrorEvent(errMessage));
                        connFutInfo.Close();
                        #endregion
                    }
                }
                catch (Exception err)
                {
                    errMessage = err.Message;
                    Status = MPlazaStatus.Error;
                    OnError(new ErrorEvent(errMessage));
                }
                Thread.Sleep(100);
                #endregion
            }
            #region Deinit
            try
            {
                if (lisSpotInfo.State != State.Closed)
                    lisSpotInfo.Close();
                if (lisCurrInfo.State != State.Closed)
                    lisCurrInfo.Close();
                if (lisFutInfo.State != State.Closed)
                    lisFutInfo.Close();
                if (lisFutVM.State != State.Closed)
                    lisFutVM.Close();
                if (lisFutPart.State != State.Closed)
                    lisFutPart.Close();
                if (lisFutPos.State != State.Closed)
                    lisFutPos.Close();

                if (connFutInfo.State != State.Closed)
                    connFutInfo.Close();

                Status = MPlazaStatus.Stoped;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Stoped;
                OnError(new ErrorEvent(errMessage));
            }
            #endregion
        }
Ejemplo n.º 6
0
        public MInfo(string Name = "")
        {
            try
            {
                PlazaInit = new MPlazaInit();
                PlazaInit.Init();

                mtx = new Mutex();
                Instruments = new List<Instrument>();
                Session = new SessionInfo();
                Account = new AccountInfo();
                Status = MPlazaStatus.Stoped;

                connFutInfo = new Connection("p2tcp://127.0.0.1:4001;app_name=FI" + Name);

                lisCurrInfo = new Listener(connFutInfo, "p2repl://MCXCC_INFO_REPL;scheme=|FILE|Ini\\CurrInfo.ini|CurrInfo");
                lisCurrInfo.Handler += new Listener.MessageHandler(MessageHandlerInfoCurr);
                lisCurrInfoReplState = "";

                lisSpotInfo = new Listener(connFutInfo, "p2repl://MCXSPOT_INFO_REPL;scheme=|FILE|Ini\\SpotInfo.ini|SpotInfo");
                lisSpotInfo.Handler += new Listener.MessageHandler(MessageHandlerInfoSpot);
                lisSpotInfoReplState = "";

                lisFutInfo = new Listener(connFutInfo, "p2repl://FORTS_FUTINFO_REPL;scheme=|FILE|Ini\\FutInfo.ini|FutInfo");
                lisFutInfo.Handler += new Listener.MessageHandler(MessageHandlerInfo);
                lisFutInfoReplState = "";

                lisFutPos = new Listener(connFutInfo, "p2repl://FORTS_POS_REPL;scheme=|FILE|Ini\\FutPos.ini|FutPos");
                lisFutPos.Handler += new Listener.MessageHandler(MessageHandlerPos);
                lisFutPosReplState = "";

                lisFutPart = new Listener(connFutInfo, "p2repl://FORTS_PART_REPL;scheme=|FILE|Ini\\FutPart.ini|FutPart");
                lisFutPart.Handler += new Listener.MessageHandler(MessageHandlerPart);
                lisFutPartReplState = "";

                lisFutVM = new Listener(connFutInfo, "p2repl://FORTS_VM_REPL;scheme=|FILE|Ini\\FutVM.ini|FutVM");
                lisFutVM.Handler += new Listener.MessageHandler(MessageHandlerVM);
                lisFutVMReplState = "";

                errMessage = "";
            }
            catch (Exception err)
            {
                mtx.Close();

                if (lisSpotInfo != null)
                    lisSpotInfo.Dispose();
                if (lisCurrInfo != null)
                    lisCurrInfo.Dispose();
                if (lisFutInfo != null)
                    lisFutInfo.Dispose();
                if (lisFutPos != null)
                    lisFutPos.Dispose();
                if (lisFutPart != null)
                    lisFutPart.Dispose();
                if (lisFutVM != null)
                    lisFutVM.Dispose();

                if (connFutInfo != null)
                    connFutInfo.Dispose();

                PlazaInit.Deinit();
                errMessage = err.Message;
                throw err;
            }
        }
Ejemplo n.º 7
0
        private void CheckConnectionDrinks()
        {
            ErrorCode result;

            while (isWork)
            {
                #region Work
                try
                {
                    if (connFutDrinks.State == State.Error)
                    {
                        #region ...
                        FutDrinksOnline = false;
                        errMessage = "Connection FutDrinks Error";
                        Status = MPlazaStatus.Error;
                        OnError(new ErrorEvent(errMessage));
                        connFutDrinks.Close();
                        #endregion
                    }
                    else if (connFutDrinks.State == State.Closed)
                    {
                        #region ...
                        connFutDrinks.Open();
                        #endregion
                    }
                    else if (connFutDrinks.State == State.Opening)
                    {
                        #region ...
                        result = connFutDrinks.Process(100);
                        if (result != ErrorCode.Ok && result != ErrorCode.TimeOut)
                        {
                            errMessage = "Connection FutDrinks Opening Error" + result;
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                        }
                        Thread.Sleep(300);
                        #endregion
                    }
                    else if (connFutDrinks.State == State.Active)
                    {
                        #region ...
                        result = connFutDrinks.Process(10);
                        if (result != ErrorCode.Ok && result != ErrorCode.TimeOut)
                        {
                            errMessage = "Connection FutDrinks Process Error" + result;
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                        }
                        #endregion
                        #region
                        if (lisFutDrinks.State == State.Error)
                        {
                            FutDrinksOnline = false;
                            errMessage = "Listener FutDrinks Error";
                            Status = MPlazaStatus.Error;
                            OnError(new ErrorEvent(errMessage));
                            lisFutDrinks.Close();
                        }
                        else if (lisFutDrinks.State == State.Closed)
                        {
                            lisFutDrinks.Open("mode=snapshot+online");
                        }
                        #endregion
                    }
                }
                catch (Exception err)
                {
                    errMessage = err.Message;
                    Status = MPlazaStatus.Error;
                    OnError(new ErrorEvent(errMessage));
                }
                Thread.Sleep(1);
                #endregion
            }
            #region Deinit
            try
            {
                if (lisFutDrinks.State != State.Closed)
                    lisFutDrinks.Close();

                if (connFutDrinks.State != State.Closed)
                    connFutDrinks.Close();

                mtx.WaitOne();
                FutDrinksOnline = false;

                if (!FutPosOnline && !FutPartOnline && !FutVMOnline && !FutInfoOnline && !FutDealsOnline && !FutCommonOnline && !FutTradeOnline)
                {
                    Status = MPlazaStatus.Stoped;
                }
                mtx.ReleaseMutex();
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
            }
            #endregion
        }
Ejemplo n.º 8
0
        public MPlaza(string Name, bool Common, bool Deals, bool Drinks, bool Trade, int Depth = 5)
        {
            try
            {
                Instruments = new List<Instrument>();
                Session = new SessionInfo();
                Account = new AccountInfo();

                Status = MPlazaStatus.Stoped;
                this.Drinks = new List<Drink>();
                this.Depth = Depth;

                #region Init
                DirectoryInfo dir = new DirectoryInfo("Log");
                if (dir.Exists)
                    dir.Delete(true);

                //CGate.Open("ini=Ini/MPlaza.ini;key=IskCq8sT1t1IlrEZjivBT5ZNlOGXoIV");
                CGate.Open("ini=Ini/MPlaza.ini;key=11111111");

                connFutInfo = new Connection("p2tcp://127.0.0.1:4001;app_name=FI" + Name);

                lisFutInfo = new Listener(connFutInfo, "p2repl://FORTS_FUTINFO_REPL;scheme=|FILE|Ini\\FutInfo.ini|FutInfo");
                lisFutInfo.Handler += new Listener.MessageHandler(MessageHandlerInfo);
                lisFutInfoReplState = "";

                lisFutPos = new Listener(connFutInfo, "p2repl://FORTS_POS_REPL;scheme=|FILE|Ini\\FutPos.ini|FutPos");
                lisFutPos.Handler += new Listener.MessageHandler(MessageHandlerPos);
                lisFutPosReplState = "";

                lisFutPart = new Listener(connFutInfo, "p2repl://FORTS_PART_REPL;scheme=|FILE|Ini\\FutPart.ini|FutPart");
                lisFutPart.Handler += new Listener.MessageHandler(MessageHandlerPart);
                lisFutPartReplState = "";

                lisFutVM = new Listener(connFutInfo, "p2repl://FORTS_VM_REPL;scheme=|FILE|Ini\\FutVM.ini|FutVM");
                lisFutVM.Handler += new Listener.MessageHandler(MessageHandlerVM);
                lisFutVMReplState = "";

                if (Common)
                {
                    connFutCommon = new Connection("p2tcp://127.0.0.1:4001;app_name=FC" + Name);
                    lisFutCommon = new Listener(connFutCommon, "p2repl://FORTS_FUTCOMMON_REPL;scheme=|FILE|Ini\\FutComm.ini|FutComm");
                    lisFutCommon.Handler += new Listener.MessageHandler(MessageHandlerComm);
                    lisFutCommReplState = "";
                }

                if (Deals)
                {
                    connFutDeals = new Connection("p2tcp://127.0.0.1:4001;app_name=FDE" + Name);
                    lisFutDeals = new Listener(connFutDeals, "p2repl://FORTS_FUTTRADE_REPL;scheme=|FILE|Ini\\FutTrade.ini|FutTrade");
                    lisFutDeals.Handler += new Listener.MessageHandler(MessageHandlerDeals);
                    lisFutDealsReplState = "";
                }

                if (Drinks)
                {
                    connFutDrinks = new Connection("p2tcp://127.0.0.1:4001;app_name=FDR" + Name);
                    lisFutDrinks = new Listener(connFutDrinks, "p2repl://FORTS_FUTAGGR" + Depth + "_REPL;scheme=|FILE|Ini\\FutAggr.ini|FutAggr");
                    lisFutDrinks.Handler += new Listener.MessageHandler(MessageHandlerDrinks);
                }

                if (Trade)
                {
                    connFutTrade = new Connection("p2tcp://127.0.0.1:4001;app_name=FT" + Name);
                    pub = new Publisher(connFutTrade, "p2mq://FORTS_SRV;category=FORTS_MSG;name=Pub;timeout=5000");

                    lisFutTrade = new Listener(connFutTrade, "p2mqreply://;ref=Pub;scheme=|FILE|Ini\\FutMsg.ini|FutMsg");
                    lisFutTrade.Handler += new Listener.MessageHandler(MessageHandlerTrade);
                    lisPubReplState = "";
                }
                #endregion

                errMessage = "";
            }
            catch (Exception err)
            {
                #region Deinit

                if (pub != null)
                    pub.Dispose();

                if (lisFutInfo != null)
                    lisFutInfo.Dispose();
                if (lisFutPos != null)
                    lisFutPos.Dispose();
                if (lisFutPart != null)
                    lisFutPart.Dispose();
                if (lisFutVM != null)
                    lisFutVM.Dispose();
                if (lisFutCommon != null)
                    lisFutCommon.Dispose();
                if (lisFutDeals != null)
                    lisFutDeals.Dispose();
                if (lisFutDrinks != null)
                    lisFutDrinks.Dispose();
                if (lisFutTrade != null)
                    lisFutTrade.Dispose();

                if (connFutInfo != null)
                    connFutInfo.Dispose();
                if (connFutCommon != null)
                    connFutCommon.Dispose();
                if (connFutDeals != null)
                    connFutDeals.Dispose();
                if (connFutDrinks != null)
                    connFutDrinks.Dispose();
                if (connFutTrade != null)
                    connFutTrade.Dispose();

                CGate.Close();
                #endregion
                errMessage = err.Message;
                throw err;
            }
        }
Ejemplo n.º 9
0
        private int MessageHandlerTrade(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgData)              // DATA
                {
                    if ((msg as DataMessage).MsgName == "FORTS_MSG101")
                    {
                        SchemeFortsMsg.FORTS_MSG101 repl = new SchemeFortsMsg.FORTS_MSG101(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.order_id;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG102")
                    {
                        SchemeFortsMsg.FORTS_MSG102 repl = new SchemeFortsMsg.FORTS_MSG102(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.amount;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG103")
                    {
                        SchemeFortsMsg.FORTS_MSG103 repl = new SchemeFortsMsg.FORTS_MSG103(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.num_orders;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG105")
                    {
                        SchemeFortsMsg.FORTS_MSG105 repl = new SchemeFortsMsg.FORTS_MSG105(msg.Data);
                        if (repl.code == 0)
                            Ticket = repl.order_id1;
                        else
                        {
                            errMessage = repl.message;
                            Ticket = -repl.code;
                        }
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG99")
                    {
                        SchemeFortsMsg.FORTS_MSG99 repl = new SchemeFortsMsg.FORTS_MSG99(msg.Data);
                        errMessage = repl.message;
                        OnError(new ErrorEvent("FORTS_MSG99: " + repl.message));
                        Execution = false;
                    }
                    else if ((msg as DataMessage).MsgName == "FORTS_MSG100")
                    {
                        SchemeFortsMsg.FORTS_MSG100 repl = new SchemeFortsMsg.FORTS_MSG100(msg.Data);
                        errMessage = repl.message;
                        OnError(new ErrorEvent("FORTS_MSG100: " + repl.message));
                        Execution = false;
                    }
                }
                else if (msg.Type == MessageType.MsgP2MQTimeout)
                {
                    errMessage = "Таймаут";
                    Ticket = -1488;
                    Execution = false;
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {
                    mtx.WaitOne();
                    FutTradeOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutTradeOnline && FutVMOnline && FutCommonOnline && FutDealsOnline && FutDrinksOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisPubReplState = ((P2ReplStateMessage)msg).ReplState.TrimEnd((char)0);
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
Ejemplo n.º 10
0
        private int MessageHandlerDrinks(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    SchemeFortsDrink.orders_aggr aggr = new SchemeFortsDrink.orders_aggr(msg.Data);
                    for (int i = 0; i < Drinks.Count; i++)
                    {
                        if (aggr.isin_id == Drinks[i].InstrId)
                        {
                            if (aggr.volume != 0)
                                Drinks[i].AddQuote(new Drink.Quote(aggr.replID, aggr.price, aggr.volume, aggr.dir));
                            else
                                Drinks[i].RemoveQuote(aggr.replID);

                            if (FutDrinksOnline)
                                OnDrink(Drinks[i]);

                            break;
                        }
                    }
                }
                else if (msg.Type == MessageType.MsgP2ReplOnline)               // OPEN
                {
                    mtx.WaitOne();
                    FutDrinksOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutTradeOnline && FutVMOnline && FutCommonOnline && FutDealsOnline && FutDrinksOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }
Ejemplo n.º 11
0
        private int MessageHandlerDeals(Connection conn, Listener listener, Message msg)
        {
            try
            {
                if (msg.Type == MessageType.MsgStreamData)              // STREAM DATA
                {
                    if ((msg as ru.micexrts.cgate.message.StreamDataMessage).MsgIndex == 1)
                        OnDeal(new DealInfo(msg.Data));
                    else
                        OnOrder(new OrderInfo(msg.Data));
                }
                else if (msg.Type == MessageType.MsgOpen)               // OPEN
                {
                    mtx.WaitOne();
                    FutDealsOnline = true;

                    if (FutInfoOnline && FutPartOnline && FutPosOnline && FutTradeOnline && FutVMOnline && FutCommonOnline && FutDealsOnline && FutDrinksOnline)
                        Status = MPlazaStatus.OK;

                    mtx.ReleaseMutex();
                }
                else if (msg.Type == MessageType.MsgP2ReplReplState)    // REPLSTATE
                {
                    lisFutDealsReplState = ((P2ReplStateMessage)msg).ReplState.TrimEnd((char)0);
                }
                msg.Dispose();
                return 0;
            }
            catch (Exception err)
            {
                errMessage = err.Message;
                Status = MPlazaStatus.Error;
                OnError(new ErrorEvent(errMessage));
                msg.Dispose();
                return -1;
            }
        }