Exemplo n.º 1
0
 public void Test_StartAdvise_After_StartAdvise()
 {
     using var server = new TestServer(ServiceName);
     server.Register();
     server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData));
     using var client = new DdeClient(ServiceName, TopicName);
     client.Connect();
     client.StartAdvise(ItemName, 1, false, Timeout);
     Assert.Throws<InvalidOperationException>(() => client.StartAdvise(ItemName, 1, false, Timeout));
 }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DdeClient client = new DdeClient("MMSDDE", "FUSA");

            client.Connect();

            client.Advise += client_Advise;
            client.StartAdvise("B1YM&.101", 1, true, 60000);
            client.StartAdvise("B1YM&.184", 1, true, 60000);
        }
Exemplo n.º 3
0
 public void Test_StartAdvise_After_StartAdvise()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData));
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             client.StartAdvise(ItemName, 1, false, Timeout);
             client.StartAdvise(ItemName, 1, false, Timeout);
         }
     }
 }
Exemplo n.º 4
0
        public static void Agent()
        {
            // Create a client that connects to 'myapp|machineswitch'
            string myApp   = "ncdde";
            string myTopic = "machineswitch";

            DdeClient client = new DdeClient(myApp, myTopic);

            try {
                client.Disconnected += OnDisconnected;

                // Advise Loop
                client.Connect();
                for (int i = 0; i < Events.list.Count; i++)
                {
                    client.StartAdvise(Events.list[i].foreignEvent, 1, true, 60000);
                }

                client.Advise += OnAdvise;

                // Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                // Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            } finally {
            }
        }
        public WebLiveMonitorViewModel(params object[] args)
        {
            HidePleaseWait = false;
            //LineSr.DataSqlUpdateSucceeded += DataCopy_DataSqlUpdateSucceeded;

            if (args.Length > 0)
            {
                int.TryParse(args[0].ToString(), out _screen);
            }

            Mediator.Register <string>(this, SetUpBrowser, MsgTag.SetUpBrowser);
            Mediator.Register <string>(this, ChangeVisibility, MsgTag.ChangeVisibility);

            _client = new DdeClient("terminal", MsgTag.SetUpBrowser);
            while (!_client.IsConnected)
            {
                try
                {
                    _client.Connect();
                    _client.Disconnected += client_Disconnected;
                    _client.StartAdvise("test" + _screen, 1, true, 6000);
                    _client.Advise += client_Advise;
                }
                catch (Exception e)
                {
                    Log.Error(e.Message, e);
                }
            }
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("DDE Console");
            String _myapp = "TOS";
            String _topic = "LAST";
            String _item  = "SPY";

            try
            {
                // Create a client that connects to 'myapp|topic'.
                using (DdeClient client = new DdeClient(_myapp, _topic))
                {
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    client.Disconnected += OnDisconnected;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    client.Connect();

                    // Advise Loop
                    client.StartAdvise(_item, 1, true, 60000);
                    client.Advise += OnAdvise;

                    // Wait for the user to press ENTER before proceding.
                    Console.WriteLine("Press ENTER to quit...");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            }
        }
Exemplo n.º 7
0
        private void StartAssetDDE()
        {
            String _topic = "LAST";

            try
            {
                // Create a client that connects to 'myapp|topic'.
                using (DdeClient client = new DdeClient(Properties.Settings.Default.APP, _topic))
                {
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    client.Disconnected += OnDisconnected;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    client.Connect();

                    // Advise Loop
                    client.StartAdvise(Properties.Settings.Default.ITEM, 1, true, 60000);
                    client.Advise += OnAdvise;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Please run " + Properties.Settings.Default.APP + " and restart this application!");
            }
        }
Exemplo n.º 8
0
        public static void RunDdeClient()
        {
            // Wait for the user to press ENTER before proceding.
            Console.WriteLine("The Server sample must be running before the client can connect.");
            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
            try
            {
                // Create a client that connects to 'myapp|mytopic'.
                using (DdeClient client = new DdeClient("EXCEL", "[Book1.xlsx]2011-06-22"))
                {
                    //[stock.xls]Sheet1!'r2c2'
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    client.Disconnected += OnDisconnected;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    client.Connect();

                    // Synchronous Execute Operation
                    // client.Execute("mycommand", 60000);

                    // Synchronous Poke Operation
                    //client.Poke("myitem", DateTime.Now.ToString(), 60000);
                    //client.Poke("A3", DateTime.Now.ToString(), 60000);

                    // Syncronous Request Operation
                    //Console.WriteLine("Request: " + client.Request("myitem", 60000));
                    Console.WriteLine("Request: " + client.Request("'r1c1'", 60000));

                    // Asynchronous Execute Operation
                    //client.BeginExecute("mycommand", OnExecuteComplete, client);

                    // Asynchronous Poke Operation
                    //client.BeginPoke("myitem", Encoding.ASCII.GetBytes(DateTime.Now.ToString() + "\0"), 1, OnPokeComplete, client);
                    client.BeginPoke("A2", Encoding.ASCII.GetBytes(DateTime.Now.ToString() + "\0"), 1, OnPokeComplete, client);

                    // Asynchronous Request Operation
                    //client.BeginRequest("myitem", 1, OnRequestComplete, client);
                    client.BeginRequest("A4", 1, OnRequestComplete, client);

                    // Advise Loop
                    client.StartAdvise("myitem", 1, true, 60000);
                    client.Advise += OnAdvise;

                    // Wait for the user to press ENTER before proceding.
                    Console.WriteLine("Press ENTER to quit...");
                    Console.ReadLine();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetType().ToString());
                Console.WriteLine(e.Message);
                Console.WriteLine(e.InnerException);
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Subscribe symbol in DDE server
        /// </summary>
        /// <param name="symbol">Symbol to subscribe</param>
        public void Subscribe(string symbol)
        {
            var market = !symbol.Contains("FUT") ? "0012" : "0057";

            #region If OPTION, define series
            if (symbol.Contains("#"))
            {
                var today = DateTime.Today;
                var reff  = new DateTime(today.Year, today.Month, 15);
                while (reff.DayOfWeek != DayOfWeek.Monday)
                {
                    reff = reff.AddDays(1);
                }

                if (reff <= today)
                {
                    reff = reff.AddMonths(1).AddDays(15 - reff.Day);
                    while (reff.DayOfWeek != DayOfWeek.Monday)
                    {
                        reff = reff.AddDays(1);
                    }
                }

                symbol = symbol.Replace('#', (char)(64 + reff.Month));
            }
            #endregion

            symbol = Rename(symbol);
            var npcSymbol = symbol + ".ult";
            var cmaSymbol = market + symbol + ";1";

            if (_npcSymbols.TryAdd(npcSymbol, BvspTime) && IsDDEAvailable(_npcClient))
            {
                try { _npcClient.StartAdvise(npcSymbol, 1, true, 60000); }
                catch (Exception x) { NotifyDDE("OFF PFT: " + x.Message); }
            }

            if (_cmaSymbols.TryAdd(cmaSymbol, BvspTime) && IsDDEAvailable(_cmaClient))
            {
                try { _cmaClient.StartAdvise(cmaSymbol, 1, true, 60000); }
                catch (Exception x) { NotifyDDE("OFF CMA: " + x.Message); }
            }
        }
Exemplo n.º 10
0
        public void StartQuotesIMKB()
        {
            try
            {
                if (client.IsConnected == true)
                {
                    client.Disconnect();
                    client = new DdeClient("MTX", "DATA");
                }

                client.Advise       += OnAdvise;
                client.Disconnected += new EventHandler <DdeDisconnectedEventArgs>(client_Disconnected);

                client.Connect();
                client.StartAdvise("XU030.SON", 1, true, 60000);
            }
            catch
            { }
        }
Exemplo n.º 11
0
 public void Test_StopAdvise()
 {
     using var server = new TestServer(ServiceName);
     server.Register();
     server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData));
     using var client = new DdeClient(ServiceName, TopicName);
     client.Connect();
     client.StartAdvise(ItemName, 1, true, Timeout);
     client.StopAdvise(ItemName, Timeout);
 }
Exemplo n.º 12
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
            FileStream fs = File.Create(DateTime.Now.ToString("HH_mm_ss") + ".csv");

            writer = new StreamWriter(fs);
            writer.WriteLine("\"TIME\";\"T1\";\"T2\"");
            TimerCallback timerCallback = new TimerCallback(onTick);
            Timer         timer         = new Timer(timerCallback, null, 0, 2000);

            using (DdeClient client = new DdeClient("CoDeSys", @"D:\Project\discreteOut.pro"))
                try
                {
                    client.Disconnected += Client_Disconnected;
                    client.Connect();
                    //var s = client.Request("myitem1", 60000);
                    client.Advise += OnAdvise;
                    client.StartAdvise("T1", 1, true, 600);
                    client.StartAdvise("T2", 1, true, 600);
                    Console.ReadLine();
                }
                catch (NDde.DdeException e)
                {
                    Console.WriteLine(e.Message);
                }
            finally
            {
                timer.Dispose();
                if (client.IsConnected == true)
                {
                    client.Disconnect();
                }
                writer.Close();
                fs.Close();
            }

            /*}
             * catch(Exception e)
             * {
             *  Console.WriteLine(e.Message);
             * }*/
        }
Exemplo n.º 13
0
        private void CollectPrice()
        {
            string    _topic     = "LAST";
            string    _myapp     = Properties.Settings.Default.AppDDE;
            string    expiration = "110416";
            string    item       = "'.SPY" + expiration; //'.SPY110416C132'
            DdeClient client;

            try
            {
                // Create a client that connects to 'myapp|topic'.
                using (client = new DdeClient(_myapp, _topic))
                {
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    client.Disconnected += OnDisconnectedPrice;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    client.Connect();

                    client.StartAdvise("SPY", 1, true, 60000);
                    // Advise Loop
                    for (int j = 0; j < 2; j++)
                    {
                        string cp     = (j == 0) ? "C" : "P";
                        int    strike = 127;
                        for (int i = 0; i < 10; i++)
                        {
                            ++strike;
                            string _item = item + cp + strike.ToString();
                            client.StartAdvise(_item, 1, true, 60000);
                        }
                    }
                    client.Advise += OnAdvisePrice;
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
                log.WriteLine(getTimeStamp() + " Price " + e.ToString());
            }
        }
Exemplo n.º 14
0
 internal TOSDataPoint Subscribe(string item)
 {
     lock (_syncLock)
     {
         if (!_dataPoints.ContainsKey(item))
         {
             _dataPoints.Add(item, new TOSDataPoint(Topic, item));
             c.StartAdvise(item, 1, true, 1000);
         }
         return(_dataPoints[item]);
     }
 }
Exemplo n.º 15
0
        public void Process(int ticks)
        {
            tickLimit = ticks;
            status    = DataProviderStatus.Running;

            if (isPaused)
            {
                isPaused = false;
            }
            else
            {
                ddeClient.StartAdvise(instrument.ToString(), 1, true, 6000);
            }
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            var client = new DdeClient("MT4", "QUOTE");

            beat = new QuoteBeat();

            writer = new LogDataWriter("EURUSD");

            client.Advise += client_Advise;
            client.Connect();
            client.StartAdvise("EURUSD", 1, true, 60000);

            Console.ReadLine();
            writer.Close();
        }
Exemplo n.º 17
0
 internal void AdviseHOR(string ticker, string col)
 {
     try
     {
         clientHOR.StartAdvise($"{ticker}.{col}", 1, true, 10);
         clientHOR.Advise += OnAdviseHOR;
         CalibrateBot(true);
     }
     catch (NDde.DdeException)
     {
         ddeVWAP.ForeColor = Color.Red;
         ddeVWAP.Text      = "Error DDE";
         CalibrateBot(false);
     }
 }
Exemplo n.º 18
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            try
            {
                // Connect to the server.  It must be running or an exception will be thrown.
                client.Connect();

                // Advise Loop
                client.StartAdvise("myitem", 1, true, 60000);
            }
            catch (Exception ex)
            {
                displayTextBox.Text = "MainForm_Load: " + ex.Message;
            }
        }
Exemplo n.º 19
0
 private void Form_Load(object sender, EventArgs e)
 {
     try
     {
         //申明并实例化一个DdeClient对象
         client         = new DdeClient("MT4", "BID", this);
         client.Advise += client_Advise;
         //连接到DDE服务器
         client.Connect();
         //循环获取数据
         client.StartAdvise("USDJPY", 1, true, 60000);
     }
     catch (Exception ex)
     {
         displayTextBox.Text = "MainForm_Load: " + ex.Message;
     }
 }
Exemplo n.º 20
0
 public void Test_StartAdvise_Variation_2()
 {
     using var server = new TestServer(ServiceName);
     server.Register();
     server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData));
     using var client = new DdeClient(ServiceName, TopicName);
     var listener = new EventListener();
     client.Advise += listener.OnEvent;
     client.Connect();
     client.StartAdvise(ItemName, 1, false, Timeout);
     server.Advise(TopicName, ItemName);
     Assert.IsTrue(listener.Received.WaitOne(Timeout, false));
     var args = (DdeAdviseEventArgs) listener.Events[0];
     Assert.AreEqual(ItemName, args.Item);
     Assert.AreEqual(1, args.Format);
     Assert.IsNull(args.Data);
     Assert.IsNull(args.Text);
 }
