Exemplo n.º 1
0
        public void Multiple()
        {
            // setup some symbols
            string[] ab = new string[] { "IBM", "LVS", "T", "GS", "MHS" };
            string[] bb = new string[] { "LVS", "MHS" };
            // create baskets from our symbols
            Basket mb  = new BasketImpl(ab);
            Basket rem = new BasketImpl(bb);

            // verify symbol counts of our baskets
            Assert.That(mb.Count == ab.Length);
            Assert.That(rem.Count == bb.Length);
            // remove one basket from another
            mb.Remove(rem);
            // verify count matches
            Assert.That(mb.Count == 3, mb.Count.ToString());

            // add single symbol
            Basket cb = new BasketImpl("GM");

            // add another symbol
            cb.Add("GOOG");
            // verify we have two
            Assert.AreEqual(2, cb.Count);
            // attempt to add dupplicate
            cb.Add("GM");
            // verify we have two
            Assert.AreEqual(2, cb.Count);
        }
Exemplo n.º 2
0
        /// <summary>
        /// gets a basket from a url
        /// </summary>
        /// <returns></returns>
        public Basket FetchURL()
        {
            Basket mb = new BasketImpl();

            if (!Uri.IsWellFormedUriString(_url, UriKind.RelativeOrAbsolute))
            {
                return(mb);
            }
            if (_nyse && _linkedonly)
            {
                mb.Add(Fetch.LinkedNYSEFromURL(_url));
            }
            else if (_nyse)
            {
                mb.Add(Fetch.NYSEFromURL(_url));
            }
            if (_nasd && _linkedonly)
            {
                mb.Add(Fetch.LinkedNASDAQFromURL(_url));
            }
            else if (_nasd)
            {
                mb.Add(Fetch.NASDAQFromURL(_url));
            }
            if (_xdupe)
            {
                mb = Fetch.RemoveDupe(mb);
            }
            return(mb);
        }
Exemplo n.º 3
0
        private void importbasketbut_Click(object sender, EventArgs e)
        {
            OpenFileDialog od = new OpenFileDialog();

            od.Multiselect     = true;
            od.Filter          = "Basket (*.txt)|*.txt|All files (*.*)|*.*";
            od.AddExtension    = true;
            od.DefaultExt      = ".txt";
            od.CheckFileExists = true;
            od.Title           = "Select the baskets you wish to import to quototpia";
            if (od.ShowDialog() == DialogResult.OK)
            {
                int count = 0;
                foreach (string f in od.FileNames)
                {
                    Basket nb = BasketImpl.FromFile(f);
                    addbasket(nb);
                    count += nb.Count;
                }
                status("Imported " + count + " instruments.");
            }
            else
            {
                return;
            }

            Invalidate(true);
        }
Exemplo n.º 4
0
 bool addsymbol(string symtext)
 {
     mb.Clear();
     if (isAutoUpperCase)
     {
         symtext = symtext.ToUpper();
     }
     if (symtext.Contains(","))
     {
         mb = BasketImpl.FromString(symtext);
         debug("Used explicit parsing: " + symtext + " -> " + Util.join(mb.ToSymArrayFull()));
     }
     else
     {
         mb = BasketImpl.parsedata(symtext, false, false, debug);
     }
     status("Added " + symtext);
     if (SendNewBasketEvent != null)
     {
         SendNewBasketEvent(mb, id);
     }
     if (SendNewRawSymbolsEvent != null)
     {
         SendNewRawSymbolsEvent(symtext);
     }
     return(true);
 }
Exemplo n.º 5
0
        void symlist(object sender, EventArgs e)
        {
            string syms = TextPrompt.Prompt("Enter symbols seperated by commas", "Symbols", mb.ToString());
            Basket b    = BasketImpl.FromString(syms);

            subscribe(b);
        }
Exemplo n.º 6
0
        void updateMB()
        {
            List <string> syms = new List <string>(_symidx.Count);

            foreach (string sym in _symidx.Keys)
            {
                syms.Add(sym);
            }
            string old = _mb.ToString();

            _mb = new BasketImpl(syms.ToArray());
            bool subscribe = old != _mb.ToString();

            if (!subscribe)
            {
                return;
            }

            try
            {
                // resubscribe
                tl.Subscribe(_mb);
            }
            catch (TLServerNotFound)
            {
                debug("symbol subscribe failed as no TL server was found.");
            }
        }
