124 lines
4.1 KiB
C++
124 lines
4.1 KiB
C++
#pragma once
|
|
|
|
#include "lib/utils/bts_no_copy.h"
|
|
#include "lib/utils/bts_export.h"
|
|
#include "Shm/MDStructure.h"
|
|
#include "MDProducerChannel.h"
|
|
#include "lib/utils/datetime.h"
|
|
|
|
#include <tbb/concurrent_queue.h>
|
|
#include <vector>
|
|
|
|
|
|
namespace bts {
|
|
namespace co2 { struct Work; }
|
|
namespace md {
|
|
|
|
class BTS_EXPORT MDProducerHandle
|
|
{
|
|
public:
|
|
MDProducerHandle(ColdHeader&, HotHeader&, ColdEntry&, void* hot, MDProducerChannel channel);
|
|
~MDProducerHandle();
|
|
|
|
MDProducerHandle& operator=(MDProducerHandle const& other);
|
|
|
|
const FixedSecurity& security() const { return cdata().security; }
|
|
FixedSecurity* mutable_security() { return key() == invalid_security_key ? &cdata().security : nullptr; }
|
|
|
|
bool has_depth() const { return cheader().has_depth; }
|
|
void set_key(security_key);
|
|
security_key key() const {
|
|
security_key key = has_depth() ? hdepth().key : hdata().key;
|
|
bts_assert_d(key == cdata().security.key);
|
|
return key;
|
|
}
|
|
void set_legs(const std::vector<security_key>& legs);
|
|
|
|
void update_bbo(TimeStamp time, const PriceSize bid_price, const PriceSize ask_price, uint16_t seq=0); // hot
|
|
void update_book(TimeStamp time, std::array<PriceSize,COCONUT_MAX_DEPTH>& bids, std::array<PriceSize,COCONUT_MAX_DEPTH>& asks, uint16_t seq=0) {
|
|
if (!has_depth()) {
|
|
update_bbo(time, bids[0], asks[0], seq);
|
|
}
|
|
else {
|
|
auto& book = hdepth();
|
|
book.set_time(TimeStamp::invalid());
|
|
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
|
|
book.bid(x).store(bids[x]);
|
|
book.ask(x).store(asks[x]);
|
|
}
|
|
book.status = co2::COCONUTSECURITYSTATUS_OK;
|
|
book.sequence = seq;
|
|
book.set_time(time);
|
|
hheader().depth_count++;
|
|
}
|
|
}
|
|
|
|
void set_status(co2::CoconutSecurityStatus status); // hot
|
|
|
|
// Updates trade log and last trade
|
|
void add_trade(TimeStamp time, const PriceSize pricesize, datetime::LLDateTime date, co2::AggressorSide agside, uint32_t total_volume=0); // cold
|
|
// Update last_trade without updating trade log
|
|
void set_last_trade(TimeStamp time, const PriceSize ps, datetime::LLDateTime date, uint32_t total_volume);
|
|
void add_rfq(TimeStamp time, const co2::QuoteRequestMessage& rfq); // cold
|
|
|
|
void update_customer_bbo(TimeStamp time, const PriceSize bid, const PriceSize ask); // cold
|
|
void update_exchange_status(TimeStamp time, TradingStatus status); // cold
|
|
|
|
// Misc fields
|
|
void update_settlement(TimeStamp time, Price price, datetime::Date date); // cold
|
|
void update_previous_settlement(TimeStamp time, Price price, datetime::Date date); // cold
|
|
void update_opening(TimeStamp time, Price price, datetime::Date date); // cold
|
|
void update_closing(TimeStamp time, Price price, datetime::Date date); // cold
|
|
void update_session_high(TimeStamp time, Price price); // cold
|
|
void update_session_low(TimeStamp time, Price price); // cold
|
|
void update_open_interest(TimeStamp time, Price price); // cold
|
|
void update_session_high_bid(TimeStamp time, Price price); // cold
|
|
void update_session_low_offer(TimeStamp time, Price price); // cold
|
|
void update_fixing_price(TimeStamp time, Price price); // cold
|
|
|
|
void mark_deleted(); // cold
|
|
|
|
|
|
private:
|
|
// Private default constructor allows friend classes to store this class in a concurrent_queue
|
|
MDProducerHandle();
|
|
friend class tbb::concurrent_queue < MDProducerHandle > ;
|
|
friend class SecurityIDRecorder;
|
|
friend struct bts::co2::Work;
|
|
|
|
HotEntry& hdata() const {
|
|
bts_assert_d(_hdata && !has_depth());
|
|
return *static_cast<HotEntry*>(_hdata);
|
|
}
|
|
|
|
HotDepthEntry& hdepth() const {
|
|
bts_assert_d(_hdata && has_depth());
|
|
return *static_cast<HotDepthEntry*>(_hdata);
|
|
}
|
|
|
|
HotHeader& hheader() const {
|
|
bts_assert_d(_hheader);
|
|
return *_hheader;
|
|
}
|
|
|
|
ColdEntry& cdata() const {
|
|
bts_assert_d(_cdata);
|
|
return *_cdata;
|
|
}
|
|
|
|
ColdHeader& cheader() const {
|
|
bts_assert_d(_cheader);
|
|
return *_cheader;
|
|
}
|
|
|
|
// COPY OK -- BTS_NO_COPY(MDConsumerHandle);
|
|
void* _hdata;
|
|
HotHeader* _hheader;
|
|
ColdEntry* _cdata;
|
|
ColdHeader* _cheader;
|
|
MDProducerChannel _channel;
|
|
};
|
|
|
|
}}//namespace
|
|
|