Beispiel #1
0
        public bool ModifyBroker(int provider, bool warn)
        {
            if (!feedready)
            {
                return(false);
            }
            TLClient tl = getsearchclient();

            if ((provider < 0) || (provider > ProvidersAvailable.Length))
            {
                return(false);
            }
            Providers p  = ProvidersAvailable[provider];
            bool      ok = hasminexec(tl, provider);

            if (!ok)
            {
                System.Windows.Forms.MessageBox.Show(p.ToString() + " does not support execution.");
                return(false);
            }
            this.v(tl.Name + " " + provider + " " + tl.BrokerName + (ok ? " has feed support." : " no feed support."));
            _broker = p;
            tl.Disconnect();
            Reset();
            return(true);
        }
Beispiel #2
0
 public void Disconnect()
 {
     v("disconnecting from all providers.");
     if (quote != null)
     {
         try
         {
             quote.Disconnect();
         }
         catch (TLServerNotFound) { }
     }
     if (execute != null)
     {
         try
         {
             execute.Disconnect();
         }
         catch (TLServerNotFound) { }
     }
     for (int i = 0; i < _pcon.Count; i++)
     {
         if (_pcon[i] != null)
         {
             try
             {
                 _pcon[i].Disconnect();
             }
             catch (TLServerNotFound) { }
         }
     }
 }
Beispiel #3
0
 //[TestFixtureTearDown]
 public void Stop()
 {
     // stop client
     if (client != null)
     {
         client.Disconnect();
     }
     client = null;
     // stop server
     if (con != null)
     {
         con.Stop();
     }
     con = null;
     g.d("iqfeed teardown");
 }
Beispiel #4
0
 static bool hasminquote(TLClient tl, int provider)
 {
     try
     {
         bool v     = (tl.ProviderSelected == provider) || tl.Mode(provider, false);
         bool test  = true;
         int  count = 0;
         while ((tl.BrokerName != Providers.Unknown) && (tl.BrokerName != Providers.Error) &&
                (tl.RequestFeatureList.Count == 0) && (count++ < MAXFEATUREWAIT))
         {
             Thread.Sleep(10);
         }
         test &= tl.RequestFeatureList.Contains(MessageTypes.TICKNOTIFY);
         tl.Disconnect();
         return(test && v);
     }
     catch { return(false); }
 }
Beispiel #5
0
 public void Disconnect()
 {
     v("disconnecting from all providers.");
     if (quote != null)
     {
         quote.Disconnect();
     }
     if (execute != null)
     {
         execute.Disconnect();
     }
     for (int i = 0; i < _pcon.Count; i++)
     {
         if (_pcon[i] != null)
         {
             _pcon[i].Disconnect();
         }
     }
 }
Beispiel #6
0
 static bool hasminquote(TLClient tl, int provider)
 {
     try
     {
         bool v = (tl.ProviderSelected == provider) || tl.Mode(provider, false);
         bool test = true;
         int count = 0;
         while ((tl.BrokerName != Providers.Unknown) && (tl.BrokerName != Providers.Error)
             && (tl.RequestFeatureList.Count == 0) && (count++ < MAXFEATUREWAIT))
             Thread.Sleep(10);
         test &= tl.RequestFeatureList.Contains(MessageTypes.TICKNOTIFY);
         tl.Disconnect();
         return test && v;
     }
     catch { return false; }
 }
Beispiel #7
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;
        }