76 lines
1.9 KiB
C++
76 lines
1.9 KiB
C++
#include "Span.h"
|
|
|
|
#include "server/sparkd/position/PositionAggregator.h"
|
|
#include "server/sparkd/position/MarginServiceCore.h"
|
|
#include "server/sparkd/position/Position.h"
|
|
|
|
#include "lib/orderman/orderman_utils/orderman_common.h"
|
|
|
|
#include "lib/config/config.h"
|
|
#include "lib/api/public/ServiceContext.h"
|
|
#include "lib/api/services/AuthService.client.pb.h"
|
|
#include "lib/domain_model/Security.pb.h"
|
|
#include "lib/utils/helper_macros.h"
|
|
#include "lib/utils/Dispatcher.h"
|
|
|
|
#include <google/protobuf/text_format.h>
|
|
#include <future>
|
|
#include <memory>
|
|
#include <stdlib.h>
|
|
#include <condition_variable>
|
|
#include <mutex>
|
|
#include <time.h>
|
|
|
|
using namespace bts::position;
|
|
using namespace bts::api::position;
|
|
|
|
namespace bts {
|
|
namespace cmd {
|
|
|
|
int Span::execute(const std::vector<std::string>&)
|
|
{
|
|
srand (time(NULL));
|
|
std::condition_variable cv;
|
|
std::mutex cv_m;
|
|
std::unique_lock<std::mutex> lk(cv_m);
|
|
|
|
auto& disp = utils::Dispatcher::create_new("SPAN");
|
|
MarginServiceCore core(disp);
|
|
|
|
auto name = orderman::to<orderman::AccountName>("ACC A");
|
|
AccountInfo acct(name);
|
|
Position p;
|
|
p.security_desc = "ESU9";
|
|
p.account = name;
|
|
p.position = Quantity(rand() % 100);
|
|
p.side = api::SIDE_BUY;
|
|
std::vector<Position> pos;
|
|
pos.push_back(p);
|
|
p.position = Quantity(rand() % 200);
|
|
p.side = api::SIDE_SELL;
|
|
pos.push_back(p);
|
|
|
|
//core.set_verbose_debugging(true);
|
|
core.compute_margin(acct, pos, [&cv](const api::position::MarginResult& m)
|
|
{
|
|
std::string str;
|
|
google::protobuf::TextFormat::PrintToString(m, &str);
|
|
|
|
std::cout << std::endl << str << std::endl << std::endl;
|
|
cv.notify_all();
|
|
});
|
|
|
|
std::cout << "Waiting for margin results, press any key to exit" << std::endl;
|
|
cv.wait(lk);
|
|
return 0;
|
|
}
|
|
|
|
std::string Span::help()
|
|
{
|
|
return "\t test CME CORE Span integration \n";
|
|
}
|
|
|
|
}}
|
|
|
|
|