Пример #1
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(), TL2.ORDERCANCELRESPONSE, Handle, c);
     }
 }
Пример #2
0
 public TradeLink_Client_WM(string clientname, bool showarmingonmissingserver)
     : base()
 {
     this.Text          = WMUtil.GetUniqueWindow(clientname);
     this.WindowState   = FormWindowState.Minimized;
     this.ShowInTaskbar = false;
     this.Hide();
     this.Mode(this.TLFound(), false, showarmingonmissingserver);
 }
Пример #3
0
        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);
        }
Пример #4
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);
        }
Пример #5
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(o.Serialize(), TL2.ORDERNOTIFY, Handle, client[i]);
             }
         }
     }
 }
Пример #6
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);
        }
Пример #7
0
 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]);
             }
         }
     }
 }
Пример #8
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 = type;
            str        = str + '\0';
            cds.cbData = str.Length + 1;

            System.IntPtr pData = Marshal.AllocCoTaskMem(str.Length);
            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());
        }
Пример #9
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)
     {
         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]);
             }
         }
     }
 }
Пример #10
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 || !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]);
             }
         }
     }
 }
Пример #11
0
 /// <summary>
 /// Today's closing price (zero if still open)
 /// </summary>
 /// <param name="sym">The symbol</param>
 /// <returns></returns>
 public decimal DayClose(string sym)
 {
     return(WMUtil.unpack(TLSend(TL2.CLOSEPRICE, sym)));
 }
Пример #12
0
 /// <summary>
 /// Used for testing the TL-BROKER api (programmatically)
 /// </summary>
 public void GoTest()
 {
     Disconnect(); himh = WMUtil.HisHandle(WMUtil.TESTWINDOW); LinkType = TLTypes.TESTBROKER; Register();
 }
Пример #13
0
 /// <summary>
 /// Attemptions connection to TL Replay Server
 /// </summary>
 public void GoHist()
 {
     Disconnect(); himh = WMUtil.HisHandle(WMUtil.REPLAYWINDOW); LinkType = TLTypes.HISTORICALBROKER; Register();
 }
Пример #14
0
 /// <summary>
 /// Today's high
 /// </summary>
 /// <param name="sym">The symbol.</param>
 /// <returns></returns>
 public decimal DayHigh(string sym)
 {
     return(WMUtil.unpack(TLSend(TL2.NDAYHIGH, sym)));
 }
Пример #15
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));
        }
Пример #16
0
 /// <summary>
 /// Today's low
 /// </summary>
 /// <param name="sym">The symbol</param>
 /// <returns></returns>
 public decimal DayLow(string sym)
 {
     return(WMUtil.unpack(TLSend(TL2.NDAYLOW, sym)));
 }
Пример #17
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 TL2.ORDERCANCELRESPONSE:
                if (gotOrderCancel != null)
                {
                    gotOrderCancel(Convert.ToUInt32(msg));
                }
                break;

            case TL2.TICKNOTIFY:
                if (Index.isIdx(r[(int)TickField.symbol]))
                {
                    // we got an index update
                    Index i = Index.Deserialize(msg);
                    if (gotIndexTick != null)
                    {
                        gotIndexTick(i);
                    }
                    break;
                }
                Tick t = Tick.Deserialize(msg);
                if (t.isTrade)
                {
                    try
                    {
                        if (t.trade > chighs[t.sym])
                        {
                            chighs[t.sym] = t.trade;
                        }
                        if (t.trade < clows[t.sym])
                        {
                            clows[t.sym] = t.trade;
                        }
                    }
                    catch (KeyNotFoundException)
                    {
                        decimal high = DayHigh(t.sym);
                        decimal low  = DayLow(t.sym);
                        chighs.Add(t.sym, high);
                        if (low == 0)
                        {
                            low = 640000;
                        }
                        clows.Add(t.sym, low);
                    }
                }
                if (gotTick != null)
                {
                    gotTick(t);
                }
                break;

            case TL2.EXECUTENOTIFY:
                // date,time,symbol,side,size,price,comment
                Trade tr = Trade.Deserialize(msg);
                try
                {
                    cpos[tr.symbol] = new Position(tr.symbol, AvgPrice(tr.symbol), PosSize(tr.symbol));
                }
                catch (KeyNotFoundException)
                {
                    cpos.Add(tr.symbol, new Position(tr.symbol, AvgPrice(tr.symbol), PosSize(tr.symbol)));
                }
                if (gotFill != null)
                {
                    gotFill(tr);
                }
                break;

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

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

            case TL2.FEATURERESPONSE:
                string[]   p = msg.Split(',');
                List <TL2> f = new List <TL2>();
                foreach (string s in p)
                {
                    try
                    {
                        f.Add((TL2)Convert.ToInt32(s));
                    }
                    catch (Exception) { }
                }
                if (gotSupportedFeatures != null)
                {
                    gotSupportedFeatures(f.ToArray());
                }
                break;
            }
            result   = 0;
            m.Result = (IntPtr)result;
        }
Пример #18
0
 public decimal AvgPrice(string sym, string account)
 {
     return(((account == "") || (account == null)) ? 0 : WMUtil.unpack(TLSend(TL2.AVGPRICE, sym + "," + account)));
 }
Пример #19
0
 /// <summary>
 /// Returns average price for a position
 /// </summary>
 /// <param name="sym">The symbol</param>
 /// <returns>decimal representing average price</returns>
 public decimal AvgPrice(string sym)
 {
     return(WMUtil.unpack(TLSend(TL2.AVGPRICE, sym)));
 }
Пример #20
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();
 }
Пример #21
0
 public decimal AccountOpenPL()
 {
     return(WMUtil.unpack(TLSend(TL2.ACCOUNTOPENPL, "")));
 }
Пример #22
0
 public decimal AccountOpenPL(string acct)
 {
     return(((acct == "") || (acct == null)) ? 0 : WMUtil.unpack(TLSend(TL2.ACCOUNTOPENPL, acct)));
 }
Пример #23
0
 public decimal AccountClosedPL(string acct)
 {
     return(((acct == "") || (acct == null)) ? 0 : WMUtil.unpack(TLSend(TL2.ACCOUNTCLOSEDPL, acct)));
 }
Пример #24
0
 public decimal AccountClosedPL()
 {
     return(WMUtil.unpack(TLSend(TL2.ACCOUNTCLOSEDPL, "")));
 }
Пример #25
0
        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;
        }
Пример #26
0
 /// <summary>
 /// yesterday's closing price (day)
 /// </summary>
 /// <param name="sym">the symbol</param>
 /// <returns></returns>
 public decimal YestClose(string sym)
 {
     return(WMUtil.unpack(TLSend(TL2.YESTCLOSE, sym)));
 }
Пример #27
0
 /// <summary>
 /// Gets opening price for this day
 /// </summary>
 /// <param name="sym">The symbol</param>
 /// <returns>decimal</returns>
 public decimal DayOpen(string sym)
 {
     return(WMUtil.unpack(TLSend(TL2.OPENPRICE, sym)));
 }
Пример #28
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();
 }