beginnings of span, should't be long
This commit is contained in:
1 parent
e452413b92
commit
159e8fba23
9 files changed
+236
-94
No files matched your search
@@ -0,0 +1,105 @@
|
||||
#include "MarginServiceServer.h"
|
||||
#include "Position.h"
|
||||
|
||||
#include "lib/persistence/SqliteStore.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/utils/bts_assert.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/api/service_helpers/AdminServiceUtils.h"
|
||||
#include "lib/orderman/orderman_utils/orderman_utils.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
#include "lib/utils/AuthToken.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
|
||||
#include <boost/container/flat_map.hpp>
|
||||
#include <boost/tokenizer.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
|
||||
using namespace bts::api::orderman;
|
||||
using namespace bts::api::position;
|
||||
using namespace std;
|
||||
|
||||
namespace bts {
|
||||
namespace position {
|
||||
|
||||
MarginServiceServer::MarginServiceServer(bts::api::ServiceContext& context, md::MDClient& mdclient)
|
||||
: bts::api::position::MarginServiceBase (context),
|
||||
_publisher(make_margin_data_stateful_publisher()),
|
||||
_position_service(context.locate<bts::api::position::PositionService>()),
|
||||
_position_map(),
|
||||
_oracle(mdclient)
|
||||
{
|
||||
LOG(Gen, Info, "MarginServiceServer: service started");
|
||||
|
||||
_position_service.subscribe_position_data() |
|
||||
rxcpp::operators::subscribe<api::position::Position_dataUpdate>(
|
||||
[this](auto const& update)
|
||||
{
|
||||
for (const auto& o : update.removed())
|
||||
{
|
||||
const auto& it = _position_map.find(o->record_id());
|
||||
if(it != _position_map.end())
|
||||
_position_map.erase(it);
|
||||
}
|
||||
for (const auto& ch : update.changed())
|
||||
{
|
||||
const auto& o = ch.current();
|
||||
_position_map[o->record_id()] = *o;
|
||||
}
|
||||
for (const auto& o : update.added())
|
||||
{
|
||||
_position_map[o->record_id()] = *o;
|
||||
}
|
||||
});
|
||||
|
||||
auto& disp = utils::Dispatcher::get_named("MarginServiceServer");
|
||||
utils::DispatcherTimer web_api_timer(disp, 250, [&]()
|
||||
{
|
||||
for (auto& p: platforms)
|
||||
p->send_heartbeats();
|
||||
});
|
||||
web_api_timer.start();
|
||||
|
||||
disp.run();
|
||||
}
|
||||
|
||||
MarginServiceServer::~MarginServiceServer() {}
|
||||
|
||||
void MarginServiceServer::query_accounts_and_positions(std::map<AccountName>, std::vector<Position>& result)
|
||||
|
||||
void MarginServiceServer::query_all_positions(const orderman::AccountName& account, std::vector<Position>& result)
|
||||
{
|
||||
result.reserve(_position_map.size());
|
||||
for(auto& entry : _position_map)
|
||||
{
|
||||
if(entry.second.account() != account)
|
||||
continue;
|
||||
const PositionUnit& unit = entry.second;
|
||||
auto sec = _oracle.get_security(unit.security_id());
|
||||
if(sec && sec->has_glbx())
|
||||
{
|
||||
Position pos;
|
||||
pos.account = unit.account();
|
||||
pos.security_desc = securities::descriptor(*sec);
|
||||
int32_t pos = unit.sod_long_pos() + unit.day_long_pos() - unit.sod_short_pos() - unit.day_short_pos();
|
||||
pos.position = Quantity(abs(pos));
|
||||
pos.side = (pos < 0.0 ? api::SIDE_SELL : api::SIDE_BUY);
|
||||
result.push_back(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MarginServiceServer::_publish_margin()
|
||||
{
|
||||
// // TODO, need to delete all state
|
||||
// std::vector<MDEntitlementReportUnit> entitlements;
|
||||
// AdminServiceUtils::get_md_entitlement_report(_state,entitlements);
|
||||
// for (const auto& e : entitlements)
|
||||
// _md_entit_publisher.add_or_update(e);
|
||||
// _md_entit_publisher.flush();
|
||||
}
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user