Exemplo n.º 1
0
        public static List <IPEndPoint> GetEndpoints(int port, params string[] servers)
        {
            List <IPEndPoint> ip = new List <IPEndPoint>();

            foreach (string server in servers)
            {
                if (IPUtil.isValidAddress(server))
                {
                    ip.Add(new IPEndPoint(IPAddress.Parse(server), port));
                }
            }
            return(ip);
        }
Exemplo n.º 2
0
 TLClient getrealclient(int pidx, string name)
 {
     if (!IPUtil.hasValidAddress(_servers))
     {
         return(new TLClient_WM(pidx, name, false));
     }
     else
     {
         TLClient_IP tmp = new TLClient_IP(TLClient_IP.GetEndpoints(_port, _servers), pidx, name, 3, 10, debug);
         tmp.VerboseDebugging = VerboseDebugging;
         return(tmp);
     }
 }
Exemplo n.º 3
0
 TLClient getsearchclient()
 {
     if (!IPUtil.hasValidAddress(_servers))
     {
         return(new TLClient_WM(false));
     }
     else
     {
         TLClient_IP tmp = new TLClient_IP(_servers, _port);
         tmp.VerboseDebugging = VerboseDebugging;
         return(tmp);
     }
 }
Exemplo n.º 4
0
 TLClient getsearchclient()
 {
     if (!IPUtil.hasValidAddress(_servers))
     {
         TLClient tmp = new TLClient_WM(false);
         tmp.VerboseDebugging = VerboseDebugging;
         tmp.SendDebugEvent  += new DebugDelegate(debug);
         return(tmp);
     }
     else
     {
         TLClient_IP tmp = new TLClient_IP(_servers, _port);
         tmp.VerboseDebugging = VerboseDebugging;
         tmp.SendDebugEvent  += new DebugDelegate(debug);
         return(tmp);
     }
 }
Exemplo n.º 5
0
 public TLServer_IP(string ipaddr, int port, int wait, int TickBufferSize, DebugDelegate deb)
 {
     SendDebugEvent = deb;
     if (TickBufferSize == 0)
     {
         _queueb4send = false;
     }
     else
     {
         tickq = new RingBuffer <Tick>(TickBufferSize);
     }
     MinorVer = Util.ProgramBuild(Util.PROGRAM, debug);
     _wait    = wait;
     if (!IPUtil.isValidAddress(ipaddr))
     {
         debug("Not valid ip address: " + ipaddr + ", using localhost.");
     }
     _addr = IPUtil.isValidAddress(ipaddr) ? IPAddress.Parse(ipaddr) : IPAddress.Loopback;
     _port = port;
     v("tlserver_ip wait: " + _wait);
     Start();
 }
Exemplo n.º 6
0
        /// <summary>
        /// reset brokerfeed, look for any new servers and attempt to connect to current preferred providers
        /// </summary>
        public void Reset()
        {
            feedready = false;
            if (IPUtil.hasValidAddress(_servers))
            {
                debug("At least one valid IpAddress found, attempting IP transport.");
            }
            else
            {
                debug("No ip addresses specified, attempting Windows IPC.");
            }

            TLClient tl = getsearchclient();

            _pavail = tl.ProvidersAvailable;
            if (_pavail.Length == 0)
            {
                debug("No providers were found. Ensure connectors are running.");
            }

            bool setquote = false;
            bool setexec  = false;

            // see if we can get preferred providers
            int xi = getproviderindex(_broker);
            int qi = getproviderindex(_feed);

            _isprefq = (qi != -1) && hasminquote(tl, qi);
            _isprefx = (xi != -1) && hasminexec(tl, xi);
            if (!isPreferredFeed)
            {
                debug("preferred data not available: " + _feed);
            }
            if (!isPreferredBroker)
            {
                debug("preferred execute not available: " + _broker);
            }
            // search for features

            for (int i = 0; i < ProvidersAvailable.Length; i++)
            {
                if ((qi != -1) && (xi != -1))
                {
                    break;
                }
                // switch to provider
                if ((qi == -1) && hasminquote(tl, i))
                {
                    qi = i;
                }
                if ((xi == -1) && hasminexec(tl, i))
                {
                    xi = i;
                }
            }

            // see if we're allowed to fallback

            // not allowed
            if (RequirePreferred)
            {
                setquote = isPreferredFeed;
                setexec  = isPreferredBroker;
            }
            else // ok to fallback,but where
            {
                setquote = (qi != -1);
                setexec  = (xi != -1);
            }

            // map handlers
            if (setquote)
            {
                quote              = getrealclient(qi, PROGRAM + "quote");
                quote.gotFeatures += new MessageTypesMsgDelegate(quote_gotFeatures);
                debug("DataFeed: " + quote.BrokerName + " " + quote.ServerVersion);
                _feed = quote.BrokerName;
                // clear any leftover subscriptions
                quote.Unsubscribe();
                if (isThreadSafe)
                {
                    quote.gotTick           += new TickDelegate(quote_gotTick);
                    quote.gotUnknownMessage += new MessageDelegate(quote_gotUnknownMessage);
                }
                else
                {
                    quote.gotTick           += new TickDelegate(quote_gotTick2);
                    quote.gotUnknownMessage += new MessageDelegate(quote_gotUnknownMessage2);
                }
                quote.gotImbalance += new ImbalanceDelegate(quote_gotImbalance);
            }
            if (setexec)
            {
                execute              = getrealclient(xi, PROGRAM + "exec");
                _broker              = execute.BrokerName;
                execute.gotFeatures += new MessageTypesMsgDelegate(execute_gotFeatures);
                if (isThreadSafe)
                {
                    execute.gotAccounts       += new DebugDelegate(execute_gotAccounts);
                    execute.gotFill           += new FillDelegate(execute_gotFill);
                    execute.gotOrder          += new OrderDelegate(execute_gotOrder);
                    execute.gotOrderCancel    += new LongDelegate(execute_gotOrderCancel);
                    execute.gotPosition       += new PositionDelegate(execute_gotPosition);
                    execute.gotUnknownMessage += new MessageDelegate(execute_gotUnknownMessage);
                }
                else
                {
                    execute.gotAccounts       += new DebugDelegate(execute_gotAccounts2);
                    execute.gotFill           += new FillDelegate(execute_gotFill2);
                    execute.gotOrder          += new OrderDelegate(execute_gotOrder2);
                    execute.gotOrderCancel    += new LongDelegate(execute_gotOrderCancel2);
                    execute.gotPosition       += new PositionDelegate(execute_gotPosition2);
                    execute.gotUnknownMessage += new MessageDelegate(execute_gotUnknownMessage2);
                }
                debug("Executions: " + execute.BrokerName + " " + execute.ServerVersion);
                if (RequestAccountsOnStartup)
                {
                    RequestAccounts();
                }
            }

            feedready = true;
            // connect to the rest
            for (int i = 0; i < ProvidersAvailable.Length; i++)
            {
                // skip existing connections
                if (i == xi)
                {
                    _pcon.Add(execute);
                    continue;
                }
                if ((xi != qi) && (i == qi))
                {
                    _pcon.Add(quote);
                    continue;
                }
                // add new connections
                TLClient newcon = getrealclient(i, PROGRAM);
                newcon.gotFeatures       += new MessageTypesMsgDelegate(newcon_gotFeatures);
                newcon.gotUnknownMessage += new MessageDelegate(newcon_gotUnknownMessage);
                _pcon.Add(newcon);
            }
            tl.Disconnect();
            tl = null;
        }