Exemplo n.º 7
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            debug("got symbol request: " + client + " for: " + symbols);
            // get original basket
            Basket org = new BasketImpl(b);
            // get new basket
            Basket mb = BasketImpl.FromString(symbols);

            // track it
            b.Add(mb);

            //Close_Connections(false);
            foreach (Security s in mb)
            {
                // skip symbol if we already have it
                if (org.ToString().Contains(s.Symbol))
                {
                    continue;
                }
                if (api.TD_IsStockSymbolValid(s.Symbol))
                {
                    string service = GetExchange(s.Symbol);
                    api.TD_RequestAsyncLevel1QuoteStreaming(s.Symbol, service, this);
                }
            }
        }
Exemplo n.º 8
0
        public void Multiple()
        {
            BasketImpl mb  = new BasketImpl(new string[] { "IBM", "LVS", "T", "GS", "MHS" });
            BasketImpl rem = new BasketImpl(new string[] { "LVS", "MHS" });

            Assert.That(mb.Count == 5);
            Assert.That(rem.Count == 2);
            mb.Remove(rem);
            Assert.That(mb.Count == 3, mb.Count.ToString());
        }
Exemplo n.º 9
0
 protected override void addsymsnow_post()
 {
     // subscribe to symbols after they've been added to grid
     if (SubscribeEvent != null)
     {
         var b = new BasketImpl(symbols2add);
         debug("Subscribed: " + Util.join(symbols2add));
         SubscribeEvent(b, id);
     }
 }
