Пример #1
0
        private void TLSend_Handle(string message, MessageTypes type, IntPtr source, IntPtr dest)
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke(new tlsenddel(TLSend_Handle), new object[] { message, type, self, dest });
                }
#if DEBUG
                catch (Exception ex)
                {
                    debug("error invoking tlsend_handle: " + ex.Message + ex.StackTrace);
                }
#else
                catch { }
#endif
            }
            else
            {
                try
                {
                    var senderr = WMUtil.SendMsg(message, dest, source, (int)type);
#if DEBUG
                    if (VerboseDebugging)
                    {
                        debug(Text + " sent: " + type + " to " + dest + " data: " + message);
                    }
#endif
                }
                catch (Exception ex)
                {
                    debug(Text + " error sending: " + type + " to " + dest + " err: " + ex.Message + ex.StackTrace);
                }
            }
        }
Пример #2
0
 public void newImbalance(Imbalance imb)
 {
     for (int i = 0; i < client.Count; i++)
     {
         WMUtil.SendMsg(ImbalanceImpl.Serialize(imb), hims[i], Handle, (int)MessageTypes.IMBALANCERESPONSE);
     }
 }
Пример #3
0
 // server to clients
 /// <summary>
 /// Notifies subscribed clients of a new tick.
 /// </summary>
 /// <param name="tick">The tick to include in the notification.</param>
 public void newTick(Tick tick)
 {
     if (this.InvokeRequired)
     {
         try
         {
             this.Invoke(new TickDelegate(newTick), new object[] { tick });
         }
         catch (Exception) { }
     }
     else
     {
         if (!tick.isValid)
         {
             return;                            // need a valid tick
         }
         for (int i = 0; i < client.Count; i++) // send tick to each client that has subscribed to tick's stock
         {
             if ((client[i] != null) && (stocks[i].Contains(tick.symbol)))
             {
                 WMUtil.SendMsg(TickImpl.Serialize(tick), hims[i], self, (int)MessageTypes.TICKNOTIFY);
             }
         }
     }
 }
Пример #4
0
 public void newOrderCancel(long orderid_being_cancled)
 {
     foreach (string c in client) // send order cancel notifcation to clients
     {
         WMUtil.SendMsg(orderid_being_cancled.ToString(), MessageTypes.ORDERCANCELRESPONSE, Handle, c);
     }
 }
Пример #5
0
        public static long SendMsg(string str, System.IntPtr desthandle, System.IntPtr sourcehandle, int type, int timeout)
        {
            if ((desthandle == IntPtr.Zero) || (sourcehandle == IntPtr.Zero))
            {
                return(-1);                                                              // fail on invalid handles
            }
            WMUtil.COPYDATASTRUCT cds = new WMUtil.COPYDATASTRUCT();
            cds.dwData = (IntPtr)type;
            str        = str + '\0';
            cds.cbData = str.Length + 1;

            System.IntPtr pData = Marshal.StringToCoTaskMemAnsi(str);

            cds.lpData = pData;

            IntPtr res = IntPtr.Zero;
            IntPtr err = WMUtil.SendMessageTimeout(desthandle, (uint)WM_COPYDATA, (IntPtr)sourcehandle, IntPtr.Zero, SendMessageTimeoutFlags.SMTO_NORMAL, (uint)timeout, out res);

            if (err == IntPtr.Zero)
            {
                return(0);
            }
            Marshal.FreeCoTaskMem(pData);
            return(res.ToInt64());
        }
Пример #6
0
        public bool Mode(int ProviderIndex, bool showwarning)
        {
            _linktype = TLTypes.NONE; // reset before changing link mode
            if ((ProviderIndex >= srvrwin.Count) || (ProviderIndex < 0))
            {
                if (showwarning)
                {
                    System.Windows.Forms.MessageBox.Show("Invalid broker specified or no brokers running.", "TradeLink server not found");
                }
                return(false);
            }

            try
            {
                Disconnect();
                himh      = WMUtil.HisHandle(srvrwin[ProviderIndex]);
                _linktype = TLTypes.LIVEBROKER;
                Register();
                RequestFeatures();
                _curprovider = ProviderIndex;
                return(true);
            }
            catch (TLServerNotFound)
            {
                if (showwarning)
                {
                    System.Windows.Forms.MessageBox.Show("No Live broker instance was found.  Make sure broker application + TradeLink server is running.", "TradeLink server not found");
                }
                return(false);
            }
            catch (Exception) { return(false); }
        }
