-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
63 lines (51 loc) · 1.89 KB
/
main.cpp
File metadata and controls
63 lines (51 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <memory>
#include <boost/program_options.hpp>
#include <boost/exception/exception.hpp>
#include "plog/Log.h"
#include "plog/Initializers/RollingFileInitializer.h"
#include "Utils.h"
#include "Config.h"
#include "Factory.h"
#include "MarketDataInterface.h"
#include "OrderInterface.h"
int main(int argc, char* argv [])
{
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help", "print usage message")
("config", boost::program_options::value<std::string>(), "config file");
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(argc,
argv, desc), vm);
boost::program_options::notify(vm);
if (!vm.contains("config"))
{
LOGDEBUG("Config file not provided");
BOOST_THROW_EXCEPTION(std::out_of_range("No config file provided"));
return 1;
}
std::shared_ptr<Config> config = std::make_shared<Config>
(vm.at("config").as<std::string>());
if (!config->configParamExists("log_directory"))
{
LOGDEBUG("Please specifiy log_directory in config.json");
BOOST_THROW_EXCEPTION(std::out_of_range("No log_directory provided in config"));
}
std::string logDirectory = config->get("log_directory");
plog::init(plog::debug, logDirectory.c_str());
signal(SIGHUP, handle_sighup);
auto factory = std::make_unique<Factory<MarketDataInterface, OrderInterface>>(config);
PLOG_DEBUG << "Initializing strategy " << config->get("name");
factory->initStrategy();
auto strategy = factory->getStrategy();
while (strategy->shouldEvaluate())
{
if (sig_caught) {
PLOG_DEBUG << "Received SIGHUP signal - Exiting!";
return sig_caught;
}
strategy->evaluate();
}
return 0;
}