Exemplo n.º 10
0
        void exportbasket(object send, EventArgs e)
        {
            SaveFileDialog sd = new SaveFileDialog();

            sd.AddExtension = true;
            sd.DefaultExt   = ".txt";
            if (sd.ShowDialog() == DialogResult.OK)
            {
                BasketImpl.ToFile(mb, sd.FileName);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// gets nyse symbols
        /// </summary>
        /// <param name="ParseStocks"></param>
        /// <returns></returns>
        public static BasketImpl NYSE(string ParseStocks)
        {
            BasketImpl      mb = new BasketImpl();
            MatchCollection mc = Regex.Matches(ParseStocks, @"\b[A-Z]{1,3}\b");

            for (int i = 0; i < mc.Count; i++)
            {
                mb.Add(new SecurityImpl(mc[i].Value.ToUpper()));
            }
            return(mb);
        }
Exemplo n.º 12
0
        /// <summary>
        /// remove unlisted symbols, leaving only verified symbols remaining.
        /// tradelink has a list of verified nasdaq and nyse symbols, but it is not guaranteed to be all inclusive.
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static Basket RemoveUnlisted(Basket input)
        {
            Basket output = new BasketImpl();

            for (int i = 0; i < input.Count; i++)
            {
                if (NYSE.isListed(input[i].symbol) || NASDAQ.isListed(input[i].symbol))
                {
                    output.Add(input[i]);
                }
            }
            return(output);
        }
Exemplo n.º 13
0
        public void Enumeration()
        {
            BasketImpl mb = new BasketImpl(new string[] { "IBM", "MHS", "LVS", "GM" });

            string[] l = new string[4];
            int      i = 0;

            foreach (SecurityImpl s in mb)
            {
                l[i++] = s.Symbol;
            }
            Assert.AreEqual(4, i);
        }
Exemplo n.º 14
0
        void tl_newRegisterStocks(string msg)
        {
            api.UnsubscribeAll();
            Basket mb = BasketImpl.Deserialize(msg);

            //Close_Connections(false);
            foreach (Security s in mb)
            {
                //if (api.SymbTD_IsStockSymbolValid(s.Symbol))
                {
                    api.Subscribe(s.Symbol, tdaactx.TxTDASubTypes.TDAPI_SUB_L1);//, service, this);
                }
            }
        }
Exemplo n.º 15
0
        void tl_newRegisterStocks(string msg)
        {
            Basket mb = BasketImpl.Deserialize(msg);

            //Close_Connections(false);
            foreach (Security s in mb)
            {
                if (api.TD_IsStockSymbolValid(s.Symbol))
                {
                    string service = GetExchange(s.Symbol);
                    api.TD_RequestAsyncLevel1QuoteStreaming(s.Symbol, service, this);
                }
            }
        }
Exemplo n.º 16
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            ////test();
            //string[] syms = tl.AllClientBasket.ToString().Split(',');
            ////m_Quotes.UnadviseAll(this);
            //for (int i = 0; i < syms.Length; i++)
            //{
            //    if (syms[i].Contains("."))
            //    {
            //        //we can reasonably assume this is an options request
            //        //m_Quotes.AdviseSymbol(this, syms[i], (int)enumQuoteServiceFlags.qsfOptions);
            //    }
            //    else if (syms[i].Contains("/"))
            //    {
            //        //we know (or can at least reasonably assume) this is forex
            //        //advise only level1 bid-ask quotes
            //       // m_Quotes.AdviseSymbol(this, syms[i], (int)enumQuoteServiceFlags.qsfLevelOne);
            //        //m_Quotes.AdviseSymbol(this, syms[i], (int)enumQuoteServiceFlags.qsfLevelTwo);
            //    }
            //    else
            //    {
            //        //probably equity, advise time and sales
            //        //m_Quotes.AdviseSymbol(this, syms[i], ((int)enumQuoteServiceFlags.qsfTimeAndSales));
            //        GetQuote(syms[i]);

            //    }
            //}
            //debug("Symbol Registered  " + syms[syms.Length - 1]);
            //

            // get original basket
            Basket org = BasketImpl.FromString(symquotes);

            // if we had something before, check if something was removed
            if (org.Count > 0)
            {
                Basket rem = BasketImpl.Subtract(org, tl.AllClientBasket);
                foreach (Security s in rem)
                {
                    removesym.Write(s.Symbol);
                }
            }
            symquotes = tl.AllClientBasket.ToString();
            if (VerboseDebugging)
            {
                debug("client subscribe request received: " + symquotes);
            }
            _symsq.Write(true);
        }
Exemplo n.º 17
0
        /// <summary>
        /// removes duplicate symbols
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static Basket RemoveDupe(Basket input)
        {
            List <string> cache  = new List <string>();
            Basket        output = new BasketImpl();

            for (int i = 0; i < input.Count; i++)
            {
                if (!cache.Contains(input[i].Symbol))
                {
                    output.Add(input[i]);
                    cache.Add(input[i].Symbol);
                }
            }
            return(output);
        }
Exemplo n.º 18
0
        /// <summary>
        /// gets clickable nasdaq symbols found in a string (eg html)
        /// </summary>
        /// <param name="parsestring"></param>
        /// <returns></returns>
        public static BasketImpl LinkedOnlyNASDAQ(string parsestring)
        {
            BasketImpl      mb     = new BasketImpl();
            string          regexp = @">[A-Z]{4}</a>";
            MatchCollection mc     = Regex.Matches(parsestring, regexp);

            for (int i = 0; i < mc.Count; i++)
            {
                string chunk = mc[i].Value;
                chunk = chunk.Replace("</a>", "");
                chunk = chunk.TrimStart('>');
                mb.Add(new SecurityImpl(chunk.ToUpper()));
            }
            return(mb);
        }
Exemplo n.º 19
0
        public void SymbolTrimming()
        {
            string[] t1 = new string[] { " IBM", "NYMEX FUT NYMEX ", ",WAG", "LVS,", " ,FRX,", "" };

            var r = BasketImpl.TrimSymbols(t1);
            int i = 0;

            Assert.AreEqual(5, r.Length, string.Join(".", r));
            Assert.AreEqual("IBM", r[i++]);
            Assert.AreEqual("NYMEX FUT NYMEX", r[i++]);
            Assert.AreEqual("WAG", r[i++]);
            Assert.AreEqual("LVS", r[i++]);
            Assert.AreEqual("FRX", r[i++]);
            //Assert.AreEqual(string.Empty, r[i++]);
        }
Exemplo n.º 20
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            // get existing basket
            Basket old = new BasketImpl(_basket);

            // update new basket
            AddBasket(BasketImpl.FromString(symbols));
            // remove unused symbols
            if (ReleaseDeadSymbols && (old.Count > 0))
            {
                Basket rem = BasketImpl.Subtract(old, tl.AllClientBasket);
                foreach (Security s in rem)
                {
                    unsubscribe(s.Symbol);
                }
            }
        }
