Example #1
0
        internal void copyADMDataToFile(List <ADMPositionImportWeb> admPositionImportWeb, ImportFileCheck importFileCheck)
        {
            try
            {
                //                 String fullFile = System.IO.Path.Combine(Directory.GetCurrentDirectory(),
                //                         TradingSystemConstants.ADM_DATA_FOLDER, TradingSystemConstants.ADM_STORED_DATA_FILE);

                String dir = System.IO.Path.Combine(Directory.GetCurrentDirectory(), TradingSystemConstants.FCM_DATA_FOLDER);

                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }


                System.IO.StreamWriter fs = new System.IO.StreamWriter(getNameOfADMPositionImportWebStored());

                bool firstLine = true;

                StringBuilder stringOut = new StringBuilder();

                for (int lineCounter = 0; lineCounter < admPositionImportWeb.Count; lineCounter++)
                {
                    stringOut.Clear();

                    if (firstLine)
                    {
                        stringOut.Append(Enum.GetName(typeof(BrokerImportFiles), BrokerImportFiles.BACKUP_SAVED_FILE));
                        stringOut.Append("\t");

                        fs.WriteLine(stringOut.ToString());

                        stringOut.Clear();

                        firstLine = false;
                    }



                    stringOut.Append(admPositionImportWeb[lineCounter].RecordType);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].POFFIC);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PACCT);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PCUSIP);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PCUSIP2);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].Description);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].LongQuantity);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].ShortQuantity);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].TradeDate);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].TradePrice / admPositionImportWeb[lineCounter].instrument.admFuturePriceFactor);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].WeightedPrice);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].RealTimePrice);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].SettledPrice);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PrelimPrice);

                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].Value);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].ClosedValue);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].SettledValue);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].Currency);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PSUBTY);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PEXCH);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PFC);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].strikeInDecimal);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PCTYM);
                    stringOut.Append("\t");
                    stringOut.Append(admPositionImportWeb[lineCounter].PCARD);
                    stringOut.Append("\t");


                    fs.WriteLine(stringOut.ToString());
                }

                fs.Close();
            }
            catch (Exception ex)
            {
                TSErrorCatch.errorCatchOut(Convert.ToString(this), ex);
            }
        }
