public void newOrderCancel(long orderid_being_cancled)
 {
     foreach (string c in client) // send order cancel notifcation to clients
     {
         WMUtil.SendMsg(orderid_being_cancled.ToString(), TL2.ORDERCANCELRESPONSE, Handle, c);
     }
 }
        protected long TLSend(TL2 type, string m)
        {
            if (himh == IntPtr.Zero)
            {
                throw new TLServerNotFound();
            }
            long res = WMUtil.SendMsg(m, himh, Handle, (int)type);

            return(res);
        }
 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(o.Serialize(), TL2.ORDERNOTIFY, Handle, client[i]);
             }
         }
     }
 }
 public void newIndexTick(Index itick)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(new IndexDelegate(newIndexTick), new object[] { itick });
     }
     else
     {
         if (!itick.isValid)
         {
             return;
         }
         for (int i = 0; i < index.Count; i++)
         {
             if ((client[i] != null) && (index[i].Contains(itick.Name)))
             {
                 WMUtil.SendMsg(itick.Serialize(), TL2.TICKNOTIFY, Handle, client[i]);
             }
         }
     }
 }
 // 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)
     {
         this.Invoke(new TickDelegate(newTick), new object[] { tick });
     }
     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.sym)))
             {
                 WMUtil.SendMsg(tick.Serialize(), TL2.TICKNOTIFY, Handle, client[i]);
             }
         }
     }
 }
 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 || !trade.isFilled)
         {
             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) && ((stocks[i].Contains(trade.symbol) || allclients)))
             {
                 WMUtil.SendMsg(trade.Serialize(), TL2.EXECUTENOTIFY, Handle, client[i]);
             }
         }
     }
 }
        protected override void WndProc(ref Message m)
        {
            TradeLinkMessage tlm = WMUtil.ToTradeLinkMessage(ref m);

            if (tlm == null)
            {
                base.WndProc(ref m);
                return;
            }
            string msg = tlm.body;

            long result = (long)TL2.OK;

            switch (tlm.type)
            {
            case TL2.ACCOUNTOPENPL:
                if (gotSrvAcctOpenPLRequest == null)
                {
                    break;
                }
                result = WMUtil.pack(gotSrvAcctOpenPLRequest(msg));
                break;

            case TL2.ACCOUNTCLOSEDPL:
                if (gotSrvAcctClosedPLRequest == null)
                {
                    break;
                }
                result = WMUtil.pack(gotSrvAcctClosedPLRequest(msg));
                break;

            case TL2.ACCOUNTREQUEST:
                if (gotSrvAcctRequest == null)
                {
                    break;
                }
                WMUtil.SendMsg(gotSrvAcctRequest(), TL2.ACCOUNTRESPONSE, Handle, msg);
                break;

            case TL2.ORDERCANCELREQUEST:
                if (OrderCancelRequest != null)
                {
                    OrderCancelRequest(Convert.ToUInt32(msg));
                }
                break;

            case TL2.GETSIZE:
                if (PositionSizeRequest != null)
                {
                    result = PositionSizeRequest(msg);
                }
                break;

            case TL2.AVGPRICE:
                if (PositionPriceRequest != null)
                {
                    result = WMUtil.pack(PositionPriceRequest(msg));
                }
                break;

            case TL2.NDAYHIGH:
                if (DayHighRequest != null)
                {
                    result = WMUtil.pack(DayHighRequest(msg));
                }
                break;

            case TL2.NDAYLOW:
                if (DayLowRequest != null)
                {
                    result = WMUtil.pack(DayLowRequest(msg));
                }
                break;

            case TL2.SENDORDER:
                SrvDoExecute(msg);
                break;

            case TL2.REGISTERCLIENT:
                SrvRegClient(msg);
                break;

            case TL2.REGISTERSTOCK:
                string[] m2 = msg.Split('+');
                SrvRegStocks(m2[0], m2[1]);
                break;

            case TL2.REGISTERINDEX:
                string[] ib = msg.Split('+');
                SrvRegIndex(ib[0], ib[1]);
                break;

            case TL2.CLEARCLIENT:
                SrvClearClient(msg);
                break;

            case TL2.CLEARSTOCKS:
                SrvClearStocks(msg);
                break;

            case TL2.HEARTBEAT:
                SrvBeatHeart(msg);
                break;

            case TL2.BROKERNAME:
                result = (long)Brokers.TradeLinkSimulation;
                break;

            case TL2.FEATUREREQUEST:
                TL2[]         f  = GetFeatures();
                List <string> mf = new List <string>();
                foreach (TL2 t in f)
                {
                    int ti = (int)t;
                    mf.Add(ti.ToString());
                }
                string msf = string.Join(",", mf.ToArray());
                WMUtil.SendMsg(msf, TL2.FEATURERESPONSE, Handle, msg);
                break;

            default:
                result = (long)TL2.FEATURE_NOT_IMPLEMENTED;
                break;
            }
            m.Result = (IntPtr)result;
        }
示例#8
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, TL2 messagetype, IntPtr sourcehandle, string destinationwindow)
        {
            IntPtr him = WMUtil.HisHandle(destinationwindow);

            return(WMUtil.SendMsg(message, him, sourcehandle, (int)messagetype));
        }