Пример #7
0
 public void TLSend(string message, MessageTypes type, string client)
 {
     if (client == "")
     {
         return;
     }
     WMUtil.SendMsg(message, type, Handle, client);
 }
Пример #8
0
 public TLClient_WM(string clientname, bool showarmingonmissingserver, bool handleexceptions)
     : base()
 {
     this.Text          = WMUtil.GetUniqueWindow(clientname);
     this.WindowState   = FormWindowState.Minimized;
     this.ShowInTaskbar = false;
     this.Hide();
     this.Mode(this.TLFound(), handleexceptions, showarmingonmissingserver);
 }
Пример #9
0
 public TLClient_WM(int ProviderIndex, string clientname, bool showarmingonmissingserver)
     : base()
 {
     this.Text          = WMUtil.GetUniqueWindow(clientname);
     gotFeatures       += new MessageTypesMsgDelegate(TLClient_WM_gotFeatures);
     this.WindowState   = FormWindowState.Minimized;
     this.ShowInTaskbar = false;
     this.Hide();
     this.Mode(ProviderIndex, showarmingonmissingserver);
 }
Пример #10
0
        public TLServer_WM() : base()
        {
            MinorVer = Util.BuildFromRegistry(Util.PROGRAM);

            this.Text        = WMUtil.GetUniqueWindow(WMUtil.SERVERWINDOW);
            this.WindowState = FormWindowState.Minimized;
            this.Show();
            this.ShowInTaskbar = false;
            this.Hide();
        }
Пример #11
0
        /// <summary>
        /// Gets a handle for a given window name.  Will return InPtr.Zero if no match is found.
        /// </summary>
        /// <param name="WindowName">Name of the window.</param>
        /// <returns></returns>
        public static IntPtr HisHandle(string WindowName)
        {
            IntPtr p = IntPtr.Zero;

            try
            {
                p = WMUtil.FindWindow(null, WindowName);
            }
            catch (NullReferenceException) { }
            return(p);
        }
Пример #12
0
 public void TLSend(string message, MessageTypes type, IntPtr dest)
 {
     if (InvokeRequired)
     {
         Invoke(new tlsenddel(TLSend), new object[] { message, type, dest });
     }
     else
     {
         WMUtil.SendMsg(message, dest, Handle, (int)type);
     }
 }
Пример #13
0
        public TLServer_WM() : base()
        {
            MinorVer = Util.BuildFromRegistry(Util.PROGRAM);

            this.Text        = WMUtil.GetUniqueWindow(WMUtil.SERVERWINDOW);
            this.WindowState = FormWindowState.Minimized;
            this.Show();
            this.ShowInTaskbar = false;
            this.Hide();
            //WMUtil.SendMsg(Text, (IntPtr)WMUtil.HWND_BROADCAST, Handle, (int)MessageTypes.SERVERUP);
        }
Пример #14
0
 void SrvRegClient(string cname)
 {
     if (client.IndexOf(cname) != -1)
     {
         return;                              // already registered
     }
     client.Add(cname);
     heart.Add(DateTime.Now);
     stocks.Add("");
     index.Add("");
     hims.Add(WMUtil.HisHandle(cname));
     SrvBeatHeart(cname);
 }
Пример #15
0
 public long TLSend(MessageTypes type, string m)
 {
     if (InvokeRequired)
     {
         return((long)Invoke(new TLSendDelegate(TLSend), new object[] { type, m }));
     }
     else
     {
         if (himh == IntPtr.Zero)
         {
             throw new TLServerNotFound();
         }
         long res = WMUtil.SendMsg(m, himh, Handle, (int)type);
         return(res);
     }
 }
Пример #16
0
 public void newOrder(Order o, bool allclients)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new tlneworderdelegate(newOrder), new object[] { o, allclients });
     }
     else
     {
         for (int i = 0; i < client.Count; i++)
         {
             if ((client[i] != null) && (client[i] != "") && (stocks[i].Contains(o.symbol) || allclients))
             {
                 WMUtil.SendMsg(OrderImpl.Serialize(o), MessageTypes.ORDERNOTIFY, Handle, client[i]);
             }
         }
     }
 }
