private void SendTransactionsToFile() { string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; //if (File.Exists(filepath)) File.Delete(filepath); var liststring = CsvSerializer.Serialize <OrderTransaction>(",", _transactions, true); using (StreamWriter fs = new StreamWriter(filepath, true)) { foreach (var s in liststring) { fs.WriteLine(s); } fs.Flush(); fs.Close(); } }
/// <summary> /// Sells out all positions at 15:50, and calculates the profits for the day /// emails the transactions for the day to me /// </summary> /// <param name="data">TradeBars - the data</param> /// <returns>false if end of day, true during the day </returns> public bool SoldOutAtEndOfDay(KeyValuePair <Symbol, TradeBar> data) { if (shouldSellOutAtEod) { if (this.Time.Hour == 15 && this.Time.Minute > 49 || this.Time.Hour == 16) { if (CanMakeTrade) { if (Portfolio[symbol].IsLong) { Sell(symbol, Portfolio[symbol].AbsoluteQuantity); } if (Portfolio[symbol].IsShort) { Buy(symbol, Portfolio[symbol].AbsoluteQuantity); } } // Daily Profit #region logging if (this.Time.Hour == 16) { CalculateDailyProfits(); //sharesOwned = Portfolio[symbol].Quantity; var _transactionsAsCsv = CsvSerializer.Serialize <OrderTransaction>(",", _transactions, true); StringBuilder sb = new StringBuilder(); foreach (string s in _transactionsAsCsv) { sb.AppendLine(s); } string attachment = sb.ToString(); Notify.Email("*****@*****.**", "Todays Trades " + this.Time.ToLongDateString(), "Number of Trades: " + _tradecount, attachment); SendTransactionsToFile(); _transactions = new List <OrderTransaction>(); } #endregion return(false); } } return(true); }
private void NotifyUser() { #region logging if (this.Time.Hour == 16) { var transactionsAsCsv = CsvSerializer.Serialize <OrderTransaction>(",", _transactions, true); StringBuilder sb = new StringBuilder(); var transcount = _transactions.Count(); foreach (string s in transactionsAsCsv) { sb.AppendLine(s); } string attachment = sb.ToString(); Notify.Email("*****@*****.**", string.Format("Transactions For: {0}", Time.ToLongDateString()), string.Format("Todays Date: {0} \nNumber of Transactions: {1}", Time.ToLongDateString(), _transactions.Count()), attachment); var tradesAsCsv = CsvSerializer.Serialize <MatchedTrade>(",", _orderTransactionProcessor.Trades.Where(f => f.DateAcquired == tradingDate), true); var tradecount = _orderTransactionProcessor.Trades.Count(); sb = new StringBuilder(); foreach (string s in tradesAsCsv) { sb.AppendLine(s); } attachment = sb.ToString(); Notify.Email("*****@*****.**", string.Format("Trades for: {0}", Time.ToLongDateString()), string.Format("Todays Date: {0} \nNumber of Trades: {1}", Time.ToLongDateString(), tradecount), attachment); _transactions = new List <OrderTransaction>(); } #endregion }
private void SendOrderEventsToFile() { string filepath = AssemblyLocator.ExecutingDirectory() + "orderEvents.csv"; if (File.Exists(filepath)) { File.Delete(filepath); } var liststring = CsvSerializer.Serialize <OrderEvent>(",", _orderEvents, true); using (StreamWriter fs = new StreamWriter(filepath, true)) { foreach (var s in liststring) { fs.WriteLine(s); } fs.Flush(); fs.Close(); } }
private void SendTradesToFile(string filename, IList <MatchedTrade> tradelist) { string filepath = AssemblyLocator.ExecutingDirectory() + filename; if (File.Exists(filepath)) { File.Delete(filepath); } var liststring = CsvSerializer.Serialize <MatchedTrade>(",", tradelist); using (StreamWriter fs = new StreamWriter(filepath, true)) { foreach (var s in liststring) { fs.WriteLine(s); } fs.Flush(); fs.Close(); } }
public override void OnEndOfAlgorithm() { Debug(string.Format("\nAlgorithm Name: {0}\n Ending Portfolio Value: {1} ", this.GetType().Name, Portfolio.TotalPortfolioValue)); #region Logging stuff - Saving the logs int i = 0; //foreach (string symbol in Symbols) //{ // string filename = string.Format("ITrendDebug_{0}.csv", symbol); // string filePath = @"C:\Users\JJ\Desktop\MA y señales\ITrend Debug\" + filename; // // JJ do not delete this line it locates my engine\bin\debug folder // // I just uncomment it when I run on my local machine // filePath = AssemblyLocator.ExecutingDirectory() + filename; // if (File.Exists(filePath)) File.Delete(filePath); // File.AppendAllText(filePath, stockLogging[i].ToString()); // Debug(string.Format("\nSymbol Name: {0}, Ending Portfolio Value: {1} ", symbol, Portfolio[symbol].Profit)); //} string filepath = AssemblyLocator.ExecutingDirectory() + "transactions.csv"; if (File.Exists(filepath)) { File.Delete(filepath); } var liststring = CsvSerializer.Serialize <OrderTransaction>(",", _transactions, true); using (StreamWriter fs = new StreamWriter(filepath)) { foreach (var s in liststring) { fs.WriteLine(s); } fs.Flush(); fs.Close(); } #endregion Logging stuff - Saving the logs }