75 lines
2.6 KiB
C++
75 lines
2.6 KiB
C++
#include "MarketDataAuxiliaryServiceServer.h"
|
|
#include "lib/api/services/MarketDataRelay.pb.h"
|
|
#include "lib/api/services/MarketDataRelay.client.pb.h"
|
|
#include "lib/api/public/ServiceContext.h"
|
|
#include "lib/logging/logging.h"
|
|
#include "lib/utils/PBUtils.h"
|
|
#include "lib/utils/Dispatcher.h"
|
|
#include "lib/md/get_symbols.h"
|
|
#include "VolumeAtPriceState.h"
|
|
#include "lib/utils/bts_chrono.h"
|
|
|
|
namespace bts{
|
|
namespace md{
|
|
namespace auxiliary{
|
|
|
|
using namespace bts::co2;
|
|
using namespace bts::api::md::auxiliary;
|
|
|
|
struct MarketDataAuxiliaryServiceServer::PImpl{
|
|
MarketDataRelay relay_service;
|
|
MarketDataAuxiliaryServiceBase::Volume_at_priceStatefulPublisher publisher;
|
|
std::unique_ptr<utils::DispatcherTimer> trade_timer;
|
|
int64_t poll_period_ms;
|
|
VolumeAtPriceState state;
|
|
PImpl(bts::api::ServiceContext& context,
|
|
const MarketDataAuxiliaryServiceBase::Volume_at_priceStatefulPublisher& publisher)
|
|
:
|
|
relay_service(context.locate<MarketDataRelay>()),
|
|
publisher(publisher),
|
|
trade_timer(),
|
|
poll_period_ms(100),
|
|
state(){
|
|
}
|
|
};
|
|
|
|
MarketDataAuxiliaryServiceServer::MarketDataAuxiliaryServiceServer(
|
|
bts::api::ServiceContext& context)
|
|
:
|
|
MarketDataAuxiliaryServiceBase(context),
|
|
me(new PImpl(context,
|
|
make_volume_at_price_stateful_publisher())){
|
|
auto& threadpool = utils::Dispatcher::get_named("TradesQuery");
|
|
me->trade_timer =
|
|
std::make_unique<utils::DispatcherTimer>(threadpool,
|
|
me->poll_period_ms,
|
|
[this]() {
|
|
me->relay_service.requestmd(me->state.md_req(),
|
|
[this](const bts::api::Result<MDReply>& md_reply)
|
|
{
|
|
if(md_reply.result()!=nullptr)
|
|
_scan_trades(*md_reply.result());}
|
|
);
|
|
});
|
|
me->trade_timer->start();
|
|
}
|
|
|
|
void MarketDataAuxiliaryServiceServer::_scan_trades(const MDReply& md_reply){
|
|
uint32_t n_trades=0, total_unique_levels=0;
|
|
bts::TimeStamp t0=bts::Timer::now();
|
|
for(const auto& cr : md_reply.channels())
|
|
me->state.on_new_trades(cr,
|
|
me->publisher,
|
|
n_trades,
|
|
total_unique_levels);
|
|
bts::TimeStamp t1=bts::Timer::now();
|
|
double usecs=static_cast<double>(us_diff (t1,t0));
|
|
LOG(OrderMan,Info,"MarketDataAuxiliaryServiceServer::_scan_trades "
|
|
"trades:{} tot_unique:{} usecs:{}",
|
|
n_trades,total_unique_levels,usecs);
|
|
me->publisher.flush();
|
|
}
|
|
|
|
MarketDataAuxiliaryServiceServer::~MarketDataAuxiliaryServiceServer(){
|
|
}
|
|
}}} |