int main( int argc, char** argv ) { if ( argc != 2 ) { std::cout << "usage: " << argv[ 0 ] << " FILE." << std::endl; return 0; } std::string file = argv[ 1 ]; try { FIX::SessionSettings settings( file ); Application application; FIX::FileStoreFactory storeFactory( settings ); FIX::ScreenLogFactory logFactory( settings ); FIX::ThreadedSocketAcceptor acceptor( application, storeFactory, settings, logFactory ); acceptor.start(); wait(); acceptor.stop(); return 0; } catch ( std::exception & e ) { std::cout << e.what() << std::endl; return 1; } }
int main( int argc, char** argv ) { if ( argc != 2 ) { std::cout << "usage: " << argv[ 0 ] << " FILE." << std::endl; return 0; } std::string file = argv[ 1 ]; try { FIX::SessionSettings settings( file ); Application application; FIX::FileStoreFactory storeFactory( settings ); FIX::FileLogFactory logFactory( settings ); FIX::SocketAcceptor acceptor( application, storeFactory, settings, logFactory ); acceptor.start(); //wait(); while(true){ FIX::process_sleep(5); application.sendXMessages(); } acceptor.stop(); return 0; } catch ( std::exception & e ) { std::cout << e.what() << std::endl; return 1; } }
int main( int argc, char** argv ) { if ( argc != 2 ) { std::cout << "usage: " << argv[ 0 ] << " FILE." << std::endl; return 0; } std::string file = argv[ 1 ]; try { FIX::SessionSettings settings( file ); MDApplication application; FIX::FileStoreFactory storeFactory( settings ); FIX::FileLogFactory logFactory(settings); FIX::SocketInitiator initiator( application, storeFactory, settings, logFactory ); initiator.start(); application.run(); initiator.stop(); return 0; } catch ( std::exception & e ) { std::cout << e.what(); return 1; } }
int main( int argc, char** argv ) { if ( argc < 2 ) { std::cout << "usage: " << argv[ 0 ] << " FILE." << std::endl; return 0; } std::string file = argv[ 1 ]; #ifdef HAVE_SSL std::string isSSL; if (argc > 2) { isSSL.assign(argv[2]); } #endif FIX::Acceptor * acceptor = 0; try { FIX::SessionSettings settings( file ); Application application; FIX::FileStoreFactory storeFactory( settings ); FIX::ScreenLogFactory logFactory( settings ); #ifdef HAVE_SSL if (isSSL.compare("SSL") == 0) acceptor = new FIX::ThreadedSSLSocketAcceptor ( application, storeFactory, settings, logFactory ); else if (isSSL.compare("SSL-ST") == 0) acceptor = new FIX::SSLSocketAcceptor ( application, storeFactory, settings, logFactory ); else #endif acceptor = new FIX::SocketAcceptor ( application, storeFactory, settings, logFactory ); acceptor->start(); wait(); acceptor->stop(); delete acceptor; return 0; } catch ( std::exception & e ) { std::cout << e.what() << std::endl; delete acceptor; return 1; } }
int testSendOnSocket( int count, short port ) { std::stringstream stream; stream << "[DEFAULT]" << std::endl << "SocketConnectHost=localhost" << std::endl << "SocketConnectPort=" << (unsigned short)port << std::endl << "SocketAcceptPort=" << (unsigned short)port << std::endl << "SocketReuseAddress=Y" << std::endl << "StartTime=00:00:00" << std::endl << "EndTime=00:00:00" << std::endl << "UseDataDictionary=N" << std::endl << "BeginString=FIX.4.2" << std::endl << "PersistMessages=N" << std::endl << "[SESSION]" << std::endl << "ConnectionType=acceptor" << std::endl << "SenderCompID=SERVER" << std::endl << "TargetCompID=CLIENT" << std::endl << "[SESSION]" << std::endl << "ConnectionType=initiator" << std::endl << "SenderCompID=CLIENT" << std::endl << "TargetCompID=SERVER" << std::endl << "HeartBtInt=30" << std::endl; FIX::ClOrdID clOrdID( "ORDERID" ); FIX::HandlInst handlInst( '1' ); FIX::Symbol symbol( "LNUX" ); FIX::Side side( FIX::Side_BUY ); FIX::TransactTime transactTime; FIX::OrdType ordType( FIX::OrdType_MARKET ); FIX42::NewOrderSingle message( clOrdID, handlInst, symbol, side, transactTime, ordType ); FIX::SessionID sessionID( "FIX.4.2", "CLIENT", "SERVER" ); TestApplication application; FIX::MemoryStoreFactory factory; FIX::SessionSettings settings( stream ); FIX::ScreenLogFactory logFactory( settings ); FIX::SocketAcceptor acceptor( application, factory, settings ); acceptor.start(); FIX::SocketInitiator initiator( application, factory, settings ); initiator.start(); FIX::process_sleep( 1 ); int start = GetTickCount(); for ( int i = 0; i <= count; ++i ) FIX::Session::sendToTarget( message, sessionID ); while( application.getCount() < count ) FIX::process_sleep( 0.1 ); int ticks = GetTickCount() - start; initiator.stop(); acceptor.stop(); return ticks; }
/** * Entry point */ int main(int argc, char** argv ) { // TODO ([email protected]) put init settings in ctor ApplicationConfig config; config.print_debug = false; config.is_logging = true; SetSignalHandlers(); #ifdef LOG logging_init(createTimestampedLogFilename(PANTHEIOS_FE_PROCESS_IDENTITY).c_str()); #endif if (capk::InitializeZMQPublisher(&g_zmq_context, &g_pub_socket) != 0) { #ifdef LOG pan::log_CRITICAL("Can't init ZMQ - exiting"); #endif return (-1); } // Must call this to use protobufs GOOGLE_PROTOBUF_VERIFY_VERSION; // First read command line if (ReadCommandLineParams(argc, argv, &config) != 0) { #ifdef LOG pan::log_CRITICAL("Aborting due to missing parameters."); #endif return (-1); } // Read the symbols to subscribe to from file std::vector<std::string> symbols = capk::readSymbolsFile(config.symbol_file_name); if (symbols.size() <= 0) { #ifdef LOG pan::log_CRITICAL("No symbols set in:", config.symbol_file_name.c_str()); #endif return (-1); } try { FIX::SessionSettings settings(config.config_file_name); std::set<FIX::SessionID> sessions = settings.getSessions(); assert(sessions.size() == 1); FIX::SessionID sessionId = *(sessions.begin()); const FIX::Dictionary& dict = settings.get(sessionId); // Get additional config settings from FIX config file if (ReadFIXConfig(&config, dict) != 0) { fprintf(stderr, "Can't read local config file - exiting\n"); return (-1); } if (config.venue_config_file_name == "") { // Get config settings from config server if (ReadRemoteConfig(&config) != 0) { fprintf(stderr, "Can't read remote configuration - exiting\n"); return (-1); } } else { // Get config settings from local ini file if (ReadLocalVenueConfig(config.venue_config_file_name, &config) != 0) { fprintf(stderr, "Can't read local venue configuration - exiting\n"); return (-1); } } PrintConfig(&config); // Create the FIX application instance Application application(config); g_papplication = &application; application.addSymbols(symbols); // Create the output directories for orderbooks, log, and store if needed. // Note that actual log directories are created in the location specified // with -o arg each time the program starts // @TODO ([email protected]) Maybe better to put // each log in the dated directory rather than have store and // log on same level as dated tick dirs if (config.root_output_dir.length() > 0) { fs::path argPath = fs::path(config.root_output_dir); if (!fs::exists(argPath)) { fs::create_directories(argPath); } fs::path fix_log_path = argPath / fs::path("log"); if (!fs::exists(fix_log_path)) { fs::create_directory(fix_log_path); } config.fix_log_output_dir = fix_log_path.string(); fs::path store_path = argPath / fs::path("store"); if (!fs::exists(store_path)) { fs::create_directory(store_path); } config.fix_store_output_dir = store_path.string(); } pid_t pid = getpid(); pid_t ppid = getppid(); #ifdef LOG pan::log_DEBUG("pid: ", pan::integer(pid), " ppid: ", pan::integer(ppid)); #endif if (WritePidFile(argv[0], config.mic_string.c_str(), pid, ppid) != 0) { #ifdef LOG pan::log_CRITICAL("Can't write pid file - exiting"); #endif return (-1); } // Set ZMQ parameters in Application if (config.is_publishing) { zmq_bind(g_pub_socket, config.publishing_addr.c_str()); application.setZMQContext(g_zmq_context); application.setZMQSocket(g_pub_socket); } if (config.is_logging) { std::cout << "Logging with FileStoreFactory" << std::endl; FIX::FileStoreFactory fileStoreFactory(config.fix_store_output_dir); FIX::FileLogFactory logFactory(config.fix_log_output_dir); g_pinitiator = new FIX::SocketInitiator(application, fileStoreFactory, settings, logFactory); assert(g_pinitiator); } else { std::cout << "Logging with NullStoreFactory" << std::endl; FIX::NullStoreFactory nullStoreFactory; g_pinitiator = new FIX::SocketInitiator(application, nullStoreFactory, settings); assert(g_pinitiator); } std::cout << "Starting initiator" << std::endl; g_pinitiator->start(); char x; std::cout << "Type 'q' to disconnect and exit" << std::endl; while (std::cin >> x) { if (x == 'q') { break; } } std::cout << "Cleaning up" << std::endl; g_pinitiator->stop(); return 0; } catch(FIX::Exception& e) { std::cerr << e.what(); return 1; } }
int main( int argc, char** argv ) { int err = 0; std::string argOutputDir; std::string symbolFile; std::string configFile; std::string password; bool printDebug; (void) signal(SIGINT, sighandler); (void) signal(SIGTERM, sighandler); (void) signal(SIGHUP, sighandler); try { po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("s", po::value<std::string>(), "<symbol file>") ("c", po::value<std::string>(), "<config file>") ("d", "debug info") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("help")) { std::cout << desc << "\n"; return 1; } if (vm.count("s")) { std::cout << "Symbol file: " << vm["s"].as<std::string>() << "\n"; symbolFile = vm["s"].as<std::string>(); } else { // use default name for symbols file name symbolFile = "symbols.cfg"; std::cout << "Using default symbols file: symbols.cfg\n"; } if (vm.count("c")) { std::cout << "Config file: " << vm["c"].as<std::string>() << ".\n"; configFile = vm["c"].as<std::string>(); } else { std::cout << "Config file was not set.\n"; err++; } printDebug = vm.count("d") > 0; } catch(std::exception& e) { std::cerr << "EXCEPTION:" << e.what(); return 1; } if (err > 0) { std::cout << "Usage: validate_symbols --c <config_file> --s <symbol_file> \n"; std::cout << "Will save files to MIC.validated-symbols"; return 1; } /* * @see http://www.boost.org/doc/libs/1_41_0/doc/html/program_options.html */ std::vector<std::string> symbols = readSymbols(symbolFile); try { FIX::SessionSettings settings(configFile); std::set<FIX::SessionID> sessions = settings.getSessions (); assert(sessions.size() == 1); FIX::SessionID sessionId = *(sessions.begin()); const FIX::Dictionary& dict = settings.get(sessionId); ApplicationConfig config; // MIC code for adding to output filename config.mic_code = dict.has("MIC") ? dict.getString("MIC") : ""; // Username and password settings config.username = dict.has("Username") ? dict.getString("Username") : ""; config.password = dict.has("Password") ? dict.getString("Password") : ""; config.sendPasswordInRawDataField = dict.has("SendPasswordInRawData") && dict.getBool("SendPasswordInRawData"); // Fix Version string config.version = dict.has("FIXVersion") ? (FIXVersion)atoi(dict.getString("FIXVersion").c_str()) : FIX_42; std::cout << "Using FIX version: " << config.version << std::endl; // Reset sequence numbers? bool bReset = dict.has("ResetSeqNo") ? dict.getBool("ResetSeqNo") : false; std::cout << "Resetting sequence numbers: " << bReset << std::endl; // Debug settings config.printDebug = printDebug; Application application(bReset, config); papplication = &application; application.addSymbols(symbols); // if user specified an output dir, then put files into date-sorted // subdirectories, otherwise put into the default dirs specified in // config file std::string orderBooksOutputDir = "."; std::string logOutputDir = dict.has("FileLogPath") ? dict.getString("FileLogPath") : "."; std::string storeOutputDir = dict.has("FileStorePath") ? dict.getString("FileStorePath") : "."; if (argOutputDir.length() > 0) { orderBooksOutputDir = argOutputDir; fs::path argPath = fs::path(argOutputDir); if (!fs::exists(argPath)) { fs::create_directories(argPath); } /* put both order books and message logs in subdirs, but put the store at the root dir */ fs::path logOutputPath = argPath / fs::path("log"); if (!fs::exists(logOutputPath)) { fs::create_directory(logOutputPath); } logOutputDir = logOutputPath.string(); fs::path storeOutputPath = argPath / fs::path("store"); if (!fs::exists(storeOutputPath)) { fs::create_directory(storeOutputPath); } storeOutputDir = storeOutputPath.string(); } FIX::FileStoreFactory storeFactory(storeOutputDir); FIX::FileLogFactory logFactory(logOutputDir); FIX::SocketInitiator initiator(application, storeFactory, settings, logFactory); pinitiator = &initiator; std::cout << "Starting initiator" << std::endl; initiator.start(); //application.run(); char x; while(std::cin >> x) { std::cout << " Press 'q' to quit" << std::endl; if (x == 'q') { break; } } std::cout << "Stopping initiator..." << std::endl; initiator.stop(); return 0; } catch ( FIX::Exception & e ) { std::cout << e.what(); return 1; } }
int main( int argc, char** argv ) { int err = 0; std::string argOutputDir; std::string symbolFile; std::string configFile; std::string password; bool printDebug; bool isLogging; int zero = 0; (void) signal(SIGINT, sighandler); (void) signal(SIGTERM, sighandler); (void) signal(SIGHUP, sighandler); g_zmq_context = zmq_init(1); assert(g_zmq_context); pub_socket = zmq_socket(g_zmq_context, ZMQ_PUB); zmq_setsockopt(pub_socket, ZMQ_LINGER, &zero, sizeof(zero)); assert(pub_socket); GOOGLE_PROTOBUF_VERIFY_VERSION; try { po::options_description desc("Allowed options"); desc.add_options() ("help", "produce help message") ("c", po::value<std::string>(), "<config file>") ("s", po::value<std::string>(), "<symbol file>") ("o", po::value<std::string>(), "<output path>") ("nolog", po::value<int>()->implicit_value(0), "disable logging (FIX and tick)") ("d", "debug info") ; po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); if (vm.count("nolog")) { std::cout << "Logging disabled" << std::endl; //isLogging = (vm["nolog"].as<int>() == 1 ? false : true); isLogging = false; } else { std::cout << "Logging enabled" << std::endl; isLogging = true; } if (vm.count("help")) { std::cout << desc << "\n"; return 1; } if (vm.count("o")) { std::cout << "Output path: " << vm["o"].as<std::string>() << "\n"; argOutputDir = vm["o"].as<std::string>(); } else { // set default std::cout << "Output path file was not set \n"; } if (vm.count("s")) { std::cout << "Symbol file: " << vm["s"].as<std::string>() << "\n"; symbolFile = vm["s"].as<std::string>(); } else { // use default name for symbols file name symbolFile = "symbols.cfg"; std::cout << "Using default symbols file: symbols.cfg\n"; } if (vm.count("c")) { std::cout << "Config file: " << vm["c"].as<std::string>() << ".\n"; configFile = vm["c"].as<std::string>(); } else { std::cout << "Config file was not set.\n"; err++; } printDebug = vm.count("d") > 0; /* moved passwords to cfg files if (vm.count("p")) { std::cout << "Pass: "******"p"].as<std::string>() << ".\n"; password = vm["p"].as<std::string>(); } else { std::cout << "Password was not set.\n"; err++; } */ } catch(std::exception& e) { std::cerr << "EXCEPTION:" << e.what(); return 1; } if (err > 0) { std::cout << "Aborting due to missing parameters.\n"; return 1; } /* * @see http://www.boost.org/doc/libs/1_41_0/doc/html/program_options.html */ std::vector<std::string> symbols = readSymbols(symbolFile); try { FIX::SessionSettings settings(configFile); std::set<FIX::SessionID> sessions = settings.getSessions (); assert(sessions.size() == 1); FIX::SessionID sessionId = *(sessions.begin()); const FIX::Dictionary& dict = settings.get(sessionId); ApplicationConfig config; // MIC code for adding to output filename config.mic_string = dict.has("MIC") ? dict.getString("MIC") : ""; std::cout << "My MIC is: " << config.mic_string << std::endl; capk::get_config_params(g_zmq_context, "tcp://127.0.0.1:11111", &all_venue_config); capkproto::venue_configuration my_config = capk::get_venue_config(&all_venue_config, config.mic_string.c_str()); std::cout << "Received config:\n" << my_config.DebugString() << std::endl; // venue id as for protobuf usage to identify venue if (my_config.venue_id() == "") { std::cerr << "venue_id not set!" << std::endl; exit(-1); } else { // boost version of atoi if (qi::parse(my_config.venue_id().begin(), my_config.venue_id().end(), qi::int_, config.venue_id) == false) { std::cout << "Can't parse venue_id" << std::endl; exit(-1); } if (config.venue_id == 0) { std::cerr << "venue_id can not be 0" << std::endl; exit(-1); } std::cout << "Set venue_id to: " << config.venue_id << std::endl; } // Username and password settings config.username = dict.has("Username") ? dict.getString("Username") : ""; config.password = dict.has("Password") ? dict.getString("Password") : ""; config.sendPasswordInRawDataField = dict.has("SendPasswordInRawData") && dict.getBool("SendPasswordInRawData"); // Should use aggregated book? config.aggregatedBook = dict.has("AggregatedBook") && dict.getBool("AggregatedBook"); std::cout << "Aggregated book: " << config.aggregatedBook << std::endl; // Should we reset sequence numbers? bool bReset = dict.has("ResetSeqNo") && dict.getBool("ResetSeqNo"); std::cout << "Resetting sequence numbers: " << bReset << std::endl; // How to send market data requests - bulk or multiple messages config.sendIndividualMarketDataRequests = dict.has("SendIndividualMarketDataRequests") && dict.getBool("SendIndividualMarketDataRequests"); std::cout << "Send individual market data requests: " << config.sendIndividualMarketDataRequests << std::endl; // Fix Version string config.version = dict.has("FIXVersion") ? (FIXVersion)atoi(dict.getString("FIXVersion").c_str()) : FIX_42; std::cout << "Using FIX version: " << config.version << std::endl; // Market depth std::string depth = dict.has("MarketDepth") ? dict.getString("MarketDepth") : ""; config.marketDepth = atoi(depth.c_str()); std::cout << "Setting market depth: " << config.marketDepth << std::endl; // Update Type long updateType = dict.has("MDUpdateType") ? dict.getLong("MDUpdateType") : -1; std::cout << "Setting update type: " << updateType << std::endl; // Debug settings config.printDebug = printDebug; Application application(bReset, config); papplication = &application; application.addSymbols(symbols); // if user specified an output dir, then put files into date-sorted // subdirectories, otherwise put into the default dirs specified in // config file std::string orderBooksOutputDir = "."; std::string logOutputDir = dict.has("FileLogPath") ? dict.getString("FileLogPath") : "."; std::string storeOutputDir = dict.has("FileStorePath") ? dict.getString("FileStorePath") : "."; if (argOutputDir.length() > 0) { orderBooksOutputDir = argOutputDir; fs::path argPath = fs::path(argOutputDir); if (!fs::exists(argPath)) { fs::create_directories(argPath); } /* put both order books and message logs in subdirs, but put the store at the root dir */ fs::path logOutputPath = argPath / fs::path("log"); if (!fs::exists(logOutputPath)) { fs::create_directory(logOutputPath); } logOutputDir = logOutputPath.string(); fs::path storeOutputPath = argPath / fs::path("store"); if (!fs::exists(storeOutputPath)) { fs::create_directory(storeOutputPath); } storeOutputDir = storeOutputPath.string(); } pid_t pid = getpid(); pid_t ppid = getppid(); printf("pid: %d, ppid: %d\n", pid, ppid); std::string pidFileName = std::string(argv[0]) + "." + config.mic_string + std::string(".pid"); std::ofstream pidFile(pidFileName); if (pidFile.is_open()) { pidFile << pid; pidFile.flush(); } else { std::cerr << "Can't write pid file - exiting"; exit(-1); } // Get the bind address for zmq sockets bool isPublishing = dict.has("should_publish_prices") && dict.getBool("should_publish_prices"); if (isPublishing) { std::cout << "Collector is publishing prices to: " << my_config.market_data_broadcast_addr() << std::endl; } else { std::cout << "Collector is NOT publishing prices" << std::endl; } // ZMQ initialization if (isPublishing) { zmq_bind(pub_socket, my_config.market_data_broadcast_addr().c_str()); application.setZMQContext(g_zmq_context); application.setZMQSocket(pub_socket); } application.setPublishing(isPublishing); application.setLogging(isLogging); // Set MDUpdateType application.setUpdateType(updateType); // orderbook output setup application.setDataPath(orderBooksOutputDir); // fix logging params if (isLogging) { std::cout << "Logging with FileStoreFactory" << std::endl; FIX::FileStoreFactory fileStoreFactory(storeOutputDir); FIX::FileLogFactory logFactory(logOutputDir); pinitiator = new FIX::SocketInitiator(application, fileStoreFactory, settings, logFactory); } else { std::cout << "Logging with NullStoreFactory" << std::endl; FIX::NullStoreFactory nullStoreFactory; pinitiator = new FIX::SocketInitiator(application, nullStoreFactory, settings); } //pinitiator = &initiator; std::cout << "Starting initiator" << std::endl; pinitiator->start(); char x; while(std::cin >> x) { if (x == 'q') { break; } } std::cout << "Stopping initiator..." << std::endl; pinitiator->stop(); return 0; } catch ( FIX::Exception & e ) { std::cout << e.what(); return 1; } }