Merge branch 'master' of bitbucket.org:bluetradesys/spark
This commit is contained in:
commit
ba922bdb4f
23 files changed
+175
-25
No files matched your search
@@ -8,3 +8,4 @@ obj/
|
||||
msbuild.log
|
||||
*.orig
|
||||
vcxproj.user
|
||||
launchSettings.json
|
||||
@@ -16,6 +16,8 @@
|
||||
<StartupObject />
|
||||
<RootNamespace>bts</RootNamespace>
|
||||
<LangVersion>7.1</LangVersion>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../spark_api/spark_api.csproj" />
|
||||
|
||||
@@ -69,6 +69,10 @@ namespace mbts.config
|
||||
private static extern void reset();
|
||||
|
||||
|
||||
[DllImport("spark_lib")]
|
||||
internal static extern void configcheck(int count, string[] args);
|
||||
|
||||
|
||||
private static object config_lock = new object();
|
||||
enum State
|
||||
{
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Platforms>x64</Platforms>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<Platforms>x64</Platforms>
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<WarningsAsErrors />
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace sparkcmd
|
||||
{
|
||||
@@ -6,6 +7,11 @@ namespace sparkcmd
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
if (args.FirstOrDefault() == "configcheck") {
|
||||
mbts.config.Configuration.configcheck(args.Length-1, args.Skip(1).ToArray());
|
||||
return;
|
||||
}
|
||||
|
||||
mbts.config.Configuration.initialize();
|
||||
//mbts.utils.BTSNativeMethods.init_spark_lib();
|
||||
var c = mbts.config.Configuration.get<bts.config.JetFIX>();
|
||||
|
||||
@@ -75,6 +75,7 @@ set (SparkLib_Sources
|
||||
config/ConfigurationState.cpp
|
||||
config/ConfigValueQueue.cpp
|
||||
config/PreprocessInputStream.cpp
|
||||
config/ConfigCheck.cpp
|
||||
config/text_format/text_format.cpp
|
||||
config/tests/config_ref_tests.cpp
|
||||
config/tests/HTTPServer.cpp
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
#include "config.h"
|
||||
#include "ConfigCheck.h"
|
||||
#include "lib/utils/bts_export.h"
|
||||
#include "lib/utils/TimeStamp.h"
|
||||
|
||||
#include <google/protobuf/message.h>
|
||||
#include <google/protobuf/descriptor.h>
|
||||
#include <google/protobuf/generated_message_reflection.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
namespace proto = google::protobuf;
|
||||
namespace bts {
|
||||
namespace config {
|
||||
namespace interop {
|
||||
std::string get_macro_string(const char* name);
|
||||
} } }
|
||||
using namespace bts;
|
||||
|
||||
void fill_in_defaults(google::protobuf::Message* msg) {
|
||||
const proto::Descriptor* d = msg->GetDescriptor();
|
||||
const proto::Reflection* r = msg->GetReflection();
|
||||
for (int x = 0; x < d->field_count(); ++x) {
|
||||
auto* fd = d->field(x);
|
||||
auto type = fd->cpp_type();
|
||||
if (!fd->is_repeated()) {
|
||||
if (type == proto::FieldDescriptor::CPPTYPE_MESSAGE) {
|
||||
fill_in_defaults(r->MutableMessage(msg, fd));
|
||||
}
|
||||
else if (fd->has_default_value() && !r->HasField(*msg, fd)) {
|
||||
switch (type) {
|
||||
case proto::FieldDescriptor::CPPTYPE_INT32:
|
||||
r->SetInt32(msg, fd, fd->default_value_int32());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_INT64:
|
||||
r->SetInt64(msg, fd, fd->default_value_int64());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_UINT32:
|
||||
r->SetUInt32(msg, fd, fd->default_value_uint32());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_UINT64:
|
||||
r->SetUInt64(msg, fd, fd->default_value_uint64());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_DOUBLE:
|
||||
r->SetDouble(msg, fd, fd->default_value_double());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_FLOAT:
|
||||
r->SetFloat(msg, fd, fd->default_value_float());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_BOOL:
|
||||
r->SetBool(msg, fd, fd->default_value_bool());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_ENUM:
|
||||
r->SetEnum(msg, fd, fd->default_value_enum());
|
||||
break;
|
||||
case proto::FieldDescriptor::CPPTYPE_STRING:
|
||||
r->SetString(msg, fd, fd->default_value_string());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" BTS_EXPORT void configcheck(int argc, const char** argv) {
|
||||
std::vector<std::string> args(argv, argv+argc);
|
||||
char buffer[4096] = {0};
|
||||
utils::TimeStamp start = utils::TimeStamp::now();
|
||||
bool success = config::initialize_nothrow(buffer, sizeof(buffer));
|
||||
double time = (utils::TimeStamp::now() - start).seconds();
|
||||
|
||||
if (success) {
|
||||
success = config::internal::check_rules(buffer, sizeof(buffer));
|
||||
}
|
||||
|
||||
if (!success) {
|
||||
std::cout << buffer << std::endl;
|
||||
}
|
||||
std::cout << "Load time> " << std::floor(time * 1000) << " ms" << std::endl;
|
||||
|
||||
for (size_t x = 0; x < args.size(); x++)
|
||||
{
|
||||
std::string key = args[x];
|
||||
if (key[0] == '$') {
|
||||
// macro
|
||||
std::string result = config::interop::get_macro_string(key.c_str());
|
||||
std::cout << key << ": " << result;
|
||||
}
|
||||
else {
|
||||
const google::protobuf::Message* message = config::interop::get_named(key.c_str());
|
||||
if (message)
|
||||
{
|
||||
google::protobuf::Message* mut = message->New();
|
||||
mut->CopyFrom(*message);
|
||||
if (args.size() > 1)
|
||||
std::cout << key << ":" << std::endl;
|
||||
fill_in_defaults(mut);
|
||||
mut->PrintDebugString();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Cannot find a config key by the name: " << key;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
#include "lib/utils/bts_export.h"
|
||||
extern "C" BTS_EXPORT void configcheck(int argc, const char** argv);
|
||||
@@ -39,7 +39,7 @@ void run_md_price_latency_test(UserSymbol symbol) {
|
||||
while (true) {
|
||||
for(auto& entry : handles) {
|
||||
PriceSize bid, ask;
|
||||
if (entry.handle.get_bbo(entry.time, bid, ask)) {
|
||||
if (entry.handle.get_bbo(entry.time, bid, ask) == HandleReadResult::SUCCESS) {
|
||||
auto bid_price = bid.price();
|
||||
auto ask_price = ask.price();
|
||||
if (bid_price != entry.bid || ask_price != entry.ask) {
|
||||
|
||||
@@ -10,6 +10,12 @@ namespace md2 {
|
||||
|
||||
BTS_EXPORT TimeStamp copy_bbo(const TimeStamp& , const SingleWriterPriceSizeStore& ,
|
||||
const SingleWriterPriceSizeStore& , PriceSize& , PriceSize& );
|
||||
|
||||
enum class HandleReadResult {
|
||||
NO_CHANGE,
|
||||
BUSY,
|
||||
SUCCESS
|
||||
};
|
||||
|
||||
// Can be an invalid handle if you request a security which has not been discovered yet.
|
||||
class BTS_EXPORT MDConsumerHandle
|
||||
@@ -32,31 +38,33 @@ public:
|
||||
|
||||
|
||||
TimeStamp last_market_update() const;
|
||||
|
||||
|
||||
bool get_bbo(TimeStamp& time, PriceSize& bid, PriceSize& ask) const
|
||||
HandleReadResult get_bbo(TimeStamp& time, PriceSize& bid, PriceSize& ask) const
|
||||
{
|
||||
if (!is_initialized()) return false;
|
||||
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_bbo(pdepth->timestamp, pdepth->bid(0), pdepth->ask(0), bid, ask);
|
||||
if (temp == TimeStamp::invalid()) { return false; }
|
||||
if (temp == TimeStamp::invalid()) { return HandleReadResult::BUSY; }
|
||||
time = temp;
|
||||
return true;
|
||||
return HandleReadResult::SUCCESS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
auto* pdepth = hot();
|
||||
if (pdepth->timestamp > time || pdepth->timestamp == TimeStamp::invalid()) {
|
||||
TimeStamp temp = copy_bbo(pdepth->timestamp, pdepth->bid, pdepth->ask, bid, ask);
|
||||
if (temp == TimeStamp::invalid()) { return false; }
|
||||
if (temp == TimeStamp::invalid()) { return HandleReadResult::BUSY; }
|
||||
time = temp;
|
||||
return true;
|
||||
return HandleReadResult::SUCCESS;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return HandleReadResult::NO_CHANGE;
|
||||
}
|
||||
|
||||
|
||||
// Last bbo or depth update
|
||||
PriceSize get_bid(size_t depth) const;
|
||||
|
||||
@@ -236,7 +236,8 @@ struct QueryServerImpl : public IQueryServer {
|
||||
if (HASFLAG(flags, MDRequest::BBO) || HASFLAG(flags, MDRequest::DEPTH)) {
|
||||
PriceSize bid, ask;
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
if (handle.get_bbo(time, bid, ask)) {
|
||||
auto result = handle.get_bbo(time, bid, ask);
|
||||
if (result == HandleReadResult::SUCCESS) {
|
||||
auto* p = pupd->mutable_book();
|
||||
convert(bid, p->add_bids());
|
||||
convert(ask, p->add_asks());
|
||||
@@ -253,6 +254,16 @@ struct QueryServerImpl : public IQueryServer {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (result == HandleReadResult::BUSY) {
|
||||
LOG(MarketData,Info, "Busy read on handle {}. Retry on next request", instrument.handle.key());
|
||||
// If we get a busy reading BBO (which happens 1-2x per day for a single relay client)
|
||||
// We move the timestamp back so the next request will try to read this value again.
|
||||
// ALTERNATIVE: We could spin until the value was not busy but it could be that the writer
|
||||
// was context switched out and we will have to wait multiple ms to unblock the request.
|
||||
// This fix assumes it is better to send the update now with 1 stale value than to block the call
|
||||
// and allow all the values to be stale until this one can be read.
|
||||
reply->mutable_channel()->set_time(chan.time());
|
||||
}
|
||||
}
|
||||
if (HASFLAG(flags, MDRequest::LAST_TRADE)) {
|
||||
TimeStamp time(snapshot ? 0 : chan.time());
|
||||
|
||||
@@ -309,7 +309,7 @@ public:
|
||||
PriceSize bid, ask;
|
||||
TimeStamp read_time;
|
||||
// get_boo returns true becuase this time is after the change
|
||||
REQUIRE(c.get_bbo(read_time, bid, ask));
|
||||
REQUIRE(c.get_bbo(read_time, bid, ask) == HandleReadResult::SUCCESS);
|
||||
REQUIRE((read_time - TimeStamp()).seconds() > 0);
|
||||
REQUIRE(bid.price() == 5.0);
|
||||
REQUIRE(ask.price() == 5.0);
|
||||
@@ -321,7 +321,7 @@ public:
|
||||
auto read_time = TimeStamp::now();
|
||||
for (const auto& c : consumers) {
|
||||
PriceSize bid, ask;
|
||||
REQUIRE(!c.get_bbo(read_time, bid, ask));
|
||||
REQUIRE(c.get_bbo(read_time, bid, ask) != HandleReadResult::SUCCESS);
|
||||
}
|
||||
|
||||
// update everything once more
|
||||
@@ -335,7 +335,7 @@ public:
|
||||
TimeStamp modified_time = read_time;
|
||||
PriceSize bid, ask;
|
||||
// get_bbo returns true becuase this time is after the change
|
||||
REQUIRE(c.get_bbo(modified_time, bid, ask));
|
||||
REQUIRE(c.get_bbo(modified_time, bid, ask) == HandleReadResult::SUCCESS);
|
||||
REQUIRE( (modified_time - read_time).seconds() > 0);
|
||||
REQUIRE(bid.price() == 6.55);
|
||||
REQUIRE(ask.price() == 6.55);
|
||||
@@ -414,11 +414,11 @@ public:
|
||||
PriceSize bid, ask;
|
||||
for(auto& c : consumers) {
|
||||
TimeStamp zerotime;
|
||||
REQUIRE(!c.get_bbo(zerotime, bid, ask));
|
||||
REQUIRE(c.get_bbo(zerotime, bid, ask) != HandleReadResult::SUCCESS);
|
||||
}
|
||||
for(auto& mc : managed_consumers) {
|
||||
TimeStamp zerotime;
|
||||
REQUIRE(!mc->get_bbo(zerotime, bid, ask));
|
||||
REQUIRE(mc->get_bbo(zerotime, bid, ask) != HandleReadResult::SUCCESS);
|
||||
}
|
||||
|
||||
assign_ids(producers.begin(), producers.end());
|
||||
@@ -427,7 +427,7 @@ public:
|
||||
// Existing old handles remain invalid
|
||||
for(auto& c : consumers) {
|
||||
TimeStamp zerotime;
|
||||
if (c.get_bbo(zerotime, bid, ask)) {
|
||||
if (c.get_bbo(zerotime, bid, ask) == HandleReadResult::SUCCESS) {
|
||||
bbo_count++;
|
||||
}
|
||||
}
|
||||
@@ -435,7 +435,7 @@ public:
|
||||
// Now, magically, the existing (managed) handles are valid
|
||||
for(auto& mc : managed_consumers) {
|
||||
TimeStamp zerotime;
|
||||
if (mc->get_bbo(zerotime, bid, ask)) {
|
||||
if (mc->get_bbo(zerotime, bid, ask) == HandleReadResult::SUCCESS) {
|
||||
bbo_count++;
|
||||
}
|
||||
}
|
||||
@@ -466,11 +466,11 @@ public:
|
||||
PriceSize bid, ask;
|
||||
for(auto& c : consumers) {
|
||||
TimeStamp zerotime;
|
||||
REQUIRE(!c.get_bbo(zerotime, bid, ask));
|
||||
REQUIRE(c.get_bbo(zerotime, bid, ask) != HandleReadResult::SUCCESS);
|
||||
}
|
||||
for(auto& mc : managed_consumers) {
|
||||
TimeStamp zerotime;
|
||||
REQUIRE(!mc->get_bbo(zerotime, bid, ask));
|
||||
REQUIRE(mc->get_bbo(zerotime, bid, ask) != HandleReadResult::SUCCESS);
|
||||
}
|
||||
|
||||
// Only NOW create the producers (and the shared memory)
|
||||
@@ -488,7 +488,7 @@ public:
|
||||
// Existing old handles remain invalid
|
||||
for(auto& c : consumers) {
|
||||
TimeStamp zerotime;
|
||||
if (c.get_bbo(zerotime, bid, ask)) {
|
||||
if (c.get_bbo(zerotime, bid, ask) == HandleReadResult::SUCCESS) {
|
||||
bbo_count++;
|
||||
}
|
||||
}
|
||||
@@ -496,7 +496,7 @@ public:
|
||||
// Now, magically, the existing (managed) handles are valid
|
||||
for(auto& mc : managed_consumers) {
|
||||
TimeStamp zerotime;
|
||||
if (mc->get_bbo(zerotime, bid, ask)) {
|
||||
if (mc->get_bbo(zerotime, bid, ask) == HandleReadResult::SUCCESS) {
|
||||
bbo_count++;
|
||||
}
|
||||
}
|
||||
@@ -653,7 +653,7 @@ public:
|
||||
REQUIRE(handle->is_heart_beating());
|
||||
TimeStamp tzero;
|
||||
PriceSize bid, ask;
|
||||
REQUIRE(handle->get_bbo(tzero, bid, ask));
|
||||
REQUIRE(handle->get_bbo(tzero, bid, ask) == HandleReadResult::SUCCESS);
|
||||
REQUIRE(bid.price() == 4.0);
|
||||
REQUIRE(bid.size() == 5);
|
||||
REQUIRE(ask.price() == 6.0);
|
||||
@@ -675,9 +675,9 @@ public:
|
||||
src->producer().update_bbo(TimeStamp::invalid(), PriceSize::from_double<3>(100.0, 100), PriceSize::from_double<3>(101.0, 101));
|
||||
PriceSize bid, ask;
|
||||
TimeStamp start = TimeStamp::now();
|
||||
bool result = src->consumer().get_bbo(read, bid, ask);
|
||||
auto result = src->consumer().get_bbo(read, bid, ask);
|
||||
TimeStamp end = TimeStamp::now();
|
||||
REQUIRE(result == false);
|
||||
REQUIRE(result != HandleReadResult::SUCCESS);
|
||||
REQUIRE((end - start).seconds() < 5);
|
||||
}
|
||||
|
||||
@@ -1288,7 +1288,7 @@ struct Co2PerfTests {
|
||||
for (auto& c : consumers) {
|
||||
PriceSize bid, ask;
|
||||
TimeStamp ts;
|
||||
REQUIRE(c.get_bbo(ts, bid, ask));
|
||||
REQUIRE(c.get_bbo(ts, bid, ask) == HandleReadResult::SUCCESS);
|
||||
}
|
||||
|
||||
// Start a thread which loops and writes to the producers until terminated
|
||||
@@ -1314,7 +1314,7 @@ struct Co2PerfTests {
|
||||
for (size_t x = 0; x < consumers.size(); ++x) {
|
||||
PriceSize bid, ask;
|
||||
TimeStamp ts_temp = ts;
|
||||
if (consumers[x].get_bbo(ts_temp, bid, ask)) {
|
||||
if (consumers[x].get_bbo(ts_temp, bid, ask) == HandleReadResult::SUCCESS) {
|
||||
++read_count;
|
||||
}
|
||||
}
|
||||
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Reference in new issue
Block a user