예제 #1
0
        /// <summary>
        /// Gets a user-friendly string for Broker and TradeLink error messages.
        /// </summary>
        /// <param name="errorcode">The errorcode.</param>
        /// <returns></returns>
        public static string PrettyError(Brokers broker, int errorcode)
        {
            TL2 message = (TL2)errorcode;

            switch (message)
            {
            // tradelink messages
            case TL2.FEATURE_NOT_IMPLEMENTED: return("Feature not implemented yet.");

            case TL2.UNKNOWNSYM: return("Unknown symbol.");

            case TL2.UNKNOWNMSG: return("Unknown message.");

            case TL2.TL_CONNECTOR_MISSING: return("TradeLink Server not found.");

            case TL2.GOTNULLORDER: return("Unable to read order.");

            case TL2.OK: return("Ok");

            default:
                // broker-specific messages
                if (broker == Brokers.Assent)
                {
                    return(Enum.GetName(typeof(AnvilSendOrderError), errorcode));
                }
                if (broker == Brokers.Echo)
                {
                    return(Enum.GetName(typeof(SterlingSubmitOrderError), errorcode));
                }
                break;
            }
            return("Unknown error: " + errorcode.ToString());
        }
예제 #2
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);
        }
예제 #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
 protected long TLSend(TL2 type) { return TLSend(type, ""); }
예제 #5
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));
        }
예제 #6
0
 public LinkMessage(TL2 t) { Type = t; }
예제 #7
0
 public LinkMessage(TL2 t, object m) { Type = t; Body = m; }
예제 #8
0
 void TLSend(TL2 type) { TLSend(Him, new LinkMessage(type)); }
예제 #9
0
 public LinkMessage(TL2 t)
 {
     Type = t;
 }
예제 #10
0
 public LinkMessage(TL2 t, object m)
 {
     Type = t; Body = m;
 }
예제 #11
0
        void gotMessage(object sender, ReceiveCompletedEventArgs e)
        {
            TL2         mt      = TL2.INFO;
            string      from    = "";
            LinkMessage gotmess = null;
            object      m       = null;

            gotmess = (LinkMessage)e.Message.Body;
            mt      = gotmess.Type;
            m       = gotmess.Body;
            from    = gotmess.From;

            int  cid = -1;
            Tick t   = new Tick();

            try
            {
                switch (mt)
                {
                // CLIENT MESSAGES
                case TL2.TICKNOTIFY:
                    t = (Tick)m;
                    gotTick(t);
                    break;

                case TL2.EXECUTENOTIFY:
                    Trade trade;
                    trade = (Trade)m;
                    gotFill(trade);
                    break;

                // SERVER MESSAGES
                case TL2.REGISTERCLIENT:
                    if (client.IndexOf(from) != -1)
                    {
                        break;                                 // we already had your client, ignore
                    }
                    client.Add(from);
                    stocks.Add("");
                    heart.Add(new DateTime());
                    break;

                case TL2.REGISTERSTOCK:
                    cid = client.IndexOf(from);
                    if (cid == -1)
                    {
                        break;                // client not found
                    }
                    MarketBasket mb = (MarketBasket)m;
                    stocks[cid] = mb.ToString();
                    BeatHeart(from);
                    break;

                case TL2.HEARTBEAT:
                    BeatHeart(from);
                    break;

                case TL2.CLEARSTOCKS:
                    cid = client.IndexOf(from);
                    if (cid == -1)
                    {
                        break;
                    }
                    stocks[cid] = null;
                    BeatHeart(from);
                    break;

                case TL2.CLEARCLIENT:
                    cid = client.IndexOf(from);
                    if (cid == -1)
                    {
                        break;                // we don't have the client, nothing to do
                    }
                    client[cid] = null;
                    stocks[cid] = null;
                    heart[cid]  = new DateTime();
                    break;
                }
            }
            catch (Exception ex) { string s = ex.Message; }
            if (this.GotMessage != null)
            {
                GotMessage(mt, from); // send GotMessage event to any subscribers
            }
            rec.BeginReceive();       // prepare to receive new messages
        }
예제 #12
0
 void TLSend(TL2 type)
 {
     TLSend(Him, new LinkMessage(type));
 }
예제 #13
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);
 }
예제 #14
0
 protected long TLSend(TL2 type)
 {
     return(TLSend(type, ""));
 }