コード例 #1
0
        public static PositionsFile UpdatePositionsFile(PositionsFile originalFile, UpdatesFile updatesFile)
        {
            var updatedFile = originalFile.Clone();

            updatedFile.loadExceptions = new List <string>();
            updatedFile.header.Date    = DateTime.Today;

            var updatedOptions = updatesFile.updates.Where(u => u.SEC_TYPE == "Option").ToList();

            foreach (var update in updatedOptions)
            {
                try
                {
                    var matchingPositions = updatedFile.positions.Where(p => p.TradeSymbol.Trim() == update.getShortTicker() && p.PositionType == update.getPositionType() && p.Price == update.MKT_PRICE).ToList();

                    if (matchingPositions.Count > 0)
                    {
                        foreach (var matchingPosition in matchingPositions)
                        {
                            matchingPosition.Price = update.MKT_PRICE_NEW;
                        }
                    }
                    else
                    {
                        throw new Exception("Couldn't find corresponing position for Ticker: " + update.TICKER);
                    }
                }
                catch (Exception e)
                {
                    updatedFile.loadExceptions.Add(e.Message);
                }
            }
            return(updatedFile);
        }
コード例 #2
0
        public static UpdatesFile GenerateUpdatesFile(string filePath)
        {
            var updatesFile = new UpdatesFile();

            updatesFile.updates        = new List <Update>();
            updatesFile.loadExceptions = new List <string>();

            using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
            {
                using (var reader = ExcelReaderFactory.CreateReader(stream))
                {
                    var result   = reader.AsDataSet();
                    var workbook = result.Tables[0];
                    var i        = 0;
                    foreach (DataRow row in workbook.Rows)
                    {
                        i++;
                        try
                        {
                            var cells = row.ItemArray.Select(c => c.ToString()).Take(10).ToList();
                            if (!String.IsNullOrEmpty(cells[0]) && cells[0] != "OFFICE" && !String.IsNullOrEmpty(cells[9]))
                            {
                                var update = new Update();
                                update.OFFICE        = parseInt(cells[0], "OFFICE");
                                update.TICKER        = parseNotNullString(cells[1], "TICKER");
                                update.REAL_CUSIP    = cells[2].Trim();
                                update.DESC_1        = cells[3].Trim();
                                update.POSITION      = parseInt(cells[4], "POSITION");
                                update.MKT_PRICE     = parseDouble(cells[5], "NMKT_PRICE", true);
                                update.MKT_VAL       = (double)parseDouble(cells[6], "MKT_VAL", false);
                                update.POS_DT        = parseDate(cells[7], "POS_DT");
                                update.SEC_TYPE      = cells[8].Trim();
                                update.MKT_PRICE_NEW = (double)parseDouble(cells[9], "NMKT_PRICE(2)", false);
                                updatesFile.updates.Add(update);
                            }
                        }
                        catch (Exception e)
                        {
                            updatesFile.loadExceptions.Add(String.Format("Error on row {0} : {1}", i, e.Message));
                        }
                    }
                }
            }

            return(updatesFile);
        }