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); }
public static MarketBasket FromURL(string url) { MarketBasket b = NYSEFromURL(url); b.Add(NASDAQFromURL(url)); return(b); }
private void symbox_KeyUp(object sender, KeyEventArgs e) { if (e.KeyData == Keys.Enter) { int size = mb.Count + ib.Count; if (Stock.isStock(symbox.Text)) { mb.Add(new Stock(symbox.Text)); } else if (Index.isIdx(symbox.Text)) { ib.Add(new Index(symbox.Text)); } refreshlist(size); } }
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); }
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); }
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); }
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); }
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 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); }
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); }
private void Trade_Click(object sender, EventArgs e) { string sym = stock.Text.ToUpper(); if (!Stock.isStock(sym)) { status("Please input a stock symbol."); return; } if (Boxes.SelectedIndex == -1) { status("Please select a box."); return; } Security sec = Security.Parse(sym); string shortsym = sec.Symbol; string boxcrit = "Box on " + sym + " with " + (string)Boxes.SelectedItem; if (boxlist.ContainsKey(shortsym)) { if (MessageBox.Show("For safety, you're only allowed one box per symbol. Would you like to replace existing box?", "Confirm box replace", MessageBoxButtons.YesNoCancel) == DialogResult.Yes) { status("flatting symbol " + shortsym); tl.SendOrder(new MarketOrder(shortsym, boxlist[shortsym].PosSize * -1)); boxlist[shortsym].Shutdown("user requested shutdown"); string name = boxlist[shortsym].Name; boxlist.Remove(shortsym); status("Removed strategy " + name + " from " + shortsym); } else { status("Box activation canceled because of too many boxes."); return; } } mb.Add(new Stock(sym)); tl.Subscribe(mb); workingbox.Symbol = shortsym; boxcriteria.Items.Add(workingbox.Name + " [" + shortsym + "]"); boxlist.Add(shortsym, workingbox); seclist.Add(shortsym, sec); boxes.Add(workingbox); stock.Text = ""; status(""); Boxes.SelectedIndex = -1; }
private void importbasketbut_Click(object sender, EventArgs e) { OpenFileDialog od = new OpenFileDialog(); od.Multiselect = true; od.Filter = "Basket (*.mb)|*.mb|All files (*.*)|*.*"; od.AddExtension = true; od.DefaultExt = ".mb"; od.CheckFileExists = true; od.Title = "Select the baskets you wish to import to quototpia"; if (od.ShowDialog() == DialogResult.OK) { foreach (string f in od.FileNames) { StreamReader sr = new StreamReader(f); string line = sr.ReadLine(); sr.Close(); string[] r = line.Split(','); int skipped = 0; for (int i = 0; i < r.Length; i++) { bool add = true; if (Stock.isStock(r[i])) { mb.Add(new Stock(r[i])); } else if (Index.isIdx(r[i])) { ib.Add(new Index(r[i])); } else { add = false; skipped++; } if (add) { addsymbol(r[i]); } } status("Imported " + (r.Length - skipped) + " instruments."); } } tl.Subscribe(mb); tl.RegIndex(ib); }