SPARK-1574 Add space for implied book

This commit is contained in:
Eric Harding committed 2018-08-30 11:30:33 -04:00
1 parent 293dddc54f
commit 6d7fbe5c84
9 files changed
+71 -34

No files matched your search

+4 -1
View File
@@ -213,7 +213,10 @@ void dump_hot_t(SharedListReader<HotHeader, TEntry>& reader) {
if (!reader.is_initialized()) { LOG(md,Info,"Unable to initialize section "); return; }
auto& header = reader.header();
cout << "{ " << endl;
cout << "'header': { 'count': " << header.count << ", 'segment_count': " << header.segment_count << ", 'bbo_count': " << header.bbo_count << ", 'depth_count': " << header.depth_count << "}," << endl;
cout << "'header': { 'count': " << header.count
<< ", 'segment_count': " << header.segment_count
<< ", 'direct_count': " << header.direct_count
<< ", 'implied_count': " << header.implied_count << "}," << endl;
cout << "'entries': [ " << endl;
reader.all_entries([&](const TEntry& entry) { cout << dump_entry(entry) << "," << endl; });
cout << "] }" << endl;
+4 -4
View File
@@ -932,13 +932,13 @@ TimeStamp MDConsumerChannel::create_time() const { return _pimpl ? _pimpl->cold_
size_t MDConsumerChannel::security_count() const {
return _pimpl->cold_header().security_count;
}
size_t MDConsumerChannel::bbo_count() const {
size_t MDConsumerChannel::direct_count() const {
return is_initialized() ?
_pimpl->hot_header().bbo_count : 0;
_pimpl->hot_header().direct_count : 0;
}
size_t MDConsumerChannel::depth_count() const {
size_t MDConsumerChannel::implied_count() const {
return is_initialized() ?
_pimpl->hot_header().depth_count : 0;
_pimpl->hot_header().implied_count : 0;
}
size_t MDConsumerChannel::trade_count() const {
return _pimpl->cold_header().trade_count;
+2 -2
View File
@@ -87,8 +87,8 @@ public:
//
// Statistic counters
size_t security_count() const;
size_t bbo_count() const;
size_t depth_count() const;
size_t direct_count() const;
size_t implied_count() const;
size_t trade_count() const;
size_t rfq_count() const;
size_t gap_count() const;
+1 -1
View File
@@ -67,7 +67,7 @@ TimeStamp copy_depth(
do {
t = hot.time();
for (size_t x = 0; x < count; ++x) {
hot.read_level(x, &bid[x], &ask[x]);
hot.read_direct(x, &bid[x], &ask[x]);
}
++attempts;
} while((t != hot.time() || t == TimeStamp::invalid()) && attempts < max_attempts);
+3 -3
View File
@@ -82,7 +82,7 @@ void MDProducerHandle::update_bbo(TimeStamp time, const PriceSize bid, const Pri
if (updated) {
hdata().set_time(time);
hdata().sequence = seq;
hheader().bbo_count++;
hheader().direct_count++;
}
else {
hdata().set_time(oldtime);
@@ -91,12 +91,12 @@ void MDProducerHandle::update_bbo(TimeStamp time, const PriceSize bid, const Pri
else {
auto oldtime = hdepth().time();
hdepth().set_time(TimeStamp::invalid());
bool updated = hdepth().write_level(0, bid,ask);
bool updated = hdepth().write_direct(0, bid,ask);
hdepth().status = COCONUTSECURITYSTATUS_OK;
if (updated) {
hdepth().set_time(time);
hdepth().sequence = seq;
hheader().bbo_count++;
hheader().direct_count++;
}
else {
hdepth().set_time(oldtime);
+16 -3
View File
@@ -35,7 +35,7 @@ public:
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) {
void update_book(TimeStamp time, std::array<PriceSize,COCONUT_MAX_DEPTH>& bids, std::array<PriceSize,COCONUT_MAX_DEPTH>& asks, uint32_t seq=0) {
if (!has_depth()) {
update_bbo(time, bids[0], asks[0], seq);
}
@@ -43,12 +43,25 @@ public:
auto& book = hdepth();
book.set_time(TimeStamp::invalid());
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
book.write_level(x, bids[x], asks[x]);
book.write_direct(x, bids[x], asks[x]);
}
book.status = co2::COCONUTSECURITYSTATUS_OK;
book.sequence = seq;
book.set_time(time);
hheader().depth_count++;
hheader().direct_count += 1;
}
}
void update_implied(TimeStamp time, std::array<PriceSize,COCONUT_IMPLIED_DEPTH>& bids, std::array<PriceSize,COCONUT_IMPLIED_DEPTH>& asks, uint32_t seq=0) {
if (has_depth()) {
auto& book = hdepth();
book.set_time(TimeStamp::invalid());
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
book.write_implied(x, bids[x], asks[x]);
}
book.status = co2::COCONUTSECURITYSTATUS_OK;
book.sequence = seq;
book.set_time(time);
hheader().implied_count += 1;
}
}
+37 -18
View File
@@ -32,8 +32,8 @@ struct ALIGNED_(CACHE_LINE) HotHeader {
size_t count;
size_t segment_count;
// Just the counters. Publisher process can compute messages/second by polling these counters
size_t bbo_count;
size_t depth_count;
size_t direct_count;
size_t implied_count;
};
// These should not be cache line aligned because they are small enough for multiple to fit on one line easily
@@ -44,7 +44,7 @@ class HotEntry {
uint32_t size() const { return sizeof(HotEntry); }
PriceLevel book; // 24
security_key key; // 4
uint16_t sequence; // 4
uint32_t sequence; // 4
uint8_t status; // 1
void set_time(const TimeStamp& t) { timestamp.store(t, std::memory_order_release); }
TimeStamp time() const { return timestamp.load(std::memory_order_acquire); }
@@ -52,6 +52,7 @@ class HotEntry {
static_assert(sizeof(HotEntry) <= CACHE_LINE, "HotEntry should be small");
const uint32_t COCONUT_MAX_DEPTH = 10;
const uint32_t COCONUT_IMPLIED_DEPTH = 2;
class HotDepthEntry {
std::atomic<TimeStamp> timestamp; // 8
public:
@@ -59,32 +60,50 @@ class HotDepthEntry {
timestamp(TimeStamp(0)),
key(invalid_security_key),
sequence(0),
status(co2::COCONUTSECURITYSTATUS_OK),
book()
direct(),
implied(),
status(co2::COCONUTSECURITYSTATUS_OK)
{ }
uint32_t size() const { return sizeof(HotDepthEntry); }
security_key key; // 4 NOTE: key is at a different offset than it is in HotEntry
uint16_t sequence; // 2
uint32_t sequence; // 4
std::array<PriceLevel, COCONUT_IMPLIED_DEPTH> implied;
std::array<PriceLevel, COCONUT_MAX_DEPTH> direct;
uint8_t status; // 1
std::array<PriceLevel, COCONUT_MAX_DEPTH> book;
const PriceLevel* at(uint32_t depth) const {
if (depth < book.size()) {
return &book[depth];
if (depth < direct.size()) {
return &direct[depth];
}
return nullptr;
}
void read_level(uint32_t depth, PriceSize* bid, PriceSize* ask) const {
if (depth < book.size()) {
*bid = book[depth].bid();
*ask = book[depth].ask();
void read_direct(uint32_t depth, PriceSize* bid, PriceSize* ask) const {
if (depth < direct.size()) {
*bid = direct[depth].bid();
*ask = direct[depth].ask();
}
}
bool write_level(uint32_t depth, const PriceSize& bid, const PriceSize& ask) {
if (depth < book.size()) {
void read_implied(uint32_t depth, PriceSize* bid, PriceSize* ask) const {
if (depth < implied.size()) {
*bid = implied[depth].bid();
*ask = implied[depth].ask();
}
}
bool write_direct(uint32_t depth, const PriceSize& bid, const PriceSize& ask) {
if (depth < direct.size()) {
auto temp = PriceLevel(bid,ask);
if (book[depth] != temp) {
book[depth] = PriceLevel(bid,ask);
if (direct[depth] != temp) {
direct[depth] = PriceLevel(bid,ask);
return true;
}
}
return false;
}
bool write_implied(uint32_t depth, const PriceSize& bid, const PriceSize& ask) {
if (depth < implied.size()) {
auto temp = PriceLevel(bid,ask);
if (implied[depth] != temp) {
implied[depth] = PriceLevel(bid,ask);
return true;
}
}
@@ -94,7 +113,7 @@ class HotDepthEntry {
void set_time(const TimeStamp& t) { timestamp.store(t, std::memory_order_release); }
TimeStamp time() const { return timestamp.load(std::memory_order_acquire); }
};
static_assert(sizeof(HotDepthEntry) == 256, "HotDepthEntry should be small");
static_assert(sizeof(HotDepthEntry) <= 320, "HotDepthEntry should be small");
//
// COLD Data, brrr
+3 -1
View File
@@ -80,7 +80,9 @@ struct MDConsumerGroup {
labels.push_back({ "type", SecurityType_Name(symbol.type()).substr(13) /*SECURITYTYPE_*/ });
labels.push_back({ "exch", Venue_Name(symbol.exchange()).substr(6) /*VENUE_*/ });
stats.publish(
std::make_shared<metrics::LazyCounterMetricL>("spark_md_book_updates", [=]() { return std::max(channel.bbo_count(), channel.depth_count()); }, labels));
std::make_shared<metrics::LazyCounterMetricL>("spark_md_book_updates", [=]() {
return channel.direct_count() + channel.implied_count();
}, labels));
stats.publish(
std::make_shared<metrics::LazyCounterMetricL>("spark_md_security_count", [=]() { return channel.security_count(); }, labels));
stats.publish(
+1 -1
View File
@@ -48,7 +48,7 @@ extern "C" BTS_EXPORT void co2_get_sample_depth(size_t& size, HotDepthEntry& ent
size = sizeof(HotDepthEntry);
entry.key = 1234;
for (size_t x = 0; x < COCONUT_MAX_DEPTH; ++x) {
entry.write_level(x,
entry.write_direct(x,
PriceSize::from_double<2>(x + 0.5, x + 1),
PriceSize::from_double<2>(x + 0.6, x + 2));
}