Skip to content

Commit 45fff73

Browse files
committed
fix: clang-tidy fixed files
1 parent ea8e8c7 commit 45fff73

7 files changed

Lines changed: 42 additions & 23 deletions

File tree

src/binance/Auth.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ namespace Binance {
2121

2222
Auth::Auth(std::string &apiKey, std::string &privatePemPath)
2323
: apiKey_(apiKey), privatePemPath_(privatePemPath) {
24-
if (sodium_init() < 0) throw std::runtime_error("libsodium failed to initialize");
24+
if (sodium_init() < 0) {
25+
throw std::runtime_error("libsodium failed to initialize");
26+
}
2527
}
2628

2729
const std::string &Auth::getApiKey() const { return apiKey_; }
@@ -34,16 +36,23 @@ std::string Auth::signPayload(const std::string &payload) {
3436

3537
std::vector<unsigned char> Auth::getSeedFromPem() const {
3638
FILE *fp = fopen(privatePemPath_.c_str(), "r");
37-
if (!fp) throw std::runtime_error("Failed to open PEM file");
39+
if (fp == nullptr) {
40+
throw std::runtime_error("Failed to open PEM file");
41+
}
3842
EVP_PKEY *pkey = PEM_read_PrivateKey(fp, nullptr, nullptr, nullptr);
3943
fclose(fp);
40-
if (!pkey) throw std::runtime_error("Failed to read private key from PEM");
44+
if (pkey == nullptr) {
45+
throw std::runtime_error("Failed to read private key from PEM");
46+
}
4147

4248
size_t len = 32; // Ed25519 private key seed size
4349
std::vector<unsigned char> seed(len);
44-
if (EVP_PKEY_get_raw_private_key(pkey, seed.data(), &len) != 1)
50+
if (EVP_PKEY_get_raw_private_key(pkey, seed.data(), &len) != 1) {
4551
throw std::runtime_error("Failed to get raw private key");
46-
if (len != 32) throw std::runtime_error("Unexpected private key length");
52+
}
53+
if (len != 32) {
54+
throw std::runtime_error("Unexpected private key length");
55+
}
4756

4857
EVP_PKEY_free(pkey);
4958
return seed;
@@ -56,8 +65,9 @@ std::string Auth::signPayload(const std::string &payload,
5665
unsigned char sk[crypto_sign_SECRETKEYBYTES]; // 64 bytes
5766

5867
// Generate keypair from seed
59-
if (crypto_sign_seed_keypair(pk, sk, seed.data()) != 0)
68+
if (crypto_sign_seed_keypair(pk, sk, seed.data()) != 0) {
6069
throw std::runtime_error("Failed to generate keypair from seed");
70+
}
6171

6272
unsigned char sig[crypto_sign_BYTES];
6373
if (crypto_sign_detached(sig, nullptr,

src/binance/Config.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ std::string getEnvOrThrow(const char *key) {
2323
throw std::runtime_error(std::format("envvar not defined, key [{}]", key));
2424
};
2525

26-
// TODO: for keys, use `std::vector<unsigned char>` instead of string
26+
// TODO(mils): for keys, use `std::vector<unsigned char>` instead of string
2727

2828
/// @brief load Binance configuration from env
2929
/// (static member function)
@@ -35,7 +35,9 @@ Config Config::fromEnv() {
3535
const std::string instStr = getEnvOrThrow("SYMBOLS");
3636
std::vector<std::string> symbols;
3737
for (auto inst : std::views::split(instStr, ',')) {
38-
if (inst.size() > 0) symbols.emplace_back(inst.begin(), inst.end());
38+
if (!inst.empty()) {
39+
symbols.emplace_back(inst.begin(), inst.end());
40+
}
3941
}
4042

4143
// copy

src/binance/Worker.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Worker::Worker(std::unique_ptr<FixApp> app,
2222
std::unique_ptr<FIX::SessionSettings> settings,
2323
std::unique_ptr<FIX::FileLogFactory> fileLogFactory,
2424
std::unique_ptr<FIX::SocketInitiator> initiator,
25-
std::function<void(std::stop_token)> task)
25+
const std::function<void(std::stop_token)> &task)
2626
: app_(std::move(app)),
2727
store_(std::move(fileStoreFactory)),
2828
settings_(std::move(settings)),
@@ -31,7 +31,7 @@ Worker::Worker(std::unique_ptr<FixApp> app,
3131
workerTask_(task) {
3232
// default behaviour
3333
if (!task) {
34-
workerTask_ = ([this](std::stop_token stoken) {
34+
workerTask_ = ([this](const std::stop_token &stoken) {
3535
Utils::Threading::set_thread_name("tradercppFIX");
3636
// NB: SocketInitiator::start() is a blocking call, so the stop_token
3737
// cannot cancel the thread. NB: The `stop()` function has to forcibly
@@ -69,7 +69,9 @@ void Worker::start() {
6969

7070
void Worker::stop() {
7171
try {
72-
if (initiator_) initiator_->stop(); // TODO: does this need a try/catch?
72+
if (initiator_) {
73+
initiator_->stop(); // TODO(mils): does this need a try/catch?
74+
}
7375
spdlog::info("stopped FIX session");
7476
} catch (const std::exception &e) {
7577
spdlog::error("error stopping binance FIX session, error [{}]", e.what());

src/binance/Worker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Worker final {
2424
std::unique_ptr<FIX::SessionSettings> settings,
2525
std::unique_ptr<FIX::FileLogFactory> fileLogFactory,
2626
std::unique_ptr<FIX::SocketInitiator> initiator,
27-
std::function<void(std::stop_token)> task = {});
27+
const std::function<void(std::stop_token)> &task = {});
2828
/// @brief factory for concrete Binance instances, using config
2929
/// @param conf binance configuration parameters
3030
/// @return

src/ui/OrderBook.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ OrderBook::OrderBook(std::map<double, double, std::greater<>> bidMap,
1010
: bidMap_(std::move(bidMap)), askMap_(std::move(askMap)) {}
1111

1212
// move constructor
13-
OrderBook::OrderBook(OrderBook &&other) noexcept {
13+
OrderBook::OrderBook(OrderBook &&other) noexcept
14+
: bidMap_(std::move(other.bidMap_)), askMap_(std::move(other.askMap_)) {
1415
// lock other.mutex_ to ensure safe access to its internal maps while moving
1516
std::lock_guard lock(other.mutex_);
16-
bidMap_ = std::move(other.bidMap_);
17-
askMap_ = std::move(other.askMap_);
17+
1818
// mutex_ does not move; each instance has its own mutex
1919
}
2020

@@ -31,7 +31,7 @@ OrderBook &OrderBook::operator=(OrderBook &&other) noexcept {
3131
std::vector<BidAsk> OrderBook::toVector() {
3232
std::lock_guard lock(mutex_);
3333
const size_t rowCount = std::max(bidMap_.size(), askMap_.size());
34-
// TODO: could this be a pre-allocated/reusable vector with exactly 5000
34+
// TODO(mils): could this be a pre-allocated/reusable vector with exactly 5000
3535
// entries?
3636
std::vector<BidAsk> v(rowCount);
3737
// bids

src/ui/TableApp.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <mutex>
1414
#include <string>
1515
#include <thread>
16+
#include <utility>
1617
#include <vector>
1718

1819
#include "./../utils/Threading.h"
@@ -25,7 +26,9 @@ namespace UI {
2526

2627
// Helper to pad or truncate a string to a fixed width
2728
std::string Pad(const std::string &input, const size_t width) {
28-
if (input.size() >= width) return input.substr(0, width);
29+
if (input.size() >= width) {
30+
return input.substr(0, width);
31+
}
2932

3033
std::string result = input;
3134
result.resize(width, ' ');
@@ -91,7 +94,7 @@ TableApp::TableApp(
9194
workerTask_(std::move(task)) {
9295
// default behaviour
9396
if (!workerTask_) {
94-
workerTask_ = ([this](std::stop_token stoken) {
97+
workerTask_ = ([this](const std::stop_token &stoken) {
9598
Utils::Threading::set_thread_name("tradercppUI");
9699
pollQueue(stoken);
97100
spdlog::info("started polling queue on background thread");
@@ -101,7 +104,7 @@ TableApp::TableApp(
101104

102105
// main thread
103106
void TableApp::start() {
104-
// TODO: why does the order of these two items affect the rendered result?
107+
// TODO(mils): why does the order of these two items affect the rendered result?
105108

106109
// start worker thread
107110
worker_ = std::jthread(workerTask_);
@@ -112,7 +115,7 @@ void TableApp::start() {
112115
}
113116

114117
// worker thread
115-
void TableApp::pollQueue(std::stop_token stoken) {
118+
void TableApp::pollQueue(const std::stop_token &stoken) {
116119
try {
117120
/// Adaptive backoff strategy for spin+sleep polling
118121
/// Performs an adaptive backoff by spinning then sleeping, increasing sleep
@@ -135,7 +138,9 @@ void TableApp::pollQueue(std::stop_token stoken) {
135138
while (!stoken.stop_requested()) {
136139
std::shared_ptr<const FIX44::Message> msg;
137140
while (!queue_.try_dequeue(msg)) {
138-
if (stoken.stop_requested()) return;
141+
if (stoken.stop_requested()) {
142+
return;
143+
}
139144
adaptiveBackoff();
140145
}
141146

@@ -159,7 +164,7 @@ void TableApp::pollQueue(std::stop_token stoken) {
159164
}
160165
spdlog::info("closing worker thread...");
161166
}
162-
// TODO: log error
167+
// TODO(mils): log error
163168
catch (const std::exception &e) {
164169
spdlog::error("error in ui worker thread, error [{}]", e.what());
165170
thread_exception = std::current_exception();

src/ui/TableApp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TableApp {
4040
moodycamel::ConcurrentQueue<std::shared_ptr<const FIX44::Message>> &queue_;
4141
/// @brief poll queue for any new FIX messages, update order book
4242
/// @param stoken
43-
void pollQueue(std::stop_token stoken);
43+
void pollQueue(const std::stop_token &stoken);
4444
};
4545

4646
} // namespace UI

0 commit comments

Comments
 (0)