static void Main(string[] args) { String flexFileDirectory = @"C:\Users\David\Source\Repos\ibflexreporter\"; String[] files = Directory.GetFiles(flexFileDirectory, "*.xml"); List <Trade> allTrades = new List <Trade>(); foreach (String file in files) { XmlSerializer serializer = new XmlSerializer(typeof(FlexQueryResponse)); StringReader reader = new StringReader(File.ReadAllText(file)); FlexQueryResponse response = (FlexQueryResponse)serializer.Deserialize(reader); allTrades.AddRange(response.FlexStatements.FlexStatement.Trades); } foreach (Trade trade in allTrades) { TradeUtils.sanatizeSymbol(trade); } Console.WriteLine("Commision By Symbol"); TradeTracker t = new TradeTracker(allTrades.ToArray()); foreach (string symbol in t.getSymbols()) { Console.WriteLine(symbol + " " + t.getCommisionBySymbol(symbol)); } foreach (string symbol in t.getOptionSymbols()) { Console.WriteLine("Option " + symbol + " " + t.getCommisionByOptionSymbol(symbol)); } Console.WriteLine("Stock Trade Log"); StockTradeLog log = new StockTradeLog(allTrades.ToArray()); Console.WriteLine(log.ToString()); Console.WriteLine("Stock Position Report"); Console.WriteLine("Option Trade Log"); OptionTradeLog optLog = new OptionTradeLog(allTrades.ToArray()); Console.WriteLine(optLog.ToString()); Console.WriteLine("Option Position Report"); OptionReport optReport = new OptionReport(optLog); Console.WriteLine(optReport.ToString()); }
public OptionReport(OptionTradeLog log) { contractItems = new Dictionary <string, OptionReportItem>(); underlyingItems = new Dictionary <string, OptionReportItem>(); foreach (OptionTradeLog.OptionTradeItem trade in log) { OptionReportItem contractItem; OptionReportItem underlyingItem; if (contractItems.ContainsKey(trade.contract)) { contractItem = contractItems[trade.contract]; } else { contractItem = new OptionReportItem(); contractItem.contractsOutstanding = 0; contractItem.commision = 0; contractItem.realized = 0; } contractItem.contractsOutstanding += trade.contractCount; contractItem.commision += trade.commision; contractItem.realized += trade.price * trade.contractCount * 100 * -1; contractItems[trade.contract] = contractItem; if (underlyingItems.ContainsKey(trade.symbol)) { underlyingItem = underlyingItems[trade.symbol]; underlyingItem.contractsOutstanding += trade.contractCount; underlyingItem.commision += trade.commision; underlyingItem.realized += trade.price * trade.contractCount * 100 * -1; } else { underlyingItem = contractItem; } underlyingItems[trade.symbol] = underlyingItem; } }