Пример #17
0
        public TLTypes TLFound()
        {
            TLTypes f = TLTypes.NONE;

            if (WMUtil.Found(WMUtil.SIMWINDOW))
            {
                f |= TLTypes.SIMBROKER;
            }
            if (WMUtil.Found(WMUtil.LIVEWINDOW))
            {
                f |= TLTypes.LIVEBROKER;
            }
            if (WMUtil.Found(WMUtil.REPLAYWINDOW))
            {
                f |= TLTypes.HISTORICALBROKER;
            }
            return(f);
        }
Пример #18
0
        public bool Mode(int ProviderIndex, bool showwarning)
        {
            if (InvokeRequired)
            {
                bool v = false;
                try
                {
                    v = (bool)Invoke(new ModeDel(Mode), new object[] { ProviderIndex, showwarning });
                }
                catch { v = false; }
                return(v);
            }
            else
            {
                TLFound();
                if ((ProviderIndex >= srvrwin.Count) || (ProviderIndex < 0))
                {
                    if (showwarning)
                    {
                        System.Windows.Forms.MessageBox.Show("Invalid broker specified or no brokers running.", "TradeLink server not found");
                    }
                    return(false);
                }

                try
                {
                    Disconnect();
                    himh = WMUtil.HisHandle(srvrwin[ProviderIndex]);
                    Register();
                    RequestFeatures();
                    _curprovider = ProviderIndex;
                    return(true);
                }
                catch (TLServerNotFound)
                {
                    if (showwarning)
                    {
                        System.Windows.Forms.MessageBox.Show("No Live broker instance was found.  Make sure broker application + TradeLink server is running.", "TradeLink server not found");
                    }
                    return(false);
                }
                catch (Exception) { return(false); }
            }
        }
Пример #19
0
        /// <summary>
        /// Sends the MSG.
        /// </summary>
        /// <param name="str">The STR.</param>
        /// <param name="desthandle">The desthandle.</param>
        /// <param name="sourcehandle">The sourcehandle.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static long SendMsg(string str, System.IntPtr desthandle, System.IntPtr sourcehandle, int type)
        {
            if ((desthandle == IntPtr.Zero) || (sourcehandle == IntPtr.Zero))
            {
                return(-1); // fail on invalid handles
            }
            WMUtil.COPYDATASTRUCT cds = new WMUtil.COPYDATASTRUCT();
            cds.dwData = (IntPtr)type;
            str        = str + '\0';
            cds.cbData = str.Length + 1;

            System.IntPtr pData = Marshal.StringToCoTaskMemAnsi(str);

            cds.lpData = pData;

            IntPtr res = WMUtil.SendMessage(desthandle, WMUtil.WM_COPYDATA, (int)sourcehandle, ref cds);

            Marshal.FreeCoTaskMem(pData);
            return(res.ToInt64());
        }
Пример #20
0
        private bool addserver(string name)
        {
            // if server not running, don't add it
            if (!WMUtil.Found(name))
            {
                return(false);
            }
            // if it is running, get the handle
            IntPtr hand = WMUtil.HisHandle(name);
            // get broker name
            Providers p = (Providers)WMUtil.SendMsg(string.Empty, hand, Handle, (int)MessageTypes.BROKERNAME);

            if (p == Providers.Unknown)
            {
                return(false);
            }
            servers.Add(p);
            srvrwin.Add(name);
            return(true);
        }
Пример #21
0
 public void newFill(Trade trade, bool allclients)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new tlnewfilldelegate(newFill), new object[] { trade, allclients });
     }
     else
     {
         // make sure our trade is filled and initialized properly
         if (!trade.isValid)
         {
             return;
         }
         for (int i = 0; i < client.Count; i++) // send tick to each client that has subscribed to tick's stock
         {
             if ((client[i] != null) && (allclients || (stocks[i].Contains(trade.symbol))))
             {
                 WMUtil.SendMsg(TradeImpl.Serialize(trade), MessageTypes.EXECUTENOTIFY, Handle, client[i]);
             }
         }
     }
 }
