예제 #1
0
        long handle(MessageTypes type, string msg, Socket sock)
        {
            long result = NORETURNRESULT;

            v((sock != null  ? sock.RemoteEndPoint.ToString() : string.Empty) + " " + type.ToString() + " " + msg);
            switch (type)
            {
            case MessageTypes.ACCOUNTREQUEST:
                if (newAcctRequest == null)
                {
                    break;
                }
                string accts = newAcctRequest();
                TLSend(accts, MessageTypes.ACCOUNTRESPONSE, sock);
                break;

            case MessageTypes.POSITIONREQUEST:
                if (newPosList == null)
                {
                    break;
                }
                string[] pm = msg.Split('+');
                if (pm.Length < 2)
                {
                    break;
                }
                string     client = pm[0];
                string     acct   = pm[1];
                Position[] list   = newPosList(acct);
                foreach (Position pos in list)
                {
                    TLSend(PositionImpl.Serialize(pos), MessageTypes.POSITIONRESPONSE, client);
                }
                break;

            case MessageTypes.ORDERCANCELREQUEST:
            {
                long id = 0;
                if (long.TryParse(msg, out id) && (newOrderCancelRequest != null))
                {
                    newOrderCancelRequest(id);
                }
            }
            break;

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

            case MessageTypes.REGISTERCLIENT:
                SrvRegClient(msg, sock);
                break;

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

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

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

            case MessageTypes.HEARTBEATREQUEST:
                SrvBeatHeart(msg);
                break;

            case MessageTypes.BROKERNAME:
            {
                result = (long)newProviderName;
                sock.Send(BitConverter.GetBytes(result));
            }
            break;

            case MessageTypes.IMBALANCEREQUEST:
                if (newImbalanceRequest != null)
                {
                    newImbalanceRequest();
                }
                break;

            case MessageTypes.FEATUREREQUEST:
                string msf            = "";
                List <MessageTypes> f = new List <MessageTypes>();
                f.Add(MessageTypes.HEARTBEATREQUEST);
                f.Add(MessageTypes.HEARTBEATRESPONSE);
                f.Add(MessageTypes.CLEARCLIENT);
                f.Add(MessageTypes.CLEARSTOCKS);
                f.Add(MessageTypes.REGISTERCLIENT);
                f.Add(MessageTypes.REGISTERSTOCK);
                f.Add(MessageTypes.FEATUREREQUEST);
                f.Add(MessageTypes.FEATURERESPONSE);
                f.Add(MessageTypes.VERSION);
                f.Add(MessageTypes.BROKERNAME);
                List <string> mf = new List <string>();
                foreach (MessageTypes t in f)
                {
                    int ti = (int)t;
                    mf.Add(ti.ToString());
                }
                if (newFeatureRequest != null)
                {
                    MessageTypes[] f2 = newFeatureRequest();
                    foreach (MessageTypes t in f2)
                    {
                        int ti = (int)t;
                        mf.Add(ti.ToString());
                    }
                }
                msf = string.Join(",", mf.ToArray());
                TLSend(msf, MessageTypes.FEATURERESPONSE, msg);
                break;

            case MessageTypes.VERSION:
                result = (long)MinorVer;
                break;

            case MessageTypes.DOMREQUEST:
                string[] dom = msg.Split('+');
                SrvDOMReq(dom[0], int.Parse(dom[1]));
                break;

            default:
                if (newUnknownRequestSource != null)
                {
                    result = newUnknownRequestSource(type, msg, sock.RemoteEndPoint.ToString());
                }
                else if (newUnknownRequest != null)
                {
                    result = newUnknownRequest(type, msg);
                }
                else
                {
                    result = (long)MessageTypes.FEATURE_NOT_IMPLEMENTED;
                }
                break;
            }

            return(result);
        }
예제 #2
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            TradeLinkMessage tlm = WMUtil.ToTradeLinkMessage(ref m);

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

            long result = (long)MessageTypes.OK;

            switch (tlm.type)
            {
            case MessageTypes.ACCOUNTREQUEST:
                if (newAcctRequest == null)
                {
                    break;
                }
                string accts = newAcctRequest();
                TLSend(accts, MessageTypes.ACCOUNTRESPONSE, msg);
                break;

            case MessageTypes.POSITIONREQUEST:
                if (newPosList == null)
                {
                    break;
                }
                string [] pm = msg.Split('+');
                if (pm.Length < 2)
                {
                    break;
                }
                string     client = pm[0];
                string     acct   = pm[1];
                Position[] list   = newPosList(acct);
                foreach (Position pos in list)
                {
                    TLSend(PositionImpl.Serialize(pos), MessageTypes.POSITIONRESPONSE, client);
                }
                break;

            case MessageTypes.ORDERCANCELREQUEST:
            {
                long id = 0;
                if (long.TryParse(msg, out id) && (newOrderCancelRequest != null))
                {
                    newOrderCancelRequest(id);
                }
            }
            break;

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

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

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

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

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

            case MessageTypes.HEARTBEATREQUEST:
                SrvBeatHeart(msg);
                break;

            case MessageTypes.BROKERNAME:
                result = (long)newProviderName;
                break;

            case MessageTypes.IMBALANCEREQUEST:
                if (newImbalanceRequest != null)
                {
                    newImbalanceRequest();
                }
                break;

            case MessageTypes.FEATUREREQUEST:
                string msf            = "";
                List <MessageTypes> f = new List <MessageTypes>();
                f.Add(MessageTypes.HEARTBEATREQUEST);
                f.Add(MessageTypes.CLEARCLIENT);
                f.Add(MessageTypes.CLEARSTOCKS);
                f.Add(MessageTypes.REGISTERCLIENT);
                f.Add(MessageTypes.REGISTERSTOCK);
                f.Add(MessageTypes.FEATUREREQUEST);
                f.Add(MessageTypes.FEATURERESPONSE);
                f.Add(MessageTypes.VERSION);
                f.Add(MessageTypes.BROKERNAME);
                List <string> mf = new List <string>();
                foreach (MessageTypes t in f)
                {
                    int ti = (int)t;
                    mf.Add(ti.ToString());
                }
                if (newFeatureRequest != null)
                {
                    MessageTypes[] f2 = newFeatureRequest();
                    foreach (MessageTypes t in f2)
                    {
                        int ti = (int)t;
                        mf.Add(ti.ToString());
                    }
                }
                msf = string.Join(",", mf.ToArray());
                TLSend(msf, MessageTypes.FEATURERESPONSE, msg);
                break;

            case MessageTypes.VERSION:
                result = (long)MinorVer;
                break;

            default:
                if (newUnknownRequest != null)
                {
                    result = newUnknownRequest(tlm.type, msg);
                }
                else
                {
                    result = (long)MessageTypes.FEATURE_NOT_IMPLEMENTED;
                }
                break;
            }
            m.Result = (IntPtr)result;
        }