// runs after simulation is complete void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { debug(_sb.ToString()); _sb = new System.Text.StringBuilder(10000000); GauntArgs gargs = (GauntArgs)e.Result; if (!e.Cancelled) { List <Trade> list = SimBroker.GetTradeList(); tradeResults1.NewResultTrades(LogFile("Trades"), list); if (gargs.Trades) { debug("writing " + list.Count + " trades..."); Util.ClosedPLToText(list, ',', LogFile("Trades")); } if (gargs.Orders) { List <Order> olist = SimBroker.GetOrderList(); debug("writing " + olist.Count + " orders..."); StreamWriter sw = new StreamWriter(LogFile("Orders"), false); string[] cols = Enum.GetNames(typeof(OrderField)); sw.WriteLine(string.Join(",", cols)); for (int i = 0; i < olist.Count; i++) { sw.WriteLine(OrderImpl.Serialize(olist[i])); } sw.Close(); } string msg = "Done. Ticks: " + gargs.TicksProcessed + " Speed:" + gargs.TicksSecond.ToString("N0") + " t/s Fills: " + gargs.Executions.ToString(); debug(msg); status(msg); } else { debug("Canceled."); } // close indicators if (indf != null) { indf.Close(); indf = null; } // reset simulation h.Reset(); count = 0; lastp = 0; if (args.isUnattended) { Close(); return; } // enable new runs ProgressBar1.Enabled = false; ProgressBar1.Value = 0; queuebut.Enabled = true; Invalidate(true); }
public void SerializationAndDeserialization() { // create an order const string s = "TST"; const string x = "NYSE"; const string a = "ACCOUNT"; const string u = "COMMENT"; const decimal p = 10; const int z = 100; const CurrencyType c = CurrencyType.USD; const SecurityType t = SecurityType.STK; Order o = new OrderImpl(s, z); o.date = 20080718; o.time = 94800; o.price = p; o.Account = a; o.ex = x; o.Currency = c; o.Security = t; o.comment = u; var inst = OrderInstructionType.GTC; o.ValidInstruct = inst; //o.TIF = ot; // convert it to a message string msg = OrderImpl.Serialize(o); // convert it back to an object and validate nothing was lost string exception = null; Order n = new OrderImpl(); try { n = OrderImpl.Deserialize(msg); } catch (Exception ex) { exception = ex.ToString(); } Assert.That(exception == null, msg + " " + exception); Assert.That(n.Account == a, n.Account); Assert.That(n.symbol == s, n.symbol); Assert.That(n.size == z, n.size.ToString()); Assert.That(n.price == p, n.price.ToString()); Assert.That(n.Exchange == x, n.Exchange); Assert.That(n.Security == t, n.Security.ToString()); Assert.That(n.Currency == c, n.Currency.ToString()); Assert.That(n.ValidInstruct == inst, n.ValidInstruct.ToString(), "unexpected instruction: " + n.ValidInstruct.ToString()); Assert.That(n.date == o.date, n.date.ToString()); Assert.That(n.time == o.time, n.time.ToString()); }
void updatecompletedtrades(List <Trade> list, bool savetrades, bool saveorders) { tradeResults1.NewResultTrades(LogFile("Trades"), list); TradeResults.GetPortfolioPlot("Equity", _initialequity.Value, 0, 0, Util.ToTLDate(), Util.ToTLTime(), list, ref equitychart, tradeResults1.CurrentResults.ComPerShare); if (savetrades) { debug("writing " + list.Count + " trades..."); Util.ClosedPLToText(list, ',', LogFile("Trades")); } if (saveorders) { List <Order> olist = SimBroker.GetOrderList(); debug("writing " + olist.Count + " orders..."); StreamWriter sw = new StreamWriter(LogFile("Orders"), false); string[] cols = Enum.GetNames(typeof(OrderField)); sw.WriteLine(string.Join(",", cols)); for (int i = 0; i < olist.Count; i++) { sw.WriteLine(OrderImpl.Serialize(olist[i])); } sw.Close(); } }