Example #2
0
        internal void readADMDetailedPositionImportWeb(String[] fileNames,
                                                       List <ADMPositionImportWeb> admSummaryFieldsList, ImportFileCheck importFileCheck,
                                                       Instrument[] instruments)//, bool[] doNotImportFile)
        {
            BrokerImportFiles brokerImportFiles = BrokerImportFiles.BACKUP_SAVED_FILE;
            FTPInputFileTypes cSVImportFileType = FTPInputFileTypes.ADM_WEB_INTERFACE_FILES;

            importFileCheck.importfile = true;

            //bool importFile = true;

#if DEBUG
            try
#endif
            {
                Type  admSummaryFieldTypes     = typeof(ADM_DETAIL_FIELDS);
                Array admSummaryFieldTypeArray = Enum.GetNames(admSummaryFieldTypes);

                for (int fileCounter = 0; fileCounter < fileNames.Length; fileCounter++)
                {
                    bool firstLine = true;

                    if (File.Exists(fileNames[fileCounter]))
                    {
                        DateTime lastWriteTime = File.GetLastWriteTime(fileNames[fileCounter]);

                        {
                            FileStream fileStream = new FileStream(fileNames[fileCounter],
                                                                   FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                            StreamReader streamReader = new StreamReader(fileStream);


                            if (fileNames[fileCounter].ToLower().EndsWith(".csv"))
                            {
                                string[] parsedFileName = fileNames[fileCounter].Split('\\');

                                if (parsedFileName.Last().Substring(0, 3).ToLower().CompareTo("pos") == 0)
                                {
                                    cSVImportFileType = FTPInputFileTypes.POSITION_FILE_WEDBUSH_OR_RCG;

                                    brokerImportFiles = BrokerImportFiles.GMI_IMPORT_CSV_FILES;
                                }
                                else if (parsedFileName.Last().Substring(0, 3).ToLower().CompareTo("prl") == 0)
                                {
                                    cSVImportFileType = FTPInputFileTypes.TRANSACTION_FILE_WEDBUSH;

                                    brokerImportFiles = BrokerImportFiles.GMI_IMPORT_CSV_FILES;
                                }
                                else if (parsedFileName.Last().Substring(0, 4).ToLower().CompareTo("trnd") == 0)
                                {
                                    cSVImportFileType = FTPInputFileTypes.TRANSACTION_FILE_RCG;

                                    brokerImportFiles = BrokerImportFiles.GMI_IMPORT_CSV_FILES;
                                }
                                else if (parsedFileName.Last().ToLower().EndsWith("adatpos.csv"))
                                {
                                    cSVImportFileType = FTPInputFileTypes.POSITION_FILE_ADM;

                                    brokerImportFiles = BrokerImportFiles.GMI_IMPORT_CSV_FILES;
                                }
                                else if (parsedFileName.Last().ToLower().EndsWith("aaprlmcsv.csv"))
                                {
                                    cSVImportFileType = FTPInputFileTypes.TRANSACTION_FILE_ADM;

                                    brokerImportFiles = BrokerImportFiles.ADM_WEB_IMPORT_FILES;
                                }
                                else
                                {
                                    importFileCheck.importfile = false;

                                    String            caption = "An imported file is not a 'pos' or 'prl' file";
                                    String            message = fileNames[fileCounter] + "\nis not a 'pos' or 'prl'";
                                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                                    System.Windows.Forms.DialogResult result;

                                    // Displays the MessageBox.
                                    result = MessageBox.Show(message, caption, buttons, MessageBoxIcon.Error);
                                }
                            }
                            else
                            {
                                cSVImportFileType = FTPInputFileTypes.ADM_WEB_INTERFACE_FILES;
                                brokerImportFiles = BrokerImportFiles.ADM_WEB_IMPORT_FILES;
                            }

                            bool setFileReader = false;
                            Fill_GMI_ImportDelegate Import_GMI = null;

                            while (!(streamReader.EndOfStream) && importFileCheck.importfile)
                            {
                                String line = streamReader.ReadLine();
                                if (line.Length > 0)
                                {
                                    List <String> stringList;  // = readSeparatedLine(line, '\t');


                                    if (cSVImportFileType == FTPInputFileTypes.ADM_WEB_INTERFACE_FILES ||
                                        importFileCheck.importingBackedUpSavedFile)
                                    {
                                        stringList = readSeparatedLine(line, '\t');
                                    }
                                    else
                                    {
                                        stringList = readSeparatedLine(line, ',');
                                    }

                                    if (cSVImportFileType == FTPInputFileTypes.POSITION_FILE_ADM ||
                                        cSVImportFileType == FTPInputFileTypes.TRANSACTION_FILE_ADM)
                                    {
                                        //there isn't a header line in these 2 file types from ADM ftp
                                        firstLine = false;
                                    }



                                    if (firstLine)
                                    {
                                        //firstLine = false;

                                        if (cSVImportFileType == FTPInputFileTypes.POSITION_FILE_WEDBUSH_OR_RCG)
                                        {
                                            if (stringList.Count > 0)
                                            {
                                                //brokerImportFiles = BrokerImportFiles.BACKUP_SAVED_FILE;

                                                if (stringList[0].CompareTo("R I D") == 0)
                                                {
                                                    cSVImportFileType = FTPInputFileTypes.POSITION_FILE_RCG;
                                                }
                                                else
                                                {
                                                    cSVImportFileType = FTPInputFileTypes.POSITION_FILE_WEDBUSH;
                                                }
                                            }
                                        }

                                        else if (importFileCheck.importingBackedUpSavedFile)
                                        {
                                            brokerImportFiles = BrokerImportFiles.BACKUP_SAVED_FILE;
                                        }
                                        //else if (brokerImportFiles == BrokerImportFiles.ADM_FILES)
                                        else if (cSVImportFileType == FTPInputFileTypes.ADM_WEB_INTERFACE_FILES)
                                        {
                                            int stringListCounter = 0;

                                            while (stringListCounter < stringList.Count)
                                            {
                                                if (stringListCounter >= admSummaryFieldTypeArray.Length
                                                    ||
                                                    (stringListCounter < admSummaryFieldTypeArray.Length &&
                                                     stringList[stringListCounter].CompareTo(
                                                         admSummaryFieldTypeArray.GetValue(stringListCounter)) != 0))
                                                {
                                                    String            caption = "ADM FIELDS HAVE CHANGED, FIELDS DO NOT MATCH PREVIOUS INPUTS";
                                                    String            message = fileNames[fileCounter] + "\nADM FIELDS HAVE CHANGED, THERE IS A PROBLEM \nFILE WILL NOT BE IMPORTED";
                                                    MessageBoxButtons buttons = MessageBoxButtons.OK;
                                                    System.Windows.Forms.DialogResult result;

                                                    // Displays the MessageBox.
                                                    result = MessageBox.Show(message, caption, buttons, MessageBoxIcon.Error);

                                                    importFileCheck.importfile = false;

                                                    break;
                                                }

                                                stringListCounter++;
                                            }
                                        }
                                    }

                                    if (!setFileReader)
                                    {
                                        if ((importFileCheck.importingBackedUpSavedFile ||
                                             cSVImportFileType == FTPInputFileTypes.ADM_WEB_INTERFACE_FILES) &&
                                            importFileCheck.importfile)
                                        {
                                            Import_GMI    = new Fill_GMI_ImportDelegate(GMI_FileRead.FillGMI_ImportFromBackup_Or_ADMWeb);
                                            setFileReader = true;
                                        }
                                        else if (cSVImportFileType == FTPInputFileTypes.POSITION_FILE_WEDBUSH)
                                        {
                                            Import_GMI    = new Fill_GMI_ImportDelegate(GMI_FileRead.FillGMI_Position_Wedbush);
                                            setFileReader = true;
                                        }
                                        else if (cSVImportFileType == FTPInputFileTypes.TRANSACTION_FILE_WEDBUSH)
                                        {
                                            Import_GMI    = new Fill_GMI_ImportDelegate(GMI_FileRead.FillGMI_Transaction_Wedbush);
                                            setFileReader = true;
                                        }
                                        else if (cSVImportFileType == FTPInputFileTypes.POSITION_FILE_RCG)
                                        {
                                            Import_GMI    = new Fill_GMI_ImportDelegate(GMI_FileRead.FillGMI_Position_RCG);
                                            setFileReader = true;
                                        }
                                        else if (cSVImportFileType == FTPInputFileTypes.TRANSACTION_FILE_RCG)
                                        {
                                            Import_GMI    = new Fill_GMI_ImportDelegate(GMI_FileRead.FillGMI_Transaction_RCG);
                                            setFileReader = true;
                                        }
                                        else if (cSVImportFileType == FTPInputFileTypes.POSITION_FILE_ADM)
                                        {
                                            Import_GMI    = new Fill_GMI_ImportDelegate(GMI_FileRead.FillGMI_Position_ADM);
                                            setFileReader = true;
                                        }
                                        else if (cSVImportFileType == FTPInputFileTypes.TRANSACTION_FILE_ADM)
                                        {
                                            Import_GMI    = new Fill_GMI_ImportDelegate(GMI_FileRead.FillGMI_Transaction_ADM);
                                            setFileReader = true;
                                        }
                                    }


                                    if (!firstLine && setFileReader)
                                    {
                                        ADMPositionImportWeb aDMSummaryImport = Import_GMI(stringList);

                                        if (aDMSummaryImport != null)
                                        {
                                            admSummaryFieldsList.Add(aDMSummaryImport);

                                            setupInstrumentAndfillStrikeInDecimal(aDMSummaryImport,
                                                                                  instruments, brokerImportFiles);
                                        }
                                    }

                                    if (firstLine)
                                    {
                                        firstLine = false;
                                    }
                                    //if (stringList.Count > 0
                                    //&& stringList[(int)ADM_DETAIL_FIELDS.PEXCH].Trim().Length > 0
                                    //&& stringList[(int)ADM_DETAIL_FIELDS.PFC].Trim().Length > 0
                                    //&& stringList[(int)ADM_DETAIL_FIELDS.PCTYM].Trim().Length > 0)
                                    //{
                                    //    ADMPositionImportWeb aDMSummaryImport = new ADMPositionImportWeb();

                                    //    admSummaryFieldsList.Add(aDMSummaryImport);

                                    //    //aDMSummaryImport.rowInSummaryFieldList = admSummaryFieldsList.Count - 1;

                                    //    aDMSummaryImport.RecordType = stringList[(int)ADM_DETAIL_FIELDS.RecordType];
                                    //    aDMSummaryImport.POFFIC = stringList[(int)ADM_DETAIL_FIELDS.POFFIC];
                                    //    aDMSummaryImport.PACCT = stringList[(int)ADM_DETAIL_FIELDS.PACCT];
                                    //    aDMSummaryImport.PCUSIP = stringList[(int)ADM_DETAIL_FIELDS.PCUSIP];
                                    //    aDMSummaryImport.PCUSIP2 = stringList[(int)ADM_DETAIL_FIELDS.PCUSIP2];
                                    //    aDMSummaryImport.Description = stringList[(int)ADM_DETAIL_FIELDS.Description];

                                    //    aDMSummaryImport.LongQuantity = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.LongQuantity);
                                    //    aDMSummaryImport.ShortQuantity = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.ShortQuantity);
                                    //    //aDMSummaryImport.Net = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.TradeDate);

                                    //    //aDMSummaryImport.netContractsEditable = aDMSummaryImport.Net;

                                    //    aDMSummaryImport.TradeDate = stringList[(int)ADM_DETAIL_FIELDS.TradeDate];
                                    //    aDMSummaryImport.TradePrice = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.TradePrice);

                                    //    aDMSummaryImport.WeightedPrice = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.WeightedPrice);

                                    //    //aDMSummaryImport.AveragePrice = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.AveragePrice);

                                    //    aDMSummaryImport.RealTimePrice = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.RealTimePrice);
                                    //    aDMSummaryImport.SettledPrice = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.SettledPrice);
                                    //    aDMSummaryImport.PrelimPrice = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.PrelimPrice);
                                    //    aDMSummaryImport.Value = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.Value);
                                    //    aDMSummaryImport.ClosedValue = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.ClosedValue);
                                    //    aDMSummaryImport.SettledValue = getDoubleOutOfStringList(stringList, ADM_DETAIL_FIELDS.SettledValue);

                                    //    aDMSummaryImport.Currency = stringList[(int)ADM_DETAIL_FIELDS.Currency];
                                    //    aDMSummaryImport.PSUBTY = stringList[(int)ADM_DETAIL_FIELDS.PSUBTY];
                                    //    aDMSummaryImport.PEXCH = getIntOutOfStringList(stringList, ADM_DETAIL_FIELDS.PEXCH);
                                    //    aDMSummaryImport.PFC = stringList[(int)ADM_DETAIL_FIELDS.PFC];
                                    //    aDMSummaryImport.aDMStrike = stringList[(int)ADM_DETAIL_FIELDS.Strike];

                                    //    aDMSummaryImport.PCTYM = stringList[(int)ADM_DETAIL_FIELDS.PCTYM];

                                    //    aDMSummaryImport.PCARD = stringList[(int)ADM_DETAIL_FIELDS.PCARD];


                                    //    setupInstrumentAndfillStrikeInDecimal(aDMSummaryImport,
                                    //        instruments, brokerImportFiles);
                                    //}
                                }
                            }

                            streamReader.Close();
                            fileStream.Close();
                        }
                    }
                }
                //                 else
                //                 {
                //                     String caption = "ADM FIELDS HAVE CHANGED, FIELDS DO NOT MATCH PREVIOUS INPUTS";
                //                     String message = fileName + "\nTHERE IS A PROBLEM \nFILE WILL NOT BE IMPORTED";
                //                     MessageBoxButtons buttons = MessageBoxButtons.OK;
                //                     System.Windows.Forms.DialogResult result;
                //
                //                     // Displays the MessageBox.
                //                     result = MessageBox.Show(message, caption, buttons, MessageBoxIcon.Error);
                //                 }
            }
#if DEBUG
            catch (Exception ex)
            {
                TSErrorCatch.errorCatchOut(Convert.ToString(this), ex);
            }
#endif

            if (!importFileCheck.importfile)
            {
                admSummaryFieldsList.Clear();
            }

            //return importFile;
        }