Пример #22
0
 public long TLSend(MessageTypes type, string m, IntPtr dest)
 {
     if (InvokeRequired)
     {
         // ensure that our object is still running before we message from it
         try
         {
             return((long)Invoke(new TLSendDelegate(TLSend), new object[] { type, m, dest }));
         }
         catch (NullReferenceException) { }
         catch (ObjectDisposedException) { }
         return(0);
     }
     else
     {
         if (dest == IntPtr.Zero)
         {
             throw new TLServerNotFound();
         }
         long res = WMUtil.SendMsg(m, dest, Handle, (int)type);
         return(res);
     }
 }
Пример #23
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            long             result = 0;
            TradeLinkMessage tlm    = WMUtil.ToTradeLinkMessage(ref m);

            if (tlm == null)         // if it's not a WM_COPYDATA message
            {
                base.WndProc(ref m); // let form process it
                return;              // we're done
            }

            string msg = tlm.body;

            switch (tlm.type)
            {
            case MessageTypes.TICKNOTIFY:
                Tick t;
                try
                {
                    t = TickImpl.Deserialize(msg);
                }
                catch (Exception ex)
                {
                    _tickerrors++;
                    debug("Error processing tick: " + msg);
                    debug("TickErrors: " + _tickerrors);
                    debug("Error: " + ex.Message + ex.StackTrace);
                    break;
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;

            case MessageTypes.ORDERCANCELRESPONSE:
            {
                long id = 0;
                if (gotOrderCancel != null)
                {
                    if (long.TryParse(msg, out id))
                    {
                        gotOrderCancel(id);
                    }
                    else if (SendDebugEvent != null)
                    {
                        SendDebugEvent("Count not parse order cancel: " + msg);
                    }
                }
            }
            break;

            case MessageTypes.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                try
                {
                    Trade tr = TradeImpl.Deserialize(msg);
                    if (gotFill != null)
                    {
                        gotFill(tr);
                    }
                }
                catch (Exception ex)
                {
                    debug("error deserializing fill: " + msg);
                    debug("error: " + ex.Message + ex.StackTrace);
                    debug("broker: " + BrokerName);
                }
                break;

            case MessageTypes.ORDERNOTIFY:
                try
                {
                    Order o = OrderImpl.Deserialize(msg);
                    if (gotOrder != null)
                    {
                        gotOrder(o);
                    }
                }
                catch (Exception ex)
                {
                    debug("error deserializing order: " + msg);
                    debug("error: " + ex.Message + ex.StackTrace);
                    debug("broker: " + BrokerName);
                }
                break;

            case MessageTypes.POSITIONRESPONSE:
                try
                {
                    Position pos = PositionImpl.Deserialize(msg);
                    if (gotPosition != null)
                    {
                        gotPosition(pos);
                    }
                }
                catch (Exception ex)
                {
                    if (SendDebugEvent != null)
                    {
                        SendDebugEvent(msg + " " + ex.Message + ex.StackTrace);
                    }
                }
                break;

            case MessageTypes.ACCOUNTRESPONSE:
                if (gotAccounts != null)
                {
                    gotAccounts(msg);
                }
                break;

            case MessageTypes.FEATURERESPONSE:
                string[]            p = msg.Split(',');
                List <MessageTypes> f = new List <MessageTypes>();
                foreach (string s in p)
                {
                    try
                    {
                        f.Add((MessageTypes)Convert.ToInt32(s));
                    }
                    catch (Exception) { }
                }
                if (gotFeatures != null)
                {
                    gotFeatures(f.ToArray());
                }
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(tlm.type, 0, 0, 0, string.Empty, ref tlm.body);
                }
                break;

            case MessageTypes.SERVERDOWN:
                if (gotServerDown != null)
                {
                    gotServerDown(msg);
                }
                break;

            case MessageTypes.SERVERUP:
                if (gotServerUp != null)
                {
                    gotServerUp(msg);
                }
                break;

            default:
                if (gotUnknownMessage != null)
                {
                    gotUnknownMessage(tlm.type, 0, 0, 0, string.Empty, ref tlm.body);
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }
Пример #24
0
 /// <summary>
 /// Makes TL client use Broker Simulation mode (Broker must be logged in and TradeLink loaded)
 /// </summary>
 public void GoSim()
 {
     Disconnect(); himh = WMUtil.HisHandle(WMUtil.SIMWINDOW); LinkType = TLTypes.SIMBROKER;  Register();
 }
Пример #25
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            long             result = 0;
            TradeLinkMessage tlm    = WMUtil.ToTradeLinkMessage(ref m);

            if (tlm == null)         // if it's not a WM_COPYDATA message
            {
                base.WndProc(ref m); // let form process it
                return;              // we're done
            }

            string msg = tlm.body;

            string[] r = msg.Split(',');
            switch (tlm.type)
            {
            case MessageTypes.ORDERCANCELRESPONSE:
                if (gotOrderCancel != null)
                {
                    gotOrderCancel(Convert.ToUInt32(msg));
                }
                break;

            case MessageTypes.TICKNOTIFY:
                Tick t = TickImpl.Deserialize(msg);
                if (t.isTrade)
                {
                    try
                    {
                        if (t.trade > chighs[t.symbol])
                        {
                            chighs[t.symbol] = t.trade;
                        }
                        if (t.trade < clows[t.symbol])
                        {
                            clows[t.symbol] = t.trade;
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        chighs.Add(t.symbol, 0);
                        clows.Add(t.symbol, decimal.MaxValue);
                    }
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case MessageTypes.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                Trade tr = TradeImpl.Deserialize(msg);
                if (gotFill != null)
                {
                    gotFill(tr);
                }
                break;

            case MessageTypes.ORDERNOTIFY:
                Order o = OrderImpl.Deserialize(msg);
                if (gotOrder != null)
                {
                    gotOrder(o);
                }
                break;

            case MessageTypes.POSITIONRESPONSE:
                Position pos = PositionImpl.Deserialize(msg);
                if (gotPosition != null)
                {
                    gotPosition(pos);
                }
                break;

            case MessageTypes.ACCOUNTRESPONSE:
                if (gotAccounts != null)
                {
                    gotAccounts(msg);
                }
                break;

            case MessageTypes.FEATURERESPONSE:
                string[]            p = msg.Split(',');
                List <MessageTypes> f = new List <MessageTypes>();
                foreach (string s in p)
                {
                    try
                    {
                        f.Add((MessageTypes)Convert.ToInt32(s));
                    }
                    catch (Exception) { }
                }
                if (gotSupportedFeatures != null)
                {
                    gotSupportedFeatures(f.ToArray());
                }
                break;

            case MessageTypes.IMBALANCERESPONSE:
                Imbalance i = ImbalanceImpl.Deserialize(msg);
                if (gotImbalance != null)
                {
                    gotImbalance(i);
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }
Пример #26
0
 /// <summary>
 /// Attemptions connection to TL Replay Server
 /// </summary>
 public void GoHist()
 {
     Disconnect(); himh = WMUtil.HisHandle(WMUtil.REPLAYWINDOW); LinkType = TLTypes.HISTORICALBROKER; Register();
 }
Пример #27
0
        /// <summary>
        /// Sends the MSG from source window to destination window, using WM_COPYDATA.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="messagetype">The messagetype.</param>
        /// <param name="destinationwindow">The destinationwindow.</param>
        /// <returns></returns>
        public static long SendMsg(string message, MessageTypes messagetype, IntPtr sourcehandle, string destinationwindow)
        {
            IntPtr him = WMUtil.HisHandle(destinationwindow);

            return(WMUtil.SendMsg(message, him, sourcehandle, (int)messagetype));
        }
Пример #28
0
 public long TLSend(MessageTypes type, string m, int ProviderIndex)
 {
     return(((ProviderIndex < 0) || (ProviderIndex > srvrwin.Count)) ? 0 : TLSend(type, m, WMUtil.HisHandle(srvrwin[ProviderIndex])));
 }
Пример #29
0
 /// <summary>
 /// Used for testing the TL-BROKER api (programmatically)
 /// </summary>
 public void GoTest()
 {
     Disconnect(); himh = WMUtil.HisHandle(WMUtil.TESTWINDOW); LinkType = TLTypes.TESTBROKER; Register();
 }
Пример #30
0
 /// <summary>
 /// Makes TL client use Broker LIVE server (Broker must be logged in and TradeLink loaded)
 /// </summary>
 public void GoLive()
 {
     Disconnect(); himh = WMUtil.HisHandle(WMUtil.LIVEWINDOW); LinkType = TLTypes.LIVEBROKER; Register();
 }