Exemplo n.º 21
0
        public void FromFile_EnhancedDelim()
        {
            const string origFilePath  = "BasketImplTest_orig.txt";
            const string newFilePath   = "BasketImplTest_new.txt";
            const string comboFilePath = "BasketImplTest_combo.txt";

            string[]   symbols  = { "A", "B", "C", "D" };
            BasketImpl baseCase = new BasketImpl(symbols);

            StreamWriter origFile  = new StreamWriter(origFilePath); origFile.Write("A\nB\rC\r\nD"); origFile.Close();
            StreamWriter newFile   = new StreamWriter(newFilePath); newFile.Write("A,B,C,D"); newFile.Close();
            StreamWriter comboFile = new StreamWriter(comboFilePath); comboFile.Write("A\nB\r\nC,D"); comboFile.Close();

            Assert.AreEqual(baseCase.ToSymArray(), BasketImpl.FromFile(origFilePath).ToSymArray(), "At original test");
            Assert.AreEqual(baseCase.ToSymArray(), BasketImpl.FromFile(newFilePath).ToSymArray(), "At new test");
            Assert.AreEqual(baseCase.ToSymArray(), BasketImpl.FromFile(comboFilePath).ToSymArray(), "At combo test");
        }
Exemplo n.º 22
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            if (VerboseDebugging)
            {
                debug("client subscribe request received: " + symbols);
            }

            Basket rem = new BasketImpl();

            // if we had something before, check if something was removed
            if (org.Count > 0)
            {
                rem = BasketImpl.Subtract(org, tl.AllClientBasket);
            }

            SubscriptionFlags flags = SubscriptionFlags.Prints;

            flags |= SubscriptionFlags.Quotes;
            flags |= SubscriptionFlags.Best;

            List <string> syms = new List <string>();

            syms.AddRange(tl.AllClientBasket.ToSymArray());

            List <string> orgs = new List <string>(org.ToSymArray());

            // add current
            foreach (string sym in tl.AllClientBasket.ToSymArray())
            {
                // subscribe what we don't have
                if (!orgs.Contains(sym))
                {
                    // get the security
                    Security sec = SecurityImpl.Parse(sym);
                    string   ex  = sec.hasDest ? sec.DestEx : "NYSE";
                    oEngine.subscribe(ex, sec.Symbol, flags, null);
                }
            }

            // remove old
            foreach (Security s in rem)
            {
                oEngine.unsubscribe(string.Empty, s.Symbol);
            }
        }
Exemplo n.º 23
0
        public void Files()
        {
            // create basket
            BasketImpl mb = new BasketImpl(new string[] { "IBM", "MHS", "LVS", "GM" });
            // save it to a file
            const string file = "test.txt";

            BasketImpl.ToFile(mb, file);
            // restore it
            Basket nb = BasketImpl.FromFile(file);

            // verify it has same number of symbols
            Assert.AreEqual(mb.Count, nb.Count);
            // remove original contents from restored copy
            nb.Remove(mb);
            // verify nothing is left
            Assert.AreEqual(0, nb.Count);
        }
Exemplo n.º 24
0
        public void Serialization()
        {
            BasketImpl mb = new BasketImpl();

            mb.Add(new SecurityImpl("IBM"));
            BasketImpl compare = BasketImpl.Deserialize(mb.ToString());

            Assert.That(compare.Count == 1);
            mb.Clear();
            compare = BasketImpl.Deserialize(mb.ToString());
            Assert.That(compare.Count == 0);

            mb.Clear();
            SecurityImpl longform = SecurityImpl.Parse("CLZ8 FUT NYMEX");

            mb.Add(longform);
            compare = BasketImpl.Deserialize(mb.ToString());
            Assert.AreEqual(longform.ToString(), compare[0].ToString());
        }
Exemplo n.º 25
0
 void processcommands()
 {
     string[] args = Environment.GetCommandLineArgs();
     if (args.Length < 2)
     {
         return;
     }
     try
     {
         debug("attempting to auto-record basket: " + args[1]);
         Basket b = BasketImpl.FromFile(args[1]);
         subscribe(b);
         return;
     }
     catch (Exception ex)
     {
         debug("Error auto-subscribing to: " + args[1]);
         debug(ex.Message + ex.StackTrace);
     }
 }
