示例#1
0
        public static string GeneratePositionsFile(PositionsFile updatedFile)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append(updatedFile.header.TransId);
            stringBuilder.Append("H");
            stringBuilder.Append(updatedFile.header.FirmNumber.ToString("D4"));
            stringBuilder.Append(updatedFile.header.Date.ToString("yyyyMMdd"));
            stringBuilder.Append("\n");

            foreach (var position in updatedFile.positions)
            {
                stringBuilder.Append(position.TransId);
                stringBuilder.Append(" ");
                stringBuilder.Append(position.FirmNumber.ToString("D4"));
                stringBuilder.Append(position.Account);
                stringBuilder.Append((char)position.PositionType);
                stringBuilder.Append(position.TradeSymbol);
                stringBuilder.Append(getDate(position.Expiration));
                stringBuilder.Append(getStrike(position.Strike));
                stringBuilder.Append((char)position.MarketPosition);
                stringBuilder.Append((char)position.SecurityType);
                stringBuilder.Append(getPrice(position.Price));
                stringBuilder.Append(position.Quantity.ToString("D9"));
                stringBuilder.Append((char)position.MMIndicator);
                stringBuilder.Append(position.BasketId);
                stringBuilder.Append(position.Filler);
                stringBuilder.Append("\n");
            }

            return(stringBuilder.ToString());
        }
示例#2
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);
        }
        public static PositionsFile LoadPositions(string filePath)
        {
            var text  = System.IO.File.ReadAllText(filePath);
            var lines = text.Split(new char[] { '\n' }).ToList();

            if (lines.Count() > 1)
            {
                var positionsFile = new PositionsFile();
                positionsFile.header = ParsePositionsHeader(lines[0]);
                var parsedFile = ParsePositions(lines.Skip(1).ToList());
                positionsFile.positions      = parsedFile.Item1;
                positionsFile.loadExceptions = parsedFile.Item2;
                return(positionsFile);
            }
            else
            {
                throw new Exception("File is empty. Positions file requires a header and at least one row.");
            }
        }