Files
spark/src/server/sparkd/md/VolumeAtPriceState.cpp
T
2018-09-18 17:54:34 -04:00

61 lines
1.8 KiB
C++

#include "VolumeAtPriceState.h"
#include "lib/md/get_symbols.h"
#include "lib/api/services/MarketDataRelay.pb.h"
//#include "lib/api/services/MarketDataRelay.client.pb.h"
namespace bts{
namespace md{
namespace auxiliary{
using namespace bts::api::md::auxiliary;
using namespace bts::co2;
using namespace std;
VolumeAtPriceState::VolumeAtPriceState()
:
_channels(),
_md_req(),
_record_id(0){
std::set<bts::md::UserSymbol> syms;
bts::md::get_system_md_symbols(syms);
for(const auto& s : syms){
SecurityChannel c;
c.set_flags(MDRequest::TRADE_LOG);
c.set_type(s.type());
c.set_exchange(s.exchange());
c.set_symbol(s.symbol());
c.set_trade_cursor(0);
c.set_segment_id(0);
_update_or_add(c);
}
}
ChannelVolume& VolumeAtPriceState::_update_or_add(const SecurityChannel& channel){
for(auto& v : _channels)
if(v.match_update(channel))
return v;
SecurityChannel* new_channel_ptr = _md_req.add_channels();
new_channel_ptr->CopyFrom(channel);
_channels.emplace_back(new_channel_ptr);
return _channels.back();
}
void VolumeAtPriceState::on_new_trades(const ChannelReply& reply,
MarketDataAuxiliaryServiceBase::Volume_at_priceStatefulPublisher& publisher,
uint32_t& n_trades,
uint32_t& total_unique_levels){
ChannelVolume& channel_vol=_update_or_add(reply.channel());
for(const TradeMessage& t : reply.trade_log()){
const VolumeAtPriceLevel& sec_level_vol=channel_vol.add_trade(t,
_record_id);
publisher.add_or_update(sec_level_vol);
n_trades++;
}
total_unique_levels = _record_id;
}
const bts::co2::MDRequest& VolumeAtPriceState::md_req() const{
return _md_req;
}
}}}