Ejemplo n.º 1
0
        private static void createDefaultConfigurationTxt(string configPath)
        {
            //create the configuration.txt file with default settings
            var sb = new StringBuilder("", 1830);

            sb.Append("#***********************************************************************************\n");
            sb.Append("#***CONFIGURATION FILE**************************************************************\n");
            sb.Append("#***********************************************************************************\n");
            sb.Append("#Lines that start with a pound sign (#) are comments\n");
            sb.Append("#colons (:) separate variable names and values\n");
            sb.Append("#semicolon (;) indicates the end of a line\n");
            sb.Append("#***********************************************************************************\n");
            sb.Append("#Column Header Names are defined with [variable name]:[string name from spreadsheet]\n");
            sb.Append("#Neither the variable names, nor the values are case-sensitive\n");
            sb.Append("#White-spaces are ignored\n");
            sb.Append("#-----------------------------------------------------------------------------------\n");
            sb.Append("reportDate: report_date_as_mm_dd_yyyy;\n");
            sb.Append("markeCode: cftc_contract_market_code;\n");
            sb.Append("openInterest: open_interest_all;\n");
            sb.Append("largeTraderLongPositions: noncomm_positions_long_all;\n");
            sb.Append("largeTraderShortPositions: noncomm_positions_short_all;\n");
            sb.Append("commercialLongPositions: comm_positions_long_all;\n");
            sb.Append("commercialShortPositions: comm_positions_short_all;\n");
            sb.Append("smallSpecLongPositions: nonrept_positions_long_all;\n");
            sb.Append("smallSpecShortPositions: nonrept_positions_short_all;\n");
            sb.Append("#***********************************************************************************\n");
            sb.Append("#STOCK INDEX FUTURE, S&P 500 - INTERNATIONAL MONETARY MARKET\n");
            sb.Append("#or S&P 500 STOCK INDEX - INTERNATIONAL MONETARY MARKET\n");
            sb.Append("#CFTC_Contract_Market_Code\n");
            sb.Append("#-----------------------------------------------------------------------------------\n");
            sb.Append("spMarketCode: 138741;\n");
            sb.Append("#***********************************************************************************\n");
            sb.Append("# Output ticker symbols\n");
            sb.Append("#-----------------------------------------------------------------------------------\n");
            sb.Append("symbolCotCommercials:            ^ COTSPXCOM;\n");
            sb.Append("symbolcotLargeTraders:           ^ COTSPXLG;\n");
            sb.Append("symbolcotSmallSpeculators:       ^ COTSPXSM;\n");
            sb.Append("symbolcotSpread:                 ^ COTSPXSpread;\n");
            sb.Append("#***********************************************************************************\n");
            sb.Append("#Output files Metastock headers\n");
            sb.Append("#-----------------------------------------------------------------------------------\n");
            sb.Append("metastockHeaders:          <NAME>,<TICKER>,<PER>,<DTYYYYMMDD>,<TIME>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>\n");
            try
            {
                File.WriteAllText(configPath, sb.ToString());
            }
            catch (UnauthorizedAccessException)
            {
                ErrorHelpers.immediateEx("ERROR. Cannot create configuration file due to insufficient permissions.");
            }
            catch (IOException)
            {
                ErrorHelpers.immediateEx("ERROR. Cannot create configuration file due to an unexpected error.");
            }
            catch (Exception)
            {
                ErrorHelpers.immediateEx("ERROR. Cannot create configuration file due to an unknown error.");
            }
        }
Ejemplo n.º 2
0
        public static DataTable convertXLSToDataTable(string sourceFilePath)
        {
            string strConn = String.Concat(_oleDbConnectionString.Replace("$FILEPATH$", sourceFilePath));

            using (var conn = new OleDbConnection(strConn))
            {
                try
                {
                    conn.Open();

                    string sheetName = findFirstSheetName(sourceFilePath);
                    using (var cmd = new OleDbCommand(String.Concat("SELECT * FROM [", sheetName, "]"), conn))
                    {
                        //select the data from the spreadsheet and convert it to a DataTable
                        cmd.CommandType = CommandType.Text;
                        using (var da = new OleDbDataAdapter(cmd))
                        {
                            using (var dt = new DataTable())
                            {
                                try
                                {
                                    da.Fill(dt);
                                    return(dt);
                                }
                                catch (Exception)
                                {
                                    ErrorHelpers.immediateEx(String.Format("ERROR. Could not find data in a worksheet named {0}.\nPlease select a different file.", sheetName));
                                }
                            }
                        }
                    }
                }
                catch {
                    ErrorHelpers.immediateEx(_alreadyOpenError);
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
 public static string getConfigVal(string keyName)
 {
     if (_htConfig == null)
     {
         loadConfigFile();
     }
     if (_htConfig.ContainsKey(keyName))
     {
         //only stock symbol values are returned in uppercase
         if (keyName.StartsWith("symbol"))
         {
             return(_htConfig[keyName].ToString().ToUpper());
         }
         else
         {
             return(_htConfig[keyName].ToString().ToLower());
         }
     }
     else
     {
         ErrorHelpers.immediateEx((String.Format("ERROR. Could not find the configuration value for {0}.", keyName)));
     }
     return("");
 }