public void BasketBasics() { BasketImpl mb = new BasketImpl(); Assert.That(mb != null); SecurityImpl i = new SecurityImpl("IBM"); mb = new BasketImpl(i); mb.SendDebugEvent += new DebugDelegate(rt.d); Assert.That(mb.isNotEmpty); Assert.That(mb.isSecurityPresent(i), "missing ibm security"); Assert.That(mb.isSymbolPresent("IBM"), "missing ibm symbol"); Assert.IsFalse(mb.isSymbolPresent("LVS"), "had lvs before added"); mb.Remove(i); Assert.That(!mb.isNotEmpty); 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"); mb.Add("CLV8 FUT NYMEX"); Assert.AreEqual(3, mb.Count,"missing futures symbol"); Assert.IsTrue(mb[1].Type == SecurityType.STK, "not a equities type:" + mb[1].Type); Assert.IsTrue(mb[2].Type == SecurityType.FUT, "not a futures type:"+mb[2].Type); Security ts; Assert.IsTrue(mb.TryGetSecurityAnySymbol("IBM", out ts), "ibm fetch failed"); Assert.IsTrue(mb.TryGetSecurityAnySymbol("LVS", out ts), "lvs fetch failed"); Assert.IsTrue(mb.TryGetSecurityAnySymbol("CLV8", out ts), "CLV8 short fetch failed"); Assert.IsTrue(mb.TryGetSecurityAnySymbol("CLV8 NYMEX FUT", out ts), "CLV8 short fetch failed"); BasketImpl newbasket = new BasketImpl(new SecurityImpl("FDX")); newbasket.Add(mb); var orgcount = mb.Count; mb.Clear(); Assert.That(mb.Count==0,"basket clear did not work"); Assert.AreEqual(orgcount+1,newbasket.Count,"new basket missing symbols"); }
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); }
static void resettmpvars() { tmp_settablelist = string.Empty; //tmp_basketid = -1; tmp_basket = new BasketImpl(); tmp_barreqs.Clear(); }
public static Basket parsedata(string data, bool onlylinked, bool verify, DebugDelegate d) { debs = d; Basket b = new BasketImpl(); if (onlylinked) { Basket b2 = LinkedOnlyNASDAQ(data); if (b2.Count > 0) { b.Add(b2); } Basket b3 = LinkedOnlyNYSE(data); if (b3.Count > 0) { b.Add(b3); } } else { System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"[A-Z.]{1,6}"); foreach (System.Text.RegularExpressions.Match m in r.Matches(data)) { b.Add(m.Value); } } return(verify_equitysymbol(b, verify, d)); }
/// <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; }
/// <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; }
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()); }
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); }
/// <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); }
private void button2_Click(object sender, EventArgs e) { tc.RequestDOM(); String[] symlist = new String[2]; symlist[0] = textBox2.Text; symlist[1] = textBox3.Text; TradeLink.API.Basket b = new TradeLink.Common.BasketImpl(symlist); tc.Subscribe(b); }
public static Basket FromFile(string filename) { StreamReader sr = new StreamReader(filename); string file = sr.ReadToEnd(); sr.Close(); string[] syms = file.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); BasketImpl b = new BasketImpl(syms); return(b); }
/// <summary> /// gets symbols removed from newbasket, given original basket /// </summary> /// <param name="old"></param> /// <param name="newb"></param> /// <returns></returns> public static Basket Subtract(Basket old, Basket newb) { if (old.Count == 0) return new BasketImpl(); Basket rem = new BasketImpl(); foreach (Security sec in old) { if (!newb.ToString().Contains(sec.Symbol)) rem.Add(sec); } return rem; }
/// <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; }
/// <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; }
public static BasketImpl Deserialize(string serialBasket) { BasketImpl mb = new BasketImpl(); if ((serialBasket == null) || (serialBasket == "")) return mb; string[] r = serialBasket.Split(','); for (int i = 0; i < r.Length; i++) { if (r[i] == "") continue; SecurityImpl sec = SecurityImpl.Parse(r[i]); if (sec.isValid) mb.Add(sec); } return mb; }
/// <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; }
/// <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); }
public static Basket FromFile(string filename) { try { StreamReader sr = new StreamReader(filename); string file = sr.ReadToEnd(); sr.Close(); string[] syms = file.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); BasketImpl b = new BasketImpl(syms); b.Name = Path.GetFileNameWithoutExtension(filename); return(b); } catch { } return(new BasketImpl()); }
/// <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); }
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); }
/// <summary> /// gets symbols removed from newbasket, given original basket /// </summary> /// <param name="old"></param> /// <param name="newb"></param> /// <returns></returns> public static Basket Subtract(Basket old, Basket newb) { if (old.Count == 0) { return(new BasketImpl()); } Basket rem = new BasketImpl(); foreach (Security sec in old) { if (!newb.ToString().Contains(sec.symbol)) { rem.Add(sec); } } return(rem); }
public static Basket FromFile(string filename) { try { StreamReader sr = new StreamReader(filename); string file = sr.ReadToEnd(); sr.Close(); char[] filters = { '\r', '\n', ',' }; string[] syms = file.Split(filters, StringSplitOptions.RemoveEmptyEntries); BasketImpl b = new BasketImpl(syms); b.Name = Path.GetFileNameWithoutExtension(filename); return(b); } catch { } return(new BasketImpl()); }
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()); }
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); }
/// <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; }
public static BasketImpl Deserialize(string serialBasket) { BasketImpl mb = new BasketImpl(); if ((serialBasket == null) || (serialBasket == "")) { return(mb); } string[] r = serialBasket.Split(','); for (int i = 0; i < r.Length; i++) { if (r[i] == "") { continue; } SecurityImpl sec = SecurityImpl.Parse(r[i]); if (sec.isValid) { mb.Add(sec); } } return(mb); }
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); } } }
static Basket verify_equitysymbol(Basket b, bool googleyahoo, DebugDelegate d) { debs = d; b = RemoveDupe(b); if (googleyahoo) { Basket v = new BasketImpl(); foreach (Security s in b) { BarList bl = BarListImpl.DayFromAny(s.symbol, sdebug); if (bl.Count > 0) { v.Add(s.symbol); sdebug("verified google/yahoo: " + s.symbol + " bars: " + bl.Count); } else { sdebug("ignoring, not verified google/yahoo: " + s.symbol + " bars: " + bl.Count); } } return(v); } return(b); }
public static Basket FromFile(string filename) { try { StreamReader sr = new StreamReader(filename); string file = sr.ReadToEnd(); sr.Close(); string[] syms = file.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); BasketImpl b = new BasketImpl(syms); b.Name = Path.GetFileNameWithoutExtension(filename); return b; } catch { } return new BasketImpl(); }
public static Basket FromFile(string filename) { try { StreamReader sr = new StreamReader(filename); string file = sr.ReadToEnd(); sr.Close(); char[] filters = {'\r', '\n', ','}; string[] syms = file.Split(filters, StringSplitOptions.RemoveEmptyEntries); BasketImpl b = new BasketImpl(syms); b.Name = Path.GetFileNameWithoutExtension(filename); return b; } catch { } return new BasketImpl(); }
public static Basket FromFile(string filename) { StreamReader sr = new StreamReader(filename); string file = sr.ReadToEnd(); sr.Close(); string[] syms = file.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); BasketImpl b = new BasketImpl(syms); return b; }
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); } }
static Basket verify_equitysymbol(Basket b, bool googleyahoo, DebugDelegate d) { debs = d; b = RemoveDupe(b); if (googleyahoo) { Basket v = new BasketImpl(); foreach (Security s in b) { BarList bl = BarListImpl.DayFromAny(s.symbol,sdebug); if (bl.Count > 0) { v.Add(s.symbol); sdebug("verified google/yahoo: " + s.symbol + " bars: " + bl.Count); } else sdebug("ignoring, not verified google/yahoo: " + s.symbol + " bars: " + bl.Count); } return v; } return b; }
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"); }
public static Basket parsedata(string data, bool onlylinked, bool verify, DebugDelegate d) { debs = d; Basket b = new BasketImpl(); if (onlylinked) { Basket b2 = LinkedOnlyNASDAQ(data); if (b2.Count > 0) b.Add(b2); Basket b3 = LinkedOnlyNYSE(data); if (b3.Count > 0) b.Add(b3); } else { System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(@"[A-Z.]{1,6}"); foreach (System.Text.RegularExpressions.Match m in r.Matches(data)) b.Add(m.Value); } return verify_equitysymbol(b, verify, d); }
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); } }
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; if (_bf.FeedClient == null) return; try { // resubscribe _bf.Subscribe(_mb); } catch (TLServerNotFound) { debug("symbol subscribe failed as no TL server was found."); } }
void tl_newRegisterSymbols(string client, string symbols) { if (VerboseDebugging) debug("client subscribe request received: " + symbols); // get original basket Basket org = BasketImpl.FromString(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()); // add current foreach (string sym in org.ToSymArray()) { // subscribe what we don't have if (!syms.Contains(sym)) oEngine.subscribe(string.Empty,sym,flags,null); } // remove old foreach (Security s in rem) { oEngine.unsubscribe(string.Empty, s.Symbol); } }
void bw_DoWork(object sender, DoWorkEventArgs e) { if (!_valid) return; while (_go) { try { if (qc > qr) { // get requested symbols string[] syms = _tmpregister.Split(','); // go through each one foreach (string sym in syms) { // if we don't have subscription already if (!contains(sym)) { // add it to list _mb.Add(sym); // request subscription esig.RequestSymbol(sym, 1); } } if (ReleaseDeadSymbols) { // clone requested basket Basket newbasket = new BasketImpl(syms); // clone existing basket as deadbasket Basket deadbasket = new BasketImpl(_mb); // existing - new = deadsymbols deadbasket.Remove(newbasket); // release dead symbols string symsreleased = string.Empty; foreach (Security dead in deadbasket) { try { esig.ReleaseSymbol(dead.symbol); symsreleased += dead.symbol + " "; } catch { } } if (symsreleased!=string.Empty) verb("released unused symbols: " + symsreleased); } qr = qc; } while (_barrequests.hasItems) { BarRequest br = new BarRequest(); try { br = _barrequests.Read(); BarInterval bi = (BarInterval)br.Interval; string interval = string.Empty; int barsback = DefaultBarsBack; if (bi == BarInterval.CustomTicks) interval = br.CustomInterval + "T"; else if (bi == BarInterval.CustomTime) interval = br.CustomInterval + "S"; else if (bi == BarInterval.CustomVol) interval = br.CustomInterval + "V"; else { if (br.Interval == (int)BarInterval.Day) interval = "D"; else interval = (br.Interval / 60).ToString(); barsback = BarImpl.BarsBackFromDate(bi, br.StartDateTime, br.EndDateTime); } int alldata = BarRequestsGetAllData ? -1 : 0; int hnd = esig.get_RequestHistory(br.symbol, interval, (bi == BarInterval.Day) ? barType.btDAYS : barType.btBARS, barsback, alldata, alldata); verb("requested bar data for " + br.symbol + " on: " + br.Interval.ToString() + " " + br.CustomInterval.ToString() + " reqhandle: " + hnd); // cache request if (!_barhandle2barrequest.ContainsKey(hnd)) _barhandle2barrequest.Add(hnd, br); else verb("already had bar request: " + hnd + " " + _barhandle2barrequest[hnd].ToString()); if (esig.get_IsHistoryReady(hnd) != 0) processhistory(hnd, br); } catch (Exception ex) { debug("error on historical bar request: " + br.ToString()); debug(ex.Message + ex.StackTrace); } } } catch (Exception ex) { if (GotDebug != null) GotDebug(ex.Message + ex.StackTrace); } if (e.Cancel || !_go) break; System.Threading.Thread.Sleep(WaitBetweenEvents); } }