Exemplo n.º 21
0
 internal void Advise(string ticker, string col)
 {
     try
     {
         client.StartAdvise($"{ticker}.{col}", 1, true, 10);
         client.Advise += OnAdvise;
         CalibrateBot(true);
     }
     catch (NDde.DdeException)
     {
         ddeCurrentMeasureBot1.ForeColor = Color.Red;
         ddeCurrentMeasureBot1.Text      = "Error DDE";
         CalibrateBot(false);
     }
     finally
     {
         resetCalibBT.Focus();
     }
 }
Exemplo n.º 22
0
        public void Advise(string TagName)
        {
            if (TagNames.Contains(TagName))
            {
                return;
            }

            //ToDo: hier Prüfen, ob TagName gültig ist.
            TagNames.Add(TagName);

            try
            {
                // Create a client that connects to 'myapp|mytopic'.
                using (DdeClient dde_client = new DdeClient(DdeServerName, DdeTopic))
                {
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    dde_client.Disconnected += OnDisconnected;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    dde_client.Connect();

                    //Lese den Wert initial von DDE Server:
                    string TagValue = dde_client.Request(TagName, 60000);
                    UdpSend(TagName, TagValue);

                    //Lese den Wert von DDE Server neu ein bei Wertänderung.
                    // Advise Loop.
                    dde_client.StartAdvise(TagName, 1, true, 60000);

                    dde_client.Advise += OnAdvise2;

                    while (TagNames.Contains(TagName))
                    {
                        System.Threading.Thread.Sleep(DdeLoopTime);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.GetType().ToString() + "\r\n" + e.Message + "\r\n" + e.StackTrace);
            }
        }
Exemplo n.º 23
0
        override public void add(BooleanItem bi)
        {
            Console.WriteLine("Füge hinzu:" + bi.ToString() + " connected=" + connected);
            pool.Add(bi);
            if (connected)
            {
                ps.StartAdvise("%qx" + bi.byteAdr + "." + bi.bitAdr, 1, true, true, 60000, this);
                //ps.BeginRequest("%qx" + bi.byteAdr + "." + bi.bitAdr, 1, OnRequestComplete, ps);

                String s = ps.Request("%qx" + bi.byteAdr + "." + bi.bitAdr, 60000);
                //Console.WriteLine("Request=" + s);

                //Console.WriteLine("%qx" + bi.byteAdr + "." + bi.bitAdr + "=" + s);
                if (s.StartsWith("1"))
                {
                    bi.setState(true);
                }
                else
                {
                    bi.setState(false);
                }

                //Console.WriteLine("state)" + bi.getState());
            }
            else
            {
                Console.WriteLine("** Achtung Eingang hinzugefügt aber noch nicht verbunden !");
            }


            if (listener != null)
            {
                listener.outputChanged(bi);
            }
            else
            {
                Console.WriteLine("** Achtung Listener ist NULL!");
            }
        }
Exemplo n.º 24
0
        override public Boolean connect()
        {
            try
            {
                Console.WriteLine("DDE try Connect");
                ps.Connect();
                ps.StartAdvise(outMarke, 1, true, false, 60000, this);

                /*
                 * ThreadStart del;
                 * del = new ThreadStart(run);
                 * runner = new Thread(del);
                 * runner.Start();
                 */
                inValue    = 0;
                outValue   = 0;
                ps.Advise += OnAdvise;
                String s = ps.Request(outMarke, 60000);
                inValue = Int32.Parse(s);
                Console.WriteLine("inValue festgelegt auf" + inValue);
                connected = true;
                if (listener != null)
                {
                    listener.stateChanged("Connected");
                }
                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Connect Failed");
                if (listener != null)
                {
                    listener.stateChanged("Connection failed");
                }
                connected = false;
                return(false);
            }
        }
Exemplo n.º 25
0
 public void Test_StartAdvise_Variation_3()
 {
     using (TestServer server = new TestServer(ServiceName))
     {
         server.Register();
         server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData));
         using (DdeClient client = new DdeClient(ServiceName, TopicName))
         {
             EventListener listener = new EventListener();
             client.Advise += listener.OnEvent;
             client.Connect();
             client.StartAdvise(ItemName, 1, true, true, Timeout, "MyStateObject");
             server.Advise(TopicName, ItemName);
             Assert.IsTrue(listener.Received.WaitOne(Timeout, false));
             DdeAdviseEventArgs args = (DdeAdviseEventArgs)listener.Events[0];
             Assert.AreEqual(ItemName, args.Item);
             Assert.AreEqual(1, args.Format);
             Assert.AreEqual("MyStateObject", args.State);
             Assert.AreEqual(TestData, Encoding.ASCII.GetString(args.Data));
             Assert.AreEqual(TestData, args.Text);
         }
     }
 }
