Esempio n. 1
0
 public void Add(MarketBasket mb)
 {
     for (int i = 0; i < mb.Count; i++)
     {
         this.Add(mb[i]);
     }
 }
Esempio n. 2
0
 public static MarketBasket NYSE(string ParseStocks)
 {
     MarketBasket mb = new MarketBasket();
     MatchCollection mc = Regex.Matches(ParseStocks, @"\b[A-Z]{1,3}\b");
     for (int i = 0; i < mc.Count; i++)
         mb.Add(new Stock(mc[i].Value.ToUpper()));
     return mb;
 }
Esempio n. 3
0
 public static MarketBasket RemoveUnlisted(MarketBasket input)
 {
     MarketBasket output = new MarketBasket();
     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;
 }
Esempio n. 4
0
 public void Multiple()
 {
     MarketBasket mb = new MarketBasket(new string[] { "IBM","LVS","T","GS","MHS" } );
     MarketBasket rem = new MarketBasket(new string[] { "LVS", "MHS" });
     Assert.That(mb.Count == 5);
     Assert.That(rem.Count == 2);
     mb.Subtract(rem);
     Assert.That(mb.Count == 3,mb.Count.ToString());
 }
Esempio n. 5
0
 public void Subtract(MarketBasket mb)
 {
     List<int> remove = new List<int>();
     for (int i = 0; i < stocks.Count; i++)
         for (int j = 0; j < mb.Count; j++)
             if (stocks[i].Symbol == mb[j].Symbol)
                 remove.Add(i);
     for (int i = remove.Count - 1; i >= 0; i--)
         stocks.RemoveAt(remove[i]);
 }
Esempio n. 6
0
 public static MarketBasket FromString(string serialBasket)
 {
     MarketBasket mb = new MarketBasket();
     if ((serialBasket == null) || (serialBasket == "")) return mb;
     string[] r = serialBasket.Split(',');
     for (int i = 0; i < r.Length; i++)
         if ((r[i]!="") && Stock.isStock(r[i]))
             mb.Add(new Stock(r[i]));
     return mb;
 }
Esempio n. 7
0
 public MarketBasket URL()
 {
     MarketBasket mb = new MarketBasket();
     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;
 }
Esempio n. 8
0
 public static MarketBasket RemoveDupe(MarketBasket input)
 {
     List<string> cache = new List<string>();
     MarketBasket output = new MarketBasket();
     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;
 }
Esempio n. 9
0
        public void Serialization()
        {
            MarketBasket mb = new MarketBasket();
            mb.Add(new Stock("IBM"));
            MarketBasket compare = MarketBasket.FromString(mb.ToString());
            Assert.That(compare.Count == 1);
            mb.Clear();
            compare = MarketBasket.FromString(mb.ToString());
            Assert.That(compare.Count==0);



        }
Esempio n. 10
0
 public static MarketBasket LinkedOnlyNASDAQ(string parsestring)
 {
     MarketBasket mb = new MarketBasket();
     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 Stock(chunk.ToUpper()));
     }
     return mb;
 }
Esempio n. 11
0
 private void okbut_Click(object sender, EventArgs e)
 {
     _ft.Name = urlnamebox.Text;
     _ft.Url = urlbox.Text;
     _ft.ParseNASD = nasdaqbut.Checked;
     _ft.ParseNYSE = nysebut.Checked;
     _ft.ClickableOnly = linkedonlybut.Checked;
     string username = "";
     if (FetchUsername != null) username = FetchUsername();
     _basket = _ft.Go(username);
     if (_basket.hasStock)
         DialogResult = DialogResult.OK;
     else
         DialogResult = DialogResult.Abort;
     this.Close();
 }
Esempio n. 12
0
        public static MarketBasket FromString(string serialBasket)
        {
            MarketBasket mb = new MarketBasket();

            if ((serialBasket == null) || (serialBasket == ""))
            {
                return(mb);
            }
            string[] r = serialBasket.Split(',');
            for (int i = 0; i < r.Length; i++)
            {
                if ((r[i] != "") && Stock.isStock(r[i]))
                {
                    mb.Add(new Stock(r[i]));
                }
            }
            return(mb);
        }
Esempio n. 13
0
        public void Subtract(MarketBasket mb)
        {
            List <int> remove = new List <int>();

            for (int i = 0; i < stocks.Count; i++)
            {
                for (int j = 0; j < mb.Count; j++)
                {
                    if (stocks[i].Symbol == mb[j].Symbol)
                    {
                        remove.Add(i);
                    }
                }
            }
            for (int i = remove.Count - 1; i >= 0; i--)
            {
                stocks.RemoveAt(remove[i]);
            }
        }
Esempio n. 14
0
 public void BasketBasics()
 {
     MarketBasket mb = new MarketBasket();
     Assert.That(mb != null);
     Stock i = new Stock("IBM");
     mb = new MarketBasket(i);
     Assert.That(mb.hasStock);
     mb.Remove(i);
     Assert.That(!mb.hasStock);
     mb.Add(new Stock("LVS"));
     Assert.That(mb.Get(0).Symbol=="LVS",mb[0].ToString());
     mb.Add(new Stock("IBM"));
     Assert.That(mb[1].Symbol=="IBM");
     MarketBasket newbasket = new MarketBasket(new Stock("FDX"));
     newbasket.Add(mb);
     mb.Clear();
     Assert.That(mb.Count==0);
     Assert.That(newbasket.Count==3);
 }
Esempio n. 15
0
 public MarketBasket FILE()
 {
     MarketBasket mb = new MarketBasket();
     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;
     
     
 }
 public void Subscribe(MarketBasket mb)
 {
     TLSend(TL2.REGISTERSTOCK, Text + "+" + mb.ToString());
 }
Esempio n. 17
0
 public void Subscribe(MarketBasket mb)
 {
     TLSend(TL2.REGISTERSTOCK, Text + "+" + mb.ToString());
 }
Esempio n. 18
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
        }
Esempio n. 19
0
 public void Subscribe(MarketBasket mb)
 {
     TLSend(new LinkMessage(TL2.REGISTERSTOCK, mb));
 }
Esempio n. 20
0
 public void Add(MarketBasket mb)
 {
     for (int i = 0; i < mb.Count; i++)
         this.Add(mb[i]);
 }
Esempio n. 21
0
 public void Subscribe(MarketBasket mb) { TLSend(new LinkMessage(TL2.REGISTERSTOCK, mb)); }