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
@@ -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;
|
||||
Reference in new issue
Block a user