#include #include #include #include "../../shared/GlobalConfigFile.h" #include "../../shared/MiscSupport.h" #include "ReadFromSpryWare.h" #include "ReadFromDatabase.h" #include "SymbolList.h" // Since we are only reading from the database, not writing to it, we use the live database. // ./get_symbol_list -i database_RO=wally-balls -i database_RW=wally-balls | tee /tmp/get_symbol_list.txt int main(int argc, char *argv[]) { if (argc == 1) { // Nothing on the command line. We could use all defaults, but it seems // to make more sense to display help here. std::cout<<"Create symbols lists from Spryware\n" <<"Use the -i / -f syntax to specify values.\n" <<"* hash_count - Use divide the market into this many sections.\n" <<" default = 1\n" <<"* hash_first - Which section to send to the files.\n" <<" 0 is first, hash_count-1 is last.\n" <<" default = 0\n" <<"* hash_last - The last section to send to the files.\n" <<" default = hash_first, i.e. 1 section.\n" <<"* output_files - A comma seperated list of files to recieve the symbols.\n" <<" default = symbols.txt\n" <<"* max_count - The maximum number of symbols to send to all the files.\n" <<" default = no limit\n" <<"Hash codes are somewhat random, and are ideal for spreading out stocks\n" <<"between various machines without them communicating with each other.\n" <<"Listing multiple files for output_files will try to distribute the symbols\n" <<"so each server will get the same amount of activity. This is the ideal\n" <<"way to break up the work between multiple processes on the same server.\n"; exit(1); } if (!addConfigItemsFromCommandLine(argv + 1)) return 1; configItemsComplete(); // Skip Canada, since we know that Active currently doesn't do Canada. std::vector< std::string > databaseExchanges; databaseExchanges.push_back("NYSE"); databaseExchanges.push_back("AMEX"); databaseExchanges.push_back("OTC"); databaseExchanges.push_back("PINK"); databaseExchanges.push_back("NASD"); SymbolList symbols; symbols.setHashCount(strtolDefault(getConfigItem("hash_count"), 1)); const int hashFirst = strtolDefault(getConfigItem("hash_first"), 0); const int hashLast = strtolDefault(getConfigItem("hash_last"), hashFirst); symbols.setHashPartitions(hashFirst, hashLast); StockInfoList recentItems; readFromSpryWare(std::vector< std::string >(), recentItems); symbols.add(recentItems); //readFromDatabase(databaseExchanges, recentItems); //symbols.addIfNew(recentItems, "database"); //readFromTextFile("IndexList.txt", recentItems); //symbols.add(recentItems); const int maxCount = strtolDefault(getConfigItem("max_count"), 0); const std::string outputFilesString = getConfigItem("output_files", "symbols.txt"); const std::vector< std::string > outputFilesVector = explode(",", outputFilesString); std::vector< std::fstream * > outputFiles; for (std::vector< std::string >::const_iterator it = outputFilesVector.begin(); it != outputFilesVector.end(); it++) { outputFiles.push_back(new std::fstream(it->c_str(), std::ios_base::out | std::ios_base::trunc)); if ((*outputFiles.rbegin())->fail()) { std::cerr<<"Error in output file “"<<*it<<"”\n"; exit(1); } } SymbolList::Result result; if (maxCount > 0) result = symbols.getValues(maxCount); else result = symbols.getValues(); std::vector< std::fstream * >::const_iterator fileIt = outputFiles.begin(); for (SymbolList::Result::const_iterator it = result.begin(); it != result.end(); it++) { if (fileIt == outputFiles.end()) fileIt = outputFiles.begin(); (**fileIt)<<*it<<'\n'; fileIt++; } for (fileIt = outputFiles.begin(); fileIt != outputFiles.end(); fileIt++) delete *fileIt; }