Exemplo n.º 26
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            if (VerboseDebugging)
            {
                debug("client subscribe request received: " + symbols);
            }
            // get original basket
            Basket org = BasketImpl.FromString(symquotes);

            // if we had something before, check if something was removed
            if (org.Count > 0)
            {
                Basket rem = BasketImpl.Subtract(org, tl.AllClientBasket);
                foreach (Security s in rem)
                {
                    removesym.Write(s.Symbol);
                }
            }
            symquotes = tl.AllClientBasket.ToString();
            _symsq.Write(true);
        }
Exemplo n.º 27
0
        void processcommands()
        {
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length < 2)
            {
                return;
            }
            string f = args[1];

            if (!File.Exists(f))
            {
                status("Can't load basket file: " + Path.GetFileName(f));
                debug("file does not exist: " + f);
                return;
            }
            Basket nb = BasketImpl.FromFile(f);

            addbasket(nb);

            Refresh();
        }
Exemplo n.º 28
0
        void tl_newRegisterSymbols(string client, string symbols)
        {
            Basket b = BasketImpl.FromString(symbols);

            foreach (Security s in b)
            {
                // make sure we don't already have a subscription for this
                if (_symstk.Contains(s.symbol))
                {
                    continue;
                }
                BWStock stk = m_Session.GetStock(s.symbol);
                stk.Subscribe();
                stk.OnTrade += new BWStock.TradeHandler(stk_OnTrade);
                //stk.OnLevel2Update += new BWStock.Level2UpdateHandler(stk_OnLevel2Update);
                stk.OnLevel1Update += new BWStock.Level1UpdateHandler(stk_OnLevel1Update);
                _stocks.Add(stk);
                _symstk.Add(s.symbol);
                v("added level1 subscription for: " + s.symbol);
            }
            // get existing list
            Basket list = tl.AllClientBasket;

            // remove old subscriptions
            for (int i = 0; i < _symstk.Count; i++)
            {
                if (!list.ToString().Contains(_symstk[i]) && (_stocks[i] != null))
                {
                    debug(_symstk[i] + " not needed, removing...");
                    try
                    {
                        _stocks[i].Unsubscribe();
                        _stocks[i] = null;
                        _symstk[i] = string.Empty;
                    }
                    catch { }
                }
            }
        }
Exemplo n.º 29
0
        public void BasketBasics()
        {
            BasketImpl mb = new BasketImpl();

            Assert.That(mb != null);
            SecurityImpl i = new SecurityImpl("IBM");

            mb = new BasketImpl(i);
            Assert.That(mb.hasStock);
            mb.Remove(i);
            Assert.That(!mb.hasStock);
            mb.Add(new SecurityImpl("LVS"));
            Assert.That(mb[0].Symbol == "LVS", mb[0].ToString());
            mb.Add(new SecurityImpl("IBM"));
            Assert.That(mb[1].Symbol == "IBM");
            BasketImpl newbasket = new BasketImpl(new SecurityImpl("FDX"));

            newbasket.Add(mb);
            mb.Clear();
            Assert.That(mb.Count == 0);
            Assert.That(newbasket.Count == 3);
        }
Exemplo n.º 30
0
        /// <summary>
        /// gets a basket from a file
        /// </summary>
        /// <returns></returns>
        public Basket FetchFILE()
        {
            Basket mb = new BasketImpl();

            if ((_file == "") || (_file == null))
            {
                return(mb);
            }
            System.IO.StreamReader sr = null;
            try
            {
                sr = new System.IO.StreamReader(_file);
            }
            catch (Exception) { return(mb); }
            string file = sr.ReadToEnd();

            if (_nyse && _linkedonly)
            {
                mb.Add(ParseStocks.LinkedOnlyNYSE(file));
            }
            else if (_nyse)
            {
                mb.Add(ParseStocks.NYSE(file));
            }
            if (_nasd && _linkedonly)
            {
                mb.Add(ParseStocks.LinkedOnlyNASDAQ(file));
            }
            else if (_nasd)
            {
                mb.Add(ParseStocks.NASDAQ(file));
            }
            if (_xdupe)
            {
                mb = Fetch.RemoveDupe(mb);
            }
            return(mb);
        }