Exemplo n.º 26
0
        /** 新增項目(Item), 並取得該項目的值(Value)
         *   1. 呼叫 DdeClient 的 "Request()" & "StartAdvise" 取得該 Item 的值
         *   2. 利用 service|topic!item 字串為 key
         *   2.1 ht_gdv(HashTable) -> (key, DataGridViewRow)
         *   3. 在 dgItemInfo(DataGridView)新增一列, 顯示項目相關資訊
         *
         *   <param name="dc">     "新增項目" 按鈕事件所在列對應的 DdeClient
         *   <param name="item"> "新增項目" 名稱(Name)
         */
        private void AddItem(DdeClient dc, string item)
        {
            try
            {
                string key = dc.Service + "|" + dc.Topic + "!" + item;

                Item it = new Item();
                it.item = item; it.value = "";

                try
                {
                    //Synchronous Request Operation, 用以取得第一次呼叫的值
                    //eLeader, 康和 並未支援同步呼叫; yeswin/hts 則有支援
                    byte[] data     = dc.Request(item, 1, 60000);
                    int    codepage = Encoding.Default.CodePage; //取得編碼的 codpage. 中文 Default: 950
                    string value    = Encoding.GetEncoding(codepage).GetString(data, 0, data.Length);
                    //it.value = Encoding.ASCII.GetString(data);
                    it.value = value;
                }
                catch (Exception)
                {
                    ;  //忽略該錯誤
                }

                //Add a Row
                int idx = dgItemInfo.Rows.Add(dc.Service, dc.Topic, item, it.value);
                //保存 key 與 所在新增 Row
                ht_gdv.Add(key, dgItemInfo.Rows[idx]);

                // Advise Loop
                dc.StartAdvise(item, 1, true, 60000);
            }
            catch (Exception thrown)
            {
                MessageBox.Show("無法新增項目: \n" + thrown.Message);
            }
        }
