Skip to content

Commit

Permalink
Merge pull request #331 from northwesternfintech/config
Browse files Browse the repository at this point in the history
Switch configs from #define to constexpr
  • Loading branch information
stevenewald authored Nov 18, 2024
2 parents 0df7a73 + 8f2c10e commit 2307112
Show file tree
Hide file tree
Showing 41 changed files with 176 additions and 300 deletions.
1 change: 0 additions & 1 deletion exchange/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ target_link_libraries(LINTER_spawner_exe PRIVATE Python3::Python)
# ---- COMMON ----------

add_library(COMMON_lib OBJECT
src/common/firebase/firebase.cpp
src/common/file_operations/file_operations.cpp
src/common/util.cpp
src/common/types/decimal.cpp
Expand Down
11 changes: 0 additions & 11 deletions exchange/src/common/config/config.h

This file was deleted.

22 changes: 22 additions & 0 deletions exchange/src/common/config/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

// Compile-time config shared between exchange and wrapper

#include <cstdint>

#include <string>

namespace nutc::common {
constexpr std::string NUTC_VERSION = "1.0";

// logging
constexpr uint8_t LOG_BACKTRACE_SIZE = 10;

// Constexpr std::string concat needs llvm 19, which is annoying to install
constexpr std::string LOG_DIR = "logs";
constexpr std::string LOG_FILEPATH = "logs/app.log";
constexpr std::string JSON_LOG_FILEPATH = "logs/json.log";

constexpr uint32_t LOG_FILE_SIZE = 1024 * 1024 / 2; // 512 KB
constexpr uint8_t LOG_BACKUP_COUNT = 5;
} // namespace nutc::common
123 changes: 0 additions & 123 deletions exchange/src/common/firebase/firebase.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions exchange/src/common/firebase/firebase.hpp

This file was deleted.

6 changes: 3 additions & 3 deletions exchange/src/common/logging/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
#define SHORT_LOGLINE_FORMAT "%(logger_name:<8): %(message)"

namespace nutc {
namespace logging {
namespace common {

using namespace quill; // NOLINT(*-using-namespace)
using cc = quill::ConsoleColours;

void
init(const std::string& log_file, quill::LogLevel log_level)
logging_init(const std::string& log_file, quill::LogLevel log_level)
{
detail::application_log_level = log_level;

Expand Down Expand Up @@ -156,5 +156,5 @@ init_file_only(
LOG_INFO(main_logger, "Logging initialized!");
}

} // namespace logging
} // namespace common
} // namespace nutc
31 changes: 16 additions & 15 deletions exchange/src/common/logging/logging.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#pragma once

#include "common/config/config.hpp"

#include <quill/Quill.h>

#include <string>

#define LOG_DIR "logs"
#define LOG_BACKTRACE_SIZE 10

namespace nutc {
namespace logging {
namespace common {

#ifdef NDEBUG // Release mode
static constexpr quill::LogLevel DEFAULT_LOG_LEVEL = quill::LogLevel::Info;
Expand Down Expand Up @@ -51,7 +50,9 @@ set_thread_name(const std::string& name)
/**
* Set up logging.
*/
void init(const std::string& log_file, quill::LogLevel log_level = DEFAULT_LOG_LEVEL);
void logging_init(
const std::string& log_file, quill::LogLevel log_level = DEFAULT_LOG_LEVEL
);
void init_file_only(
const std::string& log_file, std::uint32_t max_size_bytes,
quill::LogLevel log_level = DEFAULT_LOG_LEVEL
Expand Down Expand Up @@ -89,34 +90,34 @@ CREATE_LOG_CATEGORY(testing);
#undef CREATE_LOG_CATEGORY
// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)

} // namespace logging
} // namespace common
} // namespace nutc

// NOLINTBEGIN
#define log_bt(category, ...) \
LOG_BACKTRACE(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_BACKTRACE(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_t3(category, ...) \
LOG_TRACE_L3(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_TRACE_L3(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_t2(category, ...) \
LOG_TRACE_L2(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_TRACE_L2(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_t1(category, ...) \
LOG_TRACE_L1(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_TRACE_L1(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_d(category, ...) \
LOG_DEBUG(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_DEBUG(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_i(category, ...) \
LOG_INFO(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_INFO(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_w(category, ...) \
LOG_WARNING(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_WARNING(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_e(category, ...) \
LOG_ERROR(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_ERROR(nutc::common::get_##category##_logger(), __VA_ARGS__)

#define log_c(category, ...) \
LOG_CRITICAL(nutc::logging::get_##category##_logger(), __VA_ARGS__)
LOG_CRITICAL(nutc::common::get_##category##_logger(), __VA_ARGS__)
// NOLINTEND
12 changes: 1 addition & 11 deletions exchange/src/common/util.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "util.hpp"

#include "common/config/config.h"
#include "common/config/config.hpp"

#include <boost/algorithm/string.hpp>
#include <boost/archive/iterators/base64_from_binary.hpp>
Expand Down Expand Up @@ -67,16 +67,6 @@ get_time()
return __rdtsc();
}

std::string
get_firebase_endpoint(const std::string& params)
{
#ifdef NUTC_LOCAL_DEV
return FIREBASE_URL + params + "?ns=nutc-web-default-rtdb";
#else
return FIREBASE_URL + params;
#endif
}

std::string
to_string(Side side)
{
Expand Down
2 changes: 0 additions & 2 deletions exchange/src/common/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ order_id_t generate_order_id();
std::uint64_t get_time();
std::string trader_id(const std::string& user_id, const std::string& algo_id);

std::string get_firebase_endpoint(const std::string& params);

std::string base64_encode(const std::string& data);

std::string base64_decode(const std::string& data);
Expand Down
7 changes: 4 additions & 3 deletions exchange/src/exchange/algos/normal_mode/normal_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ NormalModeAlgoInitializer::initialize_trader_container(
glz::json_t::object_t
NormalModeAlgoInitializer::get_remote_traders()
{
const std::string endpoint = common::get_firebase_endpoint("users.json");
glz::json_t res = request_to_json("GET", endpoint);
return res.get<glz::json_t::object_t>();
throw std::runtime_error("Unimpl");
// const std::string endpoint = common::get_firebase_endpoint("users.json");
// glz::json_t res = request_to_json("GET", endpoint);
// return res.get<glz::json_t::object_t>();
}

} // namespace nutc::exchange
4 changes: 3 additions & 1 deletion exchange/src/exchange/config/dynamic/argparse.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "argparse.hpp"

#include "common/config/config.h"
#include "common/config/config.hpp"

namespace nutc::exchange {

mode
process_arguments(int argc, const char** argv)
{
using nutc::common::NUTC_VERSION;

argparse::ArgumentParser program(
"NUTC", NUTC_VERSION, argparse::default_arguments::help
);
Expand Down
4 changes: 2 additions & 2 deletions exchange/src/exchange/config/dynamic/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class Config {
get()
{
static const char* config_file_path = std::getenv("NUTC_CONFIG_FILE");
static const char* effective_path =
config_file_path ? config_file_path : DEFAULT_CONFIG_FILE;
static const std::string effective_path =
config_file_path != nullptr ? config_file_path : DEFAULT_CONFIG_FILE;

static Config instance(common::find_project_file(effective_path));
return instance;
Expand Down
Loading

0 comments on commit 2307112

Please sign in to comment.