Announcement

Collapse
No announcement yet.

Using NDde framework for getting ESignal data feed

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using NDde framework for getting ESignal data feed

    Hi,
    I have been trying to extract ESignal data feed for my C# code and at times I am able to extract the feed and NDde interfacing seems to work well. But today when I switched on my computer and restarted my program, I encountered the following exception :

    Unhandled Exception: NDde.DdeException: The client failed to initiate an advise
    loop for "eSignal|EFS!DASConnector_TNA". ---> NDde.Foundation.DdemlException: Th
    e client failed to initiate an advise loop for "eSignal|EFS!DASConnector_TNA".
    at System.Windows.Forms.Control.MarshaledInvoke(Contr ol caller, Delegate meth
    od, Object[] args, Boolean synchronous)
    at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
    at NDde.Advanced.DdeContext.DdeThread.Invoke(Delegate method, Object[] args)
    at NDde.Client.DdeClient.StartAdvise(String item, Int32 format, Boolean hot,
    Boolean acknowledge, Int32 timeout, Object adviseState)
    --- End of inner exception stack trace ---
    at NDde.Client.DdeClient.StartAdvise(String item, Int32 format, Boolean hot,
    Boolean acknowledge, Int32 timeout, Object adviseState)
    at NDde.Client.DdeClient.StartAdvise(String item, Int32 format, Boolean hot,
    Int32 timeout)
    at ESignalDASConnectorDDE.ESignalDASConnectorDDEClien t..ctor(String service,
    String topic, String item) in C:\Users\0004\documents\visual studio 2010\Project
    s\ESignalDASConnectorDDE\ESignalDASConnectorDDE\Pr ogram.cs:line 93
    at ESignalDASConnectorDDE.ESignalDASConnectorDDEClien t.Main(String[] args) in
    C:\Users\0004\documents\visual studio 2010\Projects\ESignalDASConnectorDDE\ESig
    nalDASConnectorDDE\Program.cs:line 292


    I have also pasted the code I am trying to run. Can any one please help me out why there is no consistency in connecting with Esignal via Ndde framework. The error seems to be coming from runClient(service, topic, item); marked in red.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using NDde.Client;
    using daslibrary;
    
    namespace ESignalDASConnectorDDE
    {
        class ESignalDASConnectorDDEClient
        {
            private DdeClient client;
            private const int waitSeconds = 5;
            [NonSerialized()]
            private itemTrader itemtrader = null;
            [NonSerialized()]
            private EventHandler<OrderActiveArgs> orderEvent = null;
            [NonSerialized()]
            private EventHandler<Lv1Args> lv1Event = null;
            [NonSerialized()]
            private EventHandler<TradeArgs> tradeEvent = null;
    
            public static Dictionary<String, ESignalDASConnectorDDEClient> clientMap = new Dictionary<string, ESignalDASConnectorDDEClient>();
    
            private static SocketOrderServer sOS;
            private static SocketQuoteServer quoteServer = null;
            private static int masterTraderID;
            private static string mrrno;
            private static string masterTraderName;
            private static int brokerID;
            private static string route = "ARCA";
            private static int masterAccountID = 53;
            private static string username = "DON920";
            private static string password = "zd121212";
            private static int orderPort = 7500;
            private static int quotePort = 9510;
            private static string orderServer = "68.168.209.226";
            private static string quoteServerAddress = "207.251.85.80";
    
            private double askPrice = 0;
            private double bidPrice = 0;
            private long bidSize = 0;
            private long askSize = 0;
            private double lastTradedPrice = 0;
            private string symbol = "";
            private byte exch;
            private bool isQuoteSet = false;
    
        
            //Async event call mechanism for handling level1 quotes
            private void Lv1Handler(object sender, Lv1Args la)
            {
                if (la.TheIssuIfo.secsym.Equals(this.symbol))
                {
                    this.askPrice = la.TheIssuIfo.l1_AskPrice;
                    this.bidPrice = la.TheIssuIfo.l1_BidPrice;
                    this.bidSize = la.TheIssuIfo.l1_BidSize;
                    this.askSize = la.TheIssuIfo.l1_AskSize;
                    this.lastTradedPrice = la.TheIssuIfo.l1_lastPrice;
                    this.exch = la.TheIssuIfo.PrimExch;
                    isQuoteSet = true;
                }
            }
    
            public void OrderActiveHandler(object sender, OrderActiveArgs oa)
            {
    
            }
    
            public void TradeActiveHandler(object sender, TradeArgs ta)
            {
    
            }
    
            public ESignalDASConnectorDDEClient(string service, string topic, string item)
            {
                client = new DdeClient(service, topic);
                this.symbol = item.Substring(item.IndexOf("_") + 1);
               
                if (ESignalDASConnectorDDEClient.sOS == null || !ESignalDASConnectorDDEClient.sOS.IsConnected())
                {
                    this.connectSocketOrderServer();
                }
                this.orderEvent = new EventHandler<OrderActiveArgs>(OrderActiveHandler);
                this.lv1Event = new EventHandler<Lv1Args>(Lv1Handler);
                this.tradeEvent = new EventHandler<TradeArgs>(this.TradeActiveHandler);
                sOS.eventPool.Subscribe("Trade", this.tradeEvent);
                sOS.eventPool.Subscribe("Order", this.orderEvent);
                sOS.eventPool.Subscribe("Lv1", this.lv1Event);
                client.Disconnected += OnDisconnected;
                client.Connect();
                client.Advise += OnAdvise;
               [B] [COLOR="#FF0000"]runClient(service, topic, item);[/COLOR][/B]
            }
    
            private void connectSocketOrderServer()
            {
                sOS = new SocketOrderServer();
                sOS.Connect(orderServer, orderPort);
                sOS.PkgLongin(username, password, orderServer);
    
                int timeout = 0;
                while (timeout <= waitSeconds * 1000) // wait waitseconds(default =3) seconds
                {
                    timeout += 500;
                    System.Threading.Thread.Sleep(500);
                    itemtrader = sOS.sitemTrader.FindItemByName(username);
    
                    if (itemtrader != null)
                    {
                        System.Console.WriteLine("DAS Connection established");
                        try
                        {
                            quoteServer = new SocketQuoteServer(sOS);
                            quoteServer.Connect(quoteServerAddress, quotePort);
                            quoteServer.PkgLogin(username, password, quoteServerAddress);
                            masterTraderName = username;
                            masterTraderID = itemtrader.mtrid;
                            System.Console.WriteLine("MasterID " + masterTraderID);
                            brokerID = itemtrader.mbrid; //Ask Don for brokerid
                            System.Console.WriteLine("BrokerID " + brokerID);
                            mrrno = sOS.sitemAccount.FindItem(masterAccountID).mitemifo.mrrno; //Ask why at times this gives out null reference exception
                            
                        }
                        catch (Exception e)
                        {
                            System.Console.WriteLine(e.StackTrace);
                        }
                        break;
                    }
                }
    
                if (timeout > waitSeconds * 1000)
                {
                    System.Console.WriteLine("Connection problem and timed out");
                    Environment.Exit(0);
                }
    
            }
    
            private void runClient(string service, string topic, string item)
            {
                if (client != null)
                {
                   client.StartAdvise(item, 1, true, 60000);
                }
                
            }
    
            private static void OnExecuteComplete(IAsyncResult ar)
            {
                try
                {
                    DdeClient client = (DdeClient)ar.AsyncState;
                    client.EndExecute(ar);
                    Console.WriteLine("OnExecuteComplete");
                }
                catch (Exception e)
                {
                    Console.WriteLine("OnExecuteComplete: " + e.Message);
                }
            }
    
            private static void OnPokeComplete(IAsyncResult ar)
            {
                try
                {
                    DdeClient client = (DdeClient)ar.AsyncState;
                    client.EndPoke(ar);
                    Console.WriteLine("OnPokeComplete");
                }
                catch (Exception e)
                {
                    Console.WriteLine("OnPokeComplete: " + e.Message);
                }
            }
    
            private static void OnRequestComplete(IAsyncResult ar)
            {
                try
                {
                    DdeClient client = (DdeClient)ar.AsyncState;
                    byte[] data = client.EndRequest(ar);
                    Console.WriteLine("OnRequestComplete: " + Encoding.ASCII.GetString(data));
                }
                catch (Exception e)
                {
                    Console.WriteLine("OnRequestComplete: " + e.Message);
                }
            }
    
            private static void OnStartAdviseComplete(IAsyncResult ar)
            {
                try
                {
                    DdeClient client = (DdeClient)ar.AsyncState;
                    client.EndStartAdvise(ar);
                    Console.WriteLine("OnStartAdviseComplete");
                }
                catch (Exception e)
                {
                    Console.WriteLine("OnStartAdviseComplete: " + e.Message);
                }
            }
    
            private static void OnStopAdviseComplete(IAsyncResult ar)
            {
                try
                {
                    DdeClient client = (DdeClient)ar.AsyncState;
                    client.EndStopAdvise(ar);
                    Console.WriteLine("OnStopAdviseComplete");
                }
                catch (Exception e)
                {
                    Console.WriteLine("OnStopAdviseComplete: " + e.Message);
                }
            }
    
            private static void OnAdvise(object sender, DdeAdviseEventArgs args)
            {
                Console.WriteLine("OnAdvise: " + args.Text);
                string[] splitString = args.Text.Split(new char[] {','});
                bool isMarketOrder = splitString[0].Equals("MARKET") ? true : false;
                double tradePrice = Double.Parse(splitString[1]);
                int lotSize = Int32.Parse(splitString[2]);
                bool isBuyOrder = (splitString[3].Equals("LONG") || splitString[3].Equals("Cover")) ? true : false;
                ESignalDASConnectorDDEClient.quoteServer.WLSTAddWatch(splitString[4]);
                while (!ESignalDASConnectorDDEClient.clientMap[splitString[4]].isQuoteSet);
                ESignalDASConnectorDDEClient.quoteServer.WLSTRemoveWatch(splitString[4]);
                ESignalDASConnectorDDEClient.clientMap[splitString[4]].createOrder(splitString[4], lotSize, tradePrice, isBuyOrder,isMarketOrder);
            }
    
            private static void OnDisconnected(object sender, DdeDisconnectedEventArgs args)
            {
                Console.WriteLine(
                    "OnDisconnected: " +
                    "IsServerInitiated=" + args.IsServerInitiated.ToString() + " " +
                    "IsDisposed=" + args.IsDisposed.ToString());
            }
    
            private itemOrder createOrder(string symbol, int qty, double executionPrice, bool isBuyOrder, bool isMarketOrder)
            {
                itemOrder iOrder = new itemOrder();
                iOrder.mstatus = 0;
    
                if (isMarketOrder == true)
                {
                    iOrder.mstatus |= 1 << 9; // placing market order
    
                    if (isBuyOrder == true)
                    {
                        iOrder.mstatus |= 1 << 6;
                        iOrder.mprice = this.askPrice;
                    }
                    else
                    {
                        iOrder.mprice = this.bidPrice;
                    }
                }
                else
                {
                    if (isBuyOrder == true)
                    {
                        iOrder.mstatus |= 1 << 6;
                    }
                    iOrder.mprice = executionPrice;
                    iOrder.mtmforce = 65535;
                }
    
                iOrder.msecsym = symbol;
                iOrder.mqty = qty;
                iOrder.mroute = route;
                iOrder.maccid = masterAccountID;
                iOrder.mtrid = masterTraderID;
                iOrder.mbrid = brokerID;
                iOrder.mrrno = mrrno;
                iOrder.mexchange = this.exch;
    
                return iOrder;
            }
    
            static void Main(string[] args)
            {
                ESignalDASConnectorDDEClient []client = new ESignalDASConnectorDDEClient[6];
                String[] builder = {"TNA"};/*,"FAS","GLD","SPY"};*/
                int i = 0;
                while (true)
                {
                    if(client[i] == null && i < builder.Length)
                    {
                        client[i] = new ESignalDASConnectorDDEClient("eSignal", "EFS", "DASConnector_" + builder[i]); //DASConnector_
                        clientMap.Add(builder[i], client[i]);
                        i++;
                    }
                }
            }
        }
    }

    Thanks and Regards,
    Vipin

  • #2
    When accessing QLink by NDDE you use "eSignal", "EFS" to access EFS script. What do you need to use the get the QLink updates themself?

    Comment


    • #3
      In order to get QLINK to update you must have the QLINK/RTD entitlement and use the proper function calls. Here is a link for the QLINK overview. In the article you'll also see the syntax used for requesting data.

      Comment


      • #4
        Thank you for the link. I do have QLink. But that documentation has just an explenation for RTD.
        Meaning these are all =RTD() function calls in Excel.
        But I would like to use DDE. Even if it is the older technology it is much better for realtime quotes and generates much lower load in Excel!

        These functions would look like =eSignal|EFS!<objectname>
        But that would just be for EFS calls.
        But I do not know the syntax for Quote-Updates (like maybe the Nasdaq Last field).

        Comment

        Working...
        X