spark-180 consistent book read (c++)
This commit is contained in:
1 parent
90dbd8c35c
commit
425b2eff0d
2 files changed
+42
-4
No files matched your search
@@ -26,7 +26,7 @@ void MDConsumerHandle::init(const ColdHeader& cheader, const ColdEntry& centry,
|
||||
_cheader = &cheader;
|
||||
}
|
||||
|
||||
BTS_EXPORT TimeStamp copy_bbo(const TimeStamp& time, const SingleWriterPriceSizeStore& in_bid, const SingleWriterPriceSizeStore& in_ask, PriceSize& out_bid, PriceSize& out_ask) {
|
||||
TimeStamp copy_bbo(const TimeStamp& time, const SingleWriterPriceSizeStore& in_bid, const SingleWriterPriceSizeStore& in_ask, PriceSize& out_bid, PriceSize& out_ask) {
|
||||
// We expect the time, in_bid and in_ask to be changing (rapidly)
|
||||
//
|
||||
TimeStamp t;
|
||||
@@ -47,6 +47,28 @@ BTS_EXPORT TimeStamp copy_bbo(const TimeStamp& time, const SingleWriterPriceSize
|
||||
return t;
|
||||
}
|
||||
|
||||
TimeStamp copy_depth(
|
||||
const TimeStamp& time,
|
||||
const SingleWriterPriceSizeStore* source,
|
||||
size_t count,
|
||||
PriceSize* bid, PriceSize* ask)
|
||||
{
|
||||
TimeStamp t;
|
||||
int attempts = 0;
|
||||
const int max_attempts = 1619200;
|
||||
do {
|
||||
for (size_t x = 0; x < count; ++x) {
|
||||
bid[x] = source[2*x].load();
|
||||
ask[x] = source[2*x+1].load();
|
||||
}
|
||||
t = time;
|
||||
} while((t != time || t == TimeStamp::invalid()) && attempts < max_attempts);
|
||||
if (attempts >= max_attempts) {
|
||||
return TimeStamp::invalid();
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
TimeStamp MDConsumerHandle::last_market_update() const {
|
||||
if (has_depth()) {
|
||||
return hotd()->timestamp;
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
namespace bts {
|
||||
namespace md2 {
|
||||
|
||||
BTS_EXPORT TimeStamp copy_bbo(const TimeStamp& , const SingleWriterPriceSizeStore& ,
|
||||
const SingleWriterPriceSizeStore& , PriceSize& , PriceSize& );
|
||||
TimeStamp copy_bbo(const TimeStamp&, const SingleWriterPriceSizeStore&, const SingleWriterPriceSizeStore&, PriceSize&, PriceSize& );
|
||||
TimeStamp copy_depth(const TimeStamp& time, const SingleWriterPriceSizeStore* source, size_t count, PriceSize* bid, PriceSize* ask);
|
||||
|
||||
enum class HandleReadResult {
|
||||
NO_CHANGE,
|
||||
@@ -39,7 +39,6 @@ public:
|
||||
|
||||
TimeStamp last_market_update() const;
|
||||
|
||||
|
||||
HandleReadResult get_bbo(TimeStamp& time, PriceSize& bid, PriceSize& ask) const
|
||||
{
|
||||
if (!is_initialized()) return HandleReadResult::NO_CHANGE;
|
||||
@@ -65,6 +64,23 @@ public:
|
||||
return HandleReadResult::NO_CHANGE;
|
||||
}
|
||||
|
||||
HandleReadResult get_depth(TimeStamp& time, size_t depth, PriceSize* bids, PriceSize* asks) const {
|
||||
bts_assert_d(depth > 0 && depth <= COCONUT_MAX_DEPTH);
|
||||
if (!is_initialized()) return HandleReadResult::NO_CHANGE;
|
||||
if (_cheader->has_depth) {
|
||||
auto* pdepth = hotd();
|
||||
if (pdepth->timestamp > time || pdepth->timestamp == TimeStamp::invalid()) {
|
||||
TimeStamp temp = copy_depth(pdepth->timestamp, pdepth->book, depth, bids, asks);
|
||||
if (temp == TimeStamp::invalid()) { return HandleReadResult::BUSY; }
|
||||
time = temp;
|
||||
return HandleReadResult::SUCCESS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return get_bbo(time, *bids, *asks);
|
||||
}
|
||||
return HandleReadResult::NO_CHANGE;
|
||||
}
|
||||
|
||||
// Last bbo or depth update
|
||||
PriceSize get_bid(size_t depth) const;
|
||||
|
||||
Reference in new issue
Block a user