Merge remote-tracking branch 'origin/spark_crypto_base.server' into spark_crypto_base.client_server_merge
This commit is contained in:
commit
75f8963ecd
16 files changed
+194
-101
No files matched your search
+4
-1
@@ -12,6 +12,7 @@ set (SPARK_PYTHON "${EXTERNALS_ROOT}/python")
|
||||
set (SPARK_BIN "${EXTERNALS_ROOT}/bin")
|
||||
set (SPARK_INCLUDE "${EXTERNALS_ROOT}/include")
|
||||
set (SPARK_LIB "${EXTERNALS_ROOT}/lib/${CMAKE_BUILD_TYPE}")
|
||||
set (BUILD_SDK OFF CACHE BOOL "Build the sdk")
|
||||
|
||||
include_directories (BEFORE SYSTEM ${SPARK_INCLUDE} ${EXTERNALS_ROOT}/include/zlib)
|
||||
link_directories (${SPARK_LIB})
|
||||
@@ -47,7 +48,9 @@ else ()
|
||||
add_subdirectory(src/lib)
|
||||
add_subdirectory(src/web)
|
||||
add_subdirectory(doc/user)
|
||||
add_subdirectory(src/sdk)
|
||||
if (BUILD_SDK)
|
||||
add_subdirectory(src/sdk)
|
||||
endif()
|
||||
add_subdirectory(src/data_files)
|
||||
|
||||
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/server
|
||||
|
||||
+1
-1
Submodule externals updated: 5d2136faee...7bcc559c1a.
@@ -1,7 +0,0 @@
|
||||
syntax='proto3';
|
||||
package bts.config;
|
||||
import "lib/api/md/MarketDataSubscriptionParams.proto";
|
||||
|
||||
message CryptoConfig {
|
||||
repeated bts.api.md.MarketDataSubscriptionParams crypto_md = 1;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
#include <fstream>
|
||||
#include <google/protobuf/text_format.h>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
namespace bts::core {
|
||||
|
||||
class ProtoReader {
|
||||
public:
|
||||
template <class T>
|
||||
static bool read_proto(const std::string &path, T &result);
|
||||
|
||||
template <class T>
|
||||
static bool read_proto(
|
||||
const std::string &path, T &result, std::ostream &err);
|
||||
|
||||
template <class T>
|
||||
static std::optional<T> read_proto(const std::string &path);
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
bool ProtoReader::read_proto(
|
||||
const std::string &path, T &result, std::ostream &err) {
|
||||
std::ifstream f(path);
|
||||
if (f.good()) {
|
||||
std::string str(
|
||||
(std::istreambuf_iterator<char>(f)),
|
||||
(std::istreambuf_iterator<char>()));
|
||||
if (google::protobuf::TextFormat::ParseFromString(str, &result)) {
|
||||
return true;
|
||||
}
|
||||
err << "Invalid config in " << path << "\n";
|
||||
} else {
|
||||
err << "File not found in " << path << "\n";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool ProtoReader::read_proto(const std::string &path, T &result) {
|
||||
struct NullBuffer : std::streambuf {
|
||||
int overflow(int c) override { return c; }
|
||||
};
|
||||
NullBuffer null_buff;
|
||||
std::ostream no_op(&null_buff);
|
||||
return read_proto(path, result, no_op);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::optional<T> ProtoReader::read_proto(const std::string &path) {
|
||||
T result;
|
||||
if (read_proto(path, result)) {
|
||||
return result;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace spartan::core
|
||||
@@ -7,12 +7,13 @@
|
||||
|
||||
namespace bts::md {
|
||||
|
||||
struct MarketDataSubscription {
|
||||
class MarketDataSubscription {
|
||||
public:
|
||||
api::domain::Venue venue() const;
|
||||
|
||||
MarketDataSubscription() = default;
|
||||
explicit MarketDataSubscription(
|
||||
const api::md::MarketDataSubscriptionParams ¶ms);
|
||||
api::md::MarketDataSubscriptionParams params);
|
||||
|
||||
MarketDataSubscription(const MarketDataSubscription &) noexcept = default;
|
||||
MarketDataSubscription(MarketDataSubscription &&) noexcept = default;
|
||||
@@ -31,9 +32,9 @@ struct MarketDataSubscription {
|
||||
// Definition
|
||||
//////////////////////////////////////////////////
|
||||
|
||||
MarketDataSubscription::MarketDataSubscription(
|
||||
const api::md::MarketDataSubscriptionParams ¶ms)
|
||||
: params_(params) {}
|
||||
inline MarketDataSubscription::MarketDataSubscription(
|
||||
api::md::MarketDataSubscriptionParams params)
|
||||
: params_(std::move(params)) {}
|
||||
|
||||
inline const api::md::MarketDataSubscriptionParams &
|
||||
MarketDataSubscription::params() const {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "Validators.h"
|
||||
#include "server/sparkd/cmds/spartan/utils/FileUtils.h"
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
CLI::Validator Validators::file_exists() {
|
||||
return CLI::Validator(
|
||||
[](const std::string &path) -> std::string {
|
||||
if (spartan::FileUtils::file_exists(path)) {
|
||||
return "";
|
||||
}
|
||||
return fmt::format("The file '{}' does not exist.", path);
|
||||
},
|
||||
"file_exists_validator", "Validates that the file exists");
|
||||
}
|
||||
|
||||
} // namespace bts::cmds
|
||||
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <CLI11/CLI11.hpp>
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
class Validators {
|
||||
public:
|
||||
static CLI::Validator file_exists();
|
||||
};
|
||||
|
||||
} // namespace bts::cmds
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "BinanceDemo.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/CryptoConfig.pb.h"
|
||||
#include "lib/md/MarketDataGateway.h"
|
||||
#include "lib/md/MarketDataRegistration.h"
|
||||
#include "lib/md/MarketDataSubscription.h"
|
||||
#include "lib/md/listeners/LiveLadderPrinter.h"
|
||||
#include "server/sparkd/cmds/spartan/utils/FileUtils.h"
|
||||
#include <vector>
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
struct BinanceDemo::PImpl {
|
||||
std::vector<md::MarketDataSubscription> subs;
|
||||
};
|
||||
|
||||
BinanceDemo::BinanceDemo() : me_(std::make_unique<PImpl>()) {
|
||||
char ssl_cert_file[] = "SSL_CERT_FILE=/etc/ssl/cert/ca-certificates.crt";
|
||||
putenv(ssl_cert_file);
|
||||
md::MarketDataGateway gw;
|
||||
md::listeners::LiveLadderPrinter ladder_printer;
|
||||
auto crypto = config::get<bts::config::CryptoConfig>();
|
||||
for (const auto &sub_params : crypto.crypto_md()) {
|
||||
me_->subs.emplace_back(sub_params);
|
||||
md::MarketDataSubscription sub(sub_params);
|
||||
switch (sub_params.VenueParams_case()) {
|
||||
case api::md::MarketDataSubscriptionParams::kBinance: {
|
||||
gw.register_listener(sub, &ladder_printer);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
const std::size_t n_loops = 16;
|
||||
for (std::size_t n = 0; n < n_loops; n++) {
|
||||
std::cout << "Main loop iter " << n + 1;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
BinanceDemo::~BinanceDemo() = default;
|
||||
|
||||
} // namespace bts::cmds
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
class BinanceDemo {
|
||||
public:
|
||||
BinanceDemo();
|
||||
~BinanceDemo();
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me_;
|
||||
};
|
||||
|
||||
} // namespace bts::cmds
|
||||
@@ -1,20 +0,0 @@
|
||||
#include "BinanceDemoCmd.h"
|
||||
#include "BinanceDemo.h"
|
||||
#include <CLI11/CLI11.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
struct BinanceDemoCmd::PImpl {
|
||||
std::optional<BinanceDemo> demo;
|
||||
};
|
||||
|
||||
BinanceDemoCmd::BinanceDemoCmd()
|
||||
: CLI::App("Display binance live depth", "binance-demo"),
|
||||
me_(std::make_unique<BinanceDemoCmd::PImpl>()) {
|
||||
callback([this]() { me_->demo.emplace(); });
|
||||
}
|
||||
|
||||
BinanceDemoCmd::~BinanceDemoCmd() = default;
|
||||
|
||||
} // namespace bts::cmds
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "CryptoCmd.h"
|
||||
#include "BinanceDemoCmd.h"
|
||||
#include "DeribitDemoCmd.h"
|
||||
#include "LiveLadderDemoCmd.h"
|
||||
#include <CLI11/CLI11.hpp>
|
||||
|
||||
namespace bts::cmds {
|
||||
@@ -12,7 +12,7 @@ struct CryptoCmd::Args {
|
||||
CryptoCmd::CryptoCmd()
|
||||
: CLI::App("Execute commands for the new crypto system", "crypto"),
|
||||
args_(std::make_unique<CryptoCmd::Args>()) {
|
||||
add_subcommand(std::make_shared<BinanceDemoCmd>());
|
||||
add_subcommand(std::make_shared<LiveLadderDemoCmd>());
|
||||
add_subcommand(std::make_shared<DeribitDemoCmd>());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#include "LiveLadderDemo.h"
|
||||
#include "lib/md/MarketDataGateway.h"
|
||||
#include "lib/md/MarketDataRegistration.h"
|
||||
#include "lib/md/MarketDataSubscription.h"
|
||||
#include "lib/md/listeners/LiveLadderPrinter.h"
|
||||
#include <vector>
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
LiveLadderDemo::LiveLadderDemo(md::MarketDataSubscription subscription) {
|
||||
char ssl_cert_file[] = "SSL_CERT_FILE=/etc/ssl/cert/ca-certificates.crt";
|
||||
putenv(ssl_cert_file);
|
||||
|
||||
md::MarketDataGateway gw;
|
||||
md::listeners::LiveLadderPrinter ladder_printer;
|
||||
gw.register_listener(subscription, &ladder_printer);
|
||||
|
||||
const std::size_t n_loops = 16;
|
||||
for (std::size_t n = 0; n < n_loops; n++) {
|
||||
std::cout << "Main loop iter " << n + 1;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace bts::cmds
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace bts::md {
|
||||
class MarketDataSubscription;
|
||||
}
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
class LiveLadderDemo {
|
||||
public:
|
||||
explicit LiveLadderDemo(md::MarketDataSubscription subscription);
|
||||
};
|
||||
|
||||
} // namespace bts::cmds
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "LiveLadderDemoCmd.h"
|
||||
#include "LiveLadderDemo.h"
|
||||
#include "lib/api/md/MarketDataSubscriptionParams.pb.h"
|
||||
#include "lib/core/ProtoReader.h"
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/md/MarketDataSubscription.h"
|
||||
#include "server/sparkd/cmds/common/Validators.h"
|
||||
#include "server/sparkd/cmds/crypto/LiveLadderDemo.h"
|
||||
#include "server/sparkd/cmds/spartan/utils/FileUtils.h"
|
||||
#include <CLI11/CLI11.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
struct LiveLadderDemoCmd::PImpl {
|
||||
std::string subscription_in;
|
||||
std::optional<LiveLadderDemo> demo;
|
||||
};
|
||||
|
||||
LiveLadderDemoCmd::LiveLadderDemoCmd()
|
||||
: CLI::App("Display live depth", "ladder-demo"),
|
||||
me_(std::make_unique<LiveLadderDemoCmd::PImpl>()) {
|
||||
add_option(
|
||||
"subscription,--subscription", me_->subscription_in,
|
||||
"Path to a json file that defines a MarketDataSubscriptionParams "
|
||||
"object")
|
||||
->required()
|
||||
->check(Validators::file_exists());
|
||||
callback([this]() {
|
||||
auto subscriptions =
|
||||
core::ProtoReader::read_proto<api::md::MarketDataSubscriptionParams>(
|
||||
me_->subscription_in);
|
||||
if (!subscriptions.has_value()) {
|
||||
LOG(md, bts::Error,
|
||||
"Unable to parse MarketDataSubscriptionParams from file '{}'",
|
||||
me_->subscription_in);
|
||||
}
|
||||
me_->demo.emplace(md::MarketDataSubscription{std::move(*subscriptions)});
|
||||
});
|
||||
}
|
||||
|
||||
LiveLadderDemoCmd::~LiveLadderDemoCmd() = default;
|
||||
|
||||
} // namespace bts::cmds
|
||||
+3
-3
@@ -4,10 +4,10 @@
|
||||
|
||||
namespace bts::cmds {
|
||||
|
||||
class BinanceDemoCmd : public CLI::App {
|
||||
class LiveLadderDemoCmd : public CLI::App {
|
||||
public:
|
||||
BinanceDemoCmd();
|
||||
~BinanceDemoCmd();
|
||||
LiveLadderDemoCmd();
|
||||
~LiveLadderDemoCmd();
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
@@ -85,7 +85,7 @@ if [ "$FULL" == "1" ]; then
|
||||
cp -r ../public/* $OUT/ui/
|
||||
dotnet restore -s ../../../../externals/nuget/packages
|
||||
if [ "$MODE" == "release" ]; then
|
||||
dotnet fable webpack -- --env BUILD_PATH=$OUT -p
|
||||
dotnet fable webpack -- --env BUILD_PATH=$OUT --mode production
|
||||
else
|
||||
dotnet fable webpack -- --env BUILD_PATH=$OUT
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user