Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                CP2Connection conn = new CP2ConnectionClass();
                conn.AppName = "AsyncOrdSend"; // адрес вашего приложения в коммуникациях РТС.
                conn.Host = "127.0.0.1"; //Адрес
                conn.Port = 4001; // и порт локального роутера

                conn.Connect();// устанавливаем соединение с локальным роутером
                string srvAddr = conn.ResolveService("FORTS_SRV"); // ищем адрес сервера приема заявок
                LogWriteLine("address is {0}", srvAddr);
                CP2BLMessageFactory msgs = new CP2BLMessageFactory();

                msgs.Init("p2fortsgate_messages.ini", "");

                CP2BLMessage msg = msgs.CreateMessageByName("FutAddOrder");

                msg.DestAddr = srvAddr;
                msg.set_Field("P2_Category", "FORTS_MSG");
                msg.set_Field("P2_Type", 1);
                msg.set_Field("isin", "RTS-6.10");
                msg.set_Field("price", "150000");
                msg.set_Field("amount", "1");
                msg.set_Field("client_code", "001");
                msg.set_Field("type", 1);
                msg.set_Field("dir", 1);

                msg.SendAsync(conn, 5000, new CP2AsyncMessageEvents());
                msg.SendAsync2(conn, 5000, new CP2SendAsync2Event(), 1234567890);

                while (true)
                {
                    uint cookie;
                    conn.ProcessMessage(out cookie, 100);
                }

            }
            catch (Exception e)
            {
                int hRes = Marshal.GetHRForException(e);
                Console.WriteLine("Exception {0}", e.Message);
                LogWriteLine("Exception {0} {1}", e.Message, hRes);
                if (hRes == -2147205116) // P2ERR_INI_FILE_NOT_FOUND
                {
                    string s = "Can't find one or both of ini file: P2ClientGate.ini, p2fortsgate_messages.ini";
                    Console.WriteLine("{0}", s);
                    LogWriteLine("{0}", s);
                }
                return;
            }
        }