public void Parsing() { // tests to parse and generate user-supplied security specifiers SecurityImpl nyse = new SecurityImpl("LVS"); string p = nyse.ToString(); SecurityImpl t = SecurityImpl.Parse(p); Assert.That(t.Symbol == nyse.Symbol, t.Symbol); Assert.That(!t.hasDest, t.DestEx); Assert.That(t.Type == nyse.Type, t.Type.ToString()); SecurityImpl crude = SecurityImpl.Parse("CLV8 FUT GLOBEX"); Assert.That(crude.Symbol == "CLV8", crude.Symbol); Assert.That(crude.hasDest, crude.DestEx); Assert.That(crude.Type == SecurityType.FUT, crude.Type.ToString()); SecurityImpl goog = SecurityImpl.Parse("GOOG"); Assert.AreEqual("GOOG", goog.FullName); Security opt = SecurityImpl.Parse("IBM PUT 201004 100.00"); Assert.That(opt.Type == SecurityType.OPT); Assert.AreEqual(100, opt.Strike); Assert.AreEqual("PUT", opt.Details); Assert.AreEqual(201004, opt.Date); }
public void Parsing() { // tests to parse and generate user-supplied security specifiers SecurityImpl nyse = new SecurityImpl("LVS"); string p = nyse.ToString(); SecurityImpl t = SecurityImpl.Parse(p); Assert.True(t.Name == nyse.Name, t.Name); Assert.True(t.Type == nyse.Type, t.Type.ToString()); SecurityImpl crude = SecurityImpl.Parse("CLV8 FUT GLOBEX"); Assert.True(crude.Name == "CLV8", crude.Name); Assert.True(crude.HasDest, crude.DestEx); Assert.True(crude.Type == SecurityType.Future, crude.Type.ToString()); SecurityImpl goog = SecurityImpl.Parse("GOOG"); Assert.Equal("GOOG", goog.Name); }
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()); }
private void Trade_Click(object sender, EventArgs e) { // user clicks on trade button // make sure a response is selected if (_availresponses.SelectedIndex == -1) { status("Please select a response."); return; } // get all the provided symbols string[] syms = _symstraded.Text.Split(','); // prepare a list of valid symbols List <string> valid = new List <string>(); // process every provided symbol foreach (string symt in syms) { // make it uppercase string sym = symt.ToUpper(); // parse out security information SecurityImpl sec = SecurityImpl.Parse(sym); // if it's an invalid security, ignore it if (!sec.isValid) { status("Security invalid: " + sec.ToString()); continue; } // otherwise add the security _mb.Add(sec); // save simple symbol as valid valid.Add(sec.Symbol); // if we don't have this security if (!_seclist.ContainsKey(sec.Symbol)) { // lock so other threads don't modify seclist at same time lock (_seclist) { // add security to our list _seclist.Add(sec.Symbol, sec); } } } // add working response to response list after obtaining a lock lock (_reslist) { _reslist.Add(_workingres); } // get index to this response int idx = _reslist.Count - 1; // send response current positions foreach (Position p in _pt) { _reslist[idx].GotPosition(p); } // subscribe to whatever symbols were requested try { tl.Subscribe(_mb); } catch (TLServerNotFound) { debug("subscribe failed because no TL server is running."); } // add name to user's screen _resnames.Items.Add(_workingres.FullName + " [" + string.Join(",", valid.ToArray()) + "]"); // update their screen _resnames.Invalidate(true); // process all securities and build a quick index for a security's name to the response that requests it foreach (SecurityImpl sec in _seclist.Values) { if (_symidx.ContainsKey(sec.FullName)) // we already had one requestor { // get current length of request list for security int len = _symidx[sec.FullName].Length; // add one to it for our new requestor int[] a = new int[len + 1]; // add our new requestor's index at the end a[len] = idx; } else // otherwise it's just this guy so add him { _symidx.Add(sec.FullName, new int[] { idx }); } } // clear the symbol list _symstraded.Clear(); // show we added response status(_workingres.FullName + " [" + string.Join(",", valid.ToArray()) + "]"); // unselect response _availresponses.SelectedIndex = -1; }