Exemplo n.º 27
0
        private void setup_dde()
        {
            DataGridViewRowCollection DC = dgvDDESource.Rows;

            collectData.Clear();
            sendData.Clear();
            ddeList.Clear();
            list_clients.Clear();
            setupMarketDataDictionary();
            getMarketData();
            Thread.Sleep(1000);
            string[]      itemPostix = getPostfix();
            List <string> tmpSymbol  = new List <string>();

            //get items from datagridview
            foreach (DataGridViewRow dr in DC)
            {
                if (dr.Cells[0].Value == null || dr.Cells[0].Value.ToString() == "")
                {
                    MessageBox.Show("Symbol is null!!");
                    this.Invoke((MethodInvoker)(() => UIunlock()));
                    return;
                }
                else if (tmpSymbol.Contains(dr.Cells[0].Value.ToString()))
                {
                    MessageBox.Show("Duplucated Symbol!!");
                    this.Invoke((MethodInvoker)(() => UIunlock()));
                    return;
                }
                else
                {
                    tmpSymbol.Add(dr.Cells[0].Value.ToString());
                }



                if (dr.Cells[0].Value.ToString() != "" && dr.Cells[1].Value.ToString().ToLower() == "local")//local server dde
                {
                    // start advice dde item

                    if (dr.Cells[3].Value != null)
                    {
                        QuoteItem tmpItem = new QuoteItem();
                        tmpItem.sendItem.Add(dr.Cells[0].Value.ToString() + itemPostix[0]); // create dde sending price item
                        tmpItem.value         = Encoding.Default.GetBytes(dr.Cells[3].Value.ToString());
                        tmpItem.collectServer = "local";
                        tmpItem.type          = "C";
                        if (dr.Cells[2].Value == null || dr.Cells[2].Value.ToString() == "")
                        {
                            dr.Cells[2].Value = dr.Cells[0].Value.ToString();
                        }

                        tmpItem.collectTopic = dr.Cells[2].Value.ToString();
                        sendData.Add(tmpItem.sendItem[0], tmpItem);



                        QuoteItem tmpItemV = new QuoteItem();
                        tmpItemV.sendItem.Add(dr.Cells[0].Value.ToString() + itemPostix[1]); // create dde sending volume item
                        tmpItemV.value         = Encoding.Default.GetBytes("0");
                        tmpItemV.collectServer = "local";
                        tmpItemV.type          = "V";
                        tmpItemV.collectTopic  = dr.Cells[2].Value.ToString();
                        sendData.Add(tmpItemV.sendItem[0], tmpItemV);
                    }
                }
                else if (dr.Cells[0].Value.ToString() != "" && dr.Cells[1].Value.ToString() != "" && dr.Cells[2].Value.ToString() != "")
                {
                    try
                    {
                        // build up dde client server and topic
                        //each row has a ddeClient object
                        DdeClient tmpdde = new DdeClient(dr.Cells[1].Value.ToString(), dr.Cells[2].Value.ToString());
                        tmpdde.Connect();
                        if (tmpdde.IsConnected)
                        {
                            list_clients.Add(tmpdde);

                            // start advice dde item
                            for (int i = 3; i <= 8; i++)
                            {
                                string key = dr.Cells[1].Value.ToString() + "|" + dr.Cells[2].Value.ToString() + "!" + dr.Cells[i].Value.ToString();
                                if (dr.Cells[i].Value.ToString() != "" && !collectData.ContainsKey(key))
                                {
                                    tmpdde.StartAdvise(dr.Cells[i].Value.ToString(), 1, true, 6000);

                                    QuoteItem tmpItem = new QuoteItem();
                                    tmpItem.collectServer = dr.Cells[1].Value.ToString();
                                    tmpItem.collectItem   = key;
                                    tmpItem.sendItem.Add(dr.Cells[0].Value.ToString() + itemPostix[i - 3]); // create dde sending item
                                    collectData.Add(tmpItem.collectItem, tmpItem);
                                    foreach (string strItem in tmpItem.sendItem)
                                    {
                                        sendData.Add(strItem, tmpItem);
                                    }
                                }
                                else if (collectData.ContainsKey(key))//if tem is duplicated,skip to add collectData
                                {
                                    collectData[key].sendItem.Add(dr.Cells[0].Value.ToString() + itemPostix[i - 3]);
                                    sendData.Add(dr.Cells[0].Value.ToString() + itemPostix[i - 3], collectData[key]);
                                }
                            }

                            //check if use data filter
                            if (cbDataFilter.Checked)
                            {
                                tmpdde.Advise += OnAdviseFilter;
                            }
                            else
                            {
                                tmpdde.Advise += OnAdvise;
                            }
                        }
                        else
                        {
                            this.Invoke((MethodInvoker)(() => lbMsg.Items.Add(DateTime.Now.ToString("HH:mm:ss") + "   DDE has no Connection ")));
                        }
                    }
                    catch (Exception ex)
                    {
                        this.Invoke((MethodInvoker)(() => lbMsg.Items.Add(DateTime.Now.ToString("HH:mm:ss") + "   DDE Connection fail:" + ex.ToString())));
                    }
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Subscribe symbol in DDE server
        /// </summary>
        /// <param name="symbol">Symbol to subscribe</param>
        public void Subscribe(string symbol)
        {
            if (_ddeclient == null)
            {
                NotifyDDE("OFF Link DDE do CMA indisponível");
                return;
            }

            var today  = DateTime.Today;
            var Series = "FGHJKMNQUVXZ";

            symbol = _ddeclient.Service == "TWSVR" ? "0012" + symbol + ";1" : symbol + ".ult";

            #region If OPTION, define series
            if (symbol.Contains("#"))
            {
                //today = new DateTime(2013, 12, 17);
                var reff = new DateTime(today.Year, today.Month, 15);
                while (reff.DayOfWeek != DayOfWeek.Monday)
                {
                    reff = reff.AddDays(1);
                }

                if (reff <= today)
                {
                    reff = reff.AddMonths(1).AddDays(15 - reff.Day);
                    while (reff.DayOfWeek != DayOfWeek.Monday)
                    {
                        reff = reff.AddDays(1);
                    }
                }

                symbol = symbol.Replace('#', (char)(64 + reff.Month));
            }
            #endregion

            #region If INDFUT, define INDXYY
            if (symbol.Contains("FUT"))
            {
                //today = new DateTime(2013, 12, 18);
                var reff = new DateTime(today.Year, today.Month, 12);
                if (reff.Month % 2 != 0)
                {
                    reff = reff.AddMonths(1);
                }
                while (reff.DayOfWeek != DayOfWeek.Wednesday)
                {
                    reff = reff.AddDays(1);
                }

                if (reff <= today)
                {
                    reff = reff.AddMonths(1).AddDays(12 - reff.Day);
                    if (reff.Month % 2 != 0)
                    {
                        reff = reff.AddMonths(1);
                    }
                    while (reff.DayOfWeek != DayOfWeek.Wednesday)
                    {
                        reff = reff.AddDays(1);
                    }
                }

                symbol = symbol.Replace("FUT", Series[reff.Month - 1] + reff.ToString("yy")).Replace("12", "57");
            }
            #endregion

            if (!_timeofday.TryAdd(symbol, DateTime.Now) || !_lastprice.TryAdd(symbol, 0))
            {
                var msg = this._ddeserver ? "servidor DDE do CMA" : "servidor DDE do ProfitChart";
                NotifyDDE(msg + ". O ativo " + symbol + " já foi adicionado");
                return;
            }

            if (!_ddeclient.IsConnected)
            {
                try { _ddeclient.Connect(); }
                catch (Exception x) { NotifyDDE("OFF " + x.Message); }
                finally { _ddeclient.Advise += OnTickArrived; }
            }

            if (_ddeclient.IsConnected)
            {
                try { _ddeclient.StartAdvise(symbol, 1, true, 60000); }
                catch (Exception x) { NotifyDDE("OFF " + x.Message); }
            }
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            XmlDocument xml = new XmlDocument();

            try
            {
                xml.Load(@"tase.xml");
            }
            catch (Exception)
            {
                Console.WriteLine("File dde.xml was not found in current folder!");
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
                return;
            }

            Dictionary <string, string> myDict = new Dictionary <string, string>();
            XmlNodeList nodeList;
            XmlElement  root = xml.DocumentElement;

            nodeList = root.SelectNodes("/tase/option");
            foreach (XmlNode option in nodeList)
            {
                XmlNodeList optionsData = option.ChildNodes;
                string      opname      = "";
                string      id          = "";
                string      exp         = "";
                foreach (XmlNode op in optionsData)
                {
                    if (op.Name == "name")
                    {
                        opname = op.InnerText.Substring(0, 6);
                    }
                    else if (op.Name == "id")
                    {
                        id = op.InnerText;
                    }
                    else if (op.Name == "expiration")
                    {
                        DateTime dt = DateTime.ParseExact(op.InnerText, "dd/MM/yyyy",
                                                          CultureInfo.InvariantCulture);
                        exp = dt.Month.ToString();
                    }
                }
                //Console.Write("{0} {1}\n", opname+"_"+exp, id);
                myDict.Add(opname + "_" + exp, id);
            }

            // create a writer and open the file
            string filename = "data" + DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + ".txt";

            tw = new StreamWriter(filename);

            tw.WriteLine("DDE BIZPORTAL {0:MM/dd/yy}", DateTime.Now);
            string _myapp = "Star32";
            string _topic = "DDE";

            try
            {
                // Create a client that connects to 'myapp|topic'.
                using (DdeClient client = new DdeClient(_myapp, _topic))
                {
                    // Subscribe to the Disconnected event.  This event will notify the application when a conversation has been terminated.
                    client.Disconnected += OnDisconnected;

                    // Connect to the server.  It must be running or an exception will be thrown.
                    client.Connect();

                    // Advise Loop
                    foreach (KeyValuePair <string, string> pair in myDict)
                    {
                        foreach (string name in Enum.GetNames(typeof(DDE_VALUES)))
                        {
                            string advice = name + pair.Value;
                            client.StartAdvise(advice, 1, true, 60000);
                        }
                    }

                    client.Advise += OnAdvise;

                    // Wait for the user to press ENTER before proceding.
                    Console.WriteLine("Press Ctrl X to quit...");
                    ConsoleKeyInfo info = Console.ReadKey(true);
                    while (info.Key != ConsoleKey.X && info.Modifiers != ConsoleModifiers.Control)
                    {
                        info = Console.ReadKey(true);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("Press ENTER to quit...");
                Console.ReadLine();
            }

            // close the stream
            tw.Close();
        }
Exemplo n.º 30
0
        /// <summary>
        /// 監視開始関数
        /// </summary>
        private void Start()
        {
            _item = new Dictionary <string, string>()
            {
                //{ "最良売気配値1", ""},
                //{ "最良買気配値1", ""},
                //{ "最良買気配数量1", ""},
                //{ "最良売気配数量1", ""},
                { "現在値", "" },
                { "出来高", "" },
                { "出来高加重平均", "" },
                { "売買代金", "" },

                { "最良売気配値1", "" },
                { "最良売気配値2", "" },
                { "最良売気配値3", "" },
                { "最良売気配値4", "" },
                { "最良売気配値5", "" },
                { "最良売気配値6", "" },
                { "最良売気配値7", "" },
                { "最良売気配値8", "" },
                { "最良売気配値9", "" },
                { "最良売気配値10", "" },
                { "最良買気配値1", "" },
                { "最良買気配値2", "" },
                { "最良買気配値3", "" },
                { "最良買気配値4", "" },
                { "最良買気配値5", "" },
                { "最良買気配値6", "" },
                { "最良買気配値7", "" },
                { "最良買気配値8", "" },
                { "最良買気配値9", "" },
                { "最良買気配値10", "" },
                { "最良売気配数量1", "" },
                { "最良売気配数量2", "" },
                { "最良売気配数量3", "" },
                { "最良売気配数量4", "" },
                { "最良売気配数量5", "" },
                { "最良売気配数量6", "" },
                { "最良売気配数量7", "" },
                { "最良売気配数量8", "" },
                { "最良売気配数量9", "" },
                { "最良売気配数量10", "" },
                { "最良買気配数量1", "" },
                { "最良買気配数量2", "" },
                { "最良買気配数量3", "" },
                { "最良買気配数量4", "" },
                { "最良買気配数量5", "" },
                { "最良買気配数量6", "" },
                { "最良買気配数量7", "" },
                { "最良買気配数量8", "" },
                { "最良買気配数量9", "" },
                { "最良買気配数量10", "" },
                { "OVER気配数量", "" },
                { "UNDER気配数量", "" },
            };

            // DB作成
            CreateDatabase(txtCode.Text);

            // 監視開始
            client = new DdeClient("RSS", $"{txtCode.Text}.T", this);
            client.Disconnected += new EventHandler <DdeDisconnectedEventArgs>(OnDisconnected);
            client.Connect();
            foreach (string key in _item.Keys)
            {
                client.StartAdvise(key, 1, true, 60000);
                _count += 1;
            }
            client.Advise += new EventHandler <DdeAdviseEventArgs>(OnAdvise);
            _connection.Open();
        }