Skip to content

Commit 061b553

Browse files
committed
refactor example 40, 41
1 parent 684cf91 commit 061b553

File tree

153 files changed

+1294
-1378
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+1294
-1378
lines changed

.githooks/pre-commit

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#!/bin/sh
2+
3+
# Generate aos/aos.h
24
echo "#pragma once" > aos/aos.h
35
echo "" >> aos/aos.h
4-
find aos -type f -name "*.h" | sort | sed 's/^/#include "/; s/$/"/' >> aos/aos.h
6+
# Find all .h files in aos excluding aos/aos.h itself, sort and include them
7+
find aos -type f -name "*.h" ! -name "aos.h" | sort | sed 's/^/#include "/; s/$/"/' >> aos/aos.h
58

6-
# Добавляем изменения файла aos/aos.h в staged
9+
# Stage the updated aos/aos.h file
710
git add aos/aos.h
811

12+
# Generate aoe/aoe.h
913
echo "#pragma once" > aoe/aoe.h
1014
echo "" >> aoe/aoe.h
11-
find aoe -type f -name "*.h" | sort | sed 's/^/#include "/; s/$/"/' >> aoe/aoe.h
15+
# Find all .h files in aoe excluding aoe/aoe.h itself, sort and include them
16+
find aoe -type f -name "*.h" ! -name "aoe.h" | sort | sed 's/^/#include "/; s/$/"/' >> aoe/aoe.h
1217

13-
# Добавляем изменения файла aos/aos.h в staged
14-
git add aoe/aoe.h
18+
# Stage the updated aoe/aoe.h file
19+
git add aoe/aoe.h

CMakeLists.txt

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(CMAKE_CXX_CLANG_TIDY
88
-format-style=file
99
--extra-arg=-Wno-unknown-warning-option
1010
--extra-arg=-Wno-unused-command-line-argument
11+
-header-filter=aos.*\|aoe.*
1112
)
1213

1314
set(CLANG_TIDY_FOR_3RD_PARTY "" CACHE STRING "" FORCE)
@@ -19,6 +20,15 @@ endfunction()
1920
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API OFF)
2021
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP OFF)
2122

23+
# Установка lld как линковщика по умолчанию
24+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")
25+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
26+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fuse-ld=lld")
27+
28+
# Включение профилирования времени
29+
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CMAKE_COMMAND} -E time")
30+
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CMAKE_COMMAND} -E time")
31+
2232
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
2333

2434
include(FetchContent)
@@ -98,19 +108,12 @@ FetchContent_Declare(
98108
)
99109
FetchContent_MakeAvailable(nlohmann_json)
100110

101-
# # Fetch fmt
102-
# FetchContent_Declare(
103-
# fmt
104-
# GIT_REPOSITORY https://github.com/fmtlib/fmt.git
105-
# GIT_TAG master # or a specific commit/tag
106-
# )
107-
# FetchContent_MakeAvailable(fmt)
108-
109-
# Fetch fmtlog
111+
# Fetch fork fmtlog
112+
set(BUILD_TESTS_FMTLOG OFF CACHE BOOL "Suppressing fmtlog's tests" FORCE)
110113
FetchContent_Declare(
111114
fmtlog
112-
GIT_REPOSITORY https://github.com/MengRao/fmtlog.git
113-
GIT_TAG main # or use a stable tag/commit
115+
GIT_REPOSITORY https://github.com/linoxoidunix/fmtlog.git
116+
GIT_TAG main
114117
)
115118
FetchContent_MakeAvailable(fmtlog)
116119
include_directories(${fmtlog_SOURCE_DIR})
@@ -132,46 +135,30 @@ set_target_properties(fmt PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_FOR_3RD_PARTY}
132135
set_target_properties(fmtlog-static PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_FOR_3RD_PARTY}")
133136
set_target_properties(benchmark PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_FOR_3RD_PARTY}")
134137
set_target_properties(gtest_main PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_FOR_3RD_PARTY}")
138+
set_target_properties(gtest PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_FOR_3RD_PARTY}")
135139
set_target_properties(simdjson PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_FOR_3RD_PARTY}")
136140

137-
138-
139-
# # Загружаем Dlib
140-
# FetchContent_Declare(
141-
# dlib
142-
# GIT_REPOSITORY https://github.com/davisking/dlib.git
143-
# GIT_TAG master # Укажите нужную версию
144-
# )
145-
# FetchContent_MakeAvailable(dlib)
146-
147-
# # Загружаем Cereal
148-
# FetchContent_Declare(
149-
# cereal
150-
# GIT_REPOSITORY https://github.com/USCiLab/cereal.git
151-
# GIT_TAG v1.3.2 # или укажите нужную версию
152-
# )
153-
154-
# # Загружаем mlpack
155-
# FetchContent_Declare(
156-
# mlpack
157-
# GIT_REPOSITORY https://github.com/mlpack/mlpack.git
158-
# GIT_TAG master # или укажите конкретную версию, например v4.2.0
159-
# )
160-
161-
# # Загружаем зависимости для mlpack
162141
# set(DOWNLOAD_DEPENDENCIES ON CACHE BOOL "Download dependencies for mlpack")
163142

164-
# Загружаем все зависимости
165-
# FetchContent_MakeAvailable(cereal)
166-
# FetchContent_MakeAvailable(mlpack)
167-
168143
set_target_properties(gtest PROPERTIES FOLDER "Hide3rdPartyLibrary")
169144
set_target_properties(gtest_main PROPERTIES FOLDER "Hide3rdPartyLibrary")
170145
set_target_properties(gmock PROPERTIES FOLDER "Hide3rdPartyLibrary")
171146
set_target_properties(gmock_main PROPERTIES FOLDER "Hide3rdPartyLibrary")
147+
set_target_properties(fmt PROPERTIES FOLDER "Hide3rdPartyLibrary")
148+
set_target_properties(fmtlog-static PROPERTIES FOLDER "Hide3rdPartyLibrary")
149+
set_target_properties(fmtlog-shared PROPERTIES FOLDER "Hide3rdPartyLibrary")
150+
set_target_properties(simdjson PROPERTIES FOLDER "Hide3rdPartyLibrary")
151+
set_target_properties(benchmark PROPERTIES FOLDER "Hide3rdPartyLibrary")
152+
set_target_properties(benchmark_main PROPERTIES FOLDER "Hide3rdPartyLibrary")
172153

173154
set_target_properties(magic_enum PROPERTIES EXCLUDE_FROM_ALL TRUE)
174155
set_target_properties(tomlplusplus_tomlplusplus PROPERTIES EXCLUDE_FROM_ALL TRUE)
156+
set_target_properties(fmt PROPERTIES EXCLUDE_FROM_ALL TRUE)
157+
set_target_properties(fmtlog-static PROPERTIES EXCLUDE_FROM_ALL TRUE)
158+
set_target_properties(fmtlog-shared PROPERTIES EXCLUDE_FROM_ALL TRUE)
159+
set_target_properties(simdjson PROPERTIES EXCLUDE_FROM_ALL TRUE)
160+
set_target_properties(benchmark PROPERTIES EXCLUDE_FROM_ALL TRUE)
161+
set_target_properties(benchmark_main PROPERTIES EXCLUDE_FROM_ALL TRUE)
175162

176163
file(GLOB LIST_H
177164
"aos/*h"
@@ -230,3 +217,8 @@ if(BUILD_TESTS_AOS)
230217
else()
231218
message(STATUS "Tests of ${PROJECT_NAME} are skipped.")
232219
endif()
220+
221+
add_custom_target(stats
222+
COMMAND ${CMAKE_COMMAND} -E echo "=== Build statistics ==="
223+
COMMAND ${CMAKE_COMMAND} -E echo "Total build time: $<TARGET_PROPERTY:${PROJECT_NAME},TIME_BUILD>"
224+
)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
![G++](https://img.shields.io/badge/G++-14.2.0-blue)
66
![Build System](https://img.shields.io/badge/build%20system-ninja-blue?logo=ninja)
77
![License](https://img.shields.io/github/license/linoxoidunix/cryptobot_algo)
8+
![Clang-Format](https://img.shields.io/badge/style-clang--format-brightgreen)
9+
![Clang-Tidy](https://img.shields.io/badge/lint-clang--tidy-blue)
810
![Last Commit](https://img.shields.io/github/last-commit/linoxoidunix/cryptobot_algo)
911

12+
1013
## 🧩 3rd Party Libraries
1114

1215
| Library | Purpose | Link |

aoe/aoe.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#pragma once
22

3-
#include "aoe/aoe.h"
43
#include "aoe/auth/web_socket/i_auth.h"
54
#include "aoe/binance/api/external/rest/exchange_api.h"
65
#include "aoe/binance/api/external/web_socket/exchange_api_default.h"
@@ -14,6 +13,7 @@
1413
#include "aoe/binance/enums/enums.h"
1514
#include "aoe/binance/execution_event/i_types.h"
1615
#include "aoe/binance/execution_event/types.h"
16+
#include "aoe/binance/hash_utils/hash_utils.h"
1717
#include "aoe/binance/infrastructure/i_infrastructure.h"
1818
#include "aoe/binance/infrastructure/infrastructure.h"
1919
#include "aoe/binance/leaves_qty_calculator/i_leaves_qty_calculator.h"
@@ -80,13 +80,15 @@
8080
#include "aoe/bybit/api/i_exchange_api.h"
8181
#include "aoe/bybit/api/internal/exchange_api.h"
8282
#include "aoe/bybit/auth/web_socket/auth.h"
83+
#include "aoe/bybit/constants/constants.h"
8384
#include "aoe/bybit/credentials_loader/credentials_loader.h"
8485
#include "aoe/bybit/enum_printer/enum_printer.h"
8586
#include "aoe/bybit/enums/enums.h"
8687
#include "aoe/bybit/execution_event/i_types.h"
8788
#include "aoe/bybit/execution_event/types.h"
8889
#include "aoe/bybit/execution_watcher/execution_watcher.h"
8990
#include "aoe/bybit/execution_watcher/i_execution_watcher.h"
91+
#include "aoe/bybit/hash_utils/hash_utils.h"
9092
#include "aoe/bybit/infrastructure/i_infrastructure.h"
9193
#include "aoe/bybit/infrastructure/infrastructure.h"
9294
#include "aoe/bybit/order_book_event/i_order_book_event.h"

aoe/binance/api/external/rest/exchange_api.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace rest {
88
template <template <typename> typename MemoryPool>
99
class SingleOrderAPI : public SingleOrderAPIInterface<MemoryPool> {
1010
public:
11-
SingleOrderAPI() {}
11+
SingleOrderAPI() = default;
1212
void PlaceOrder(
1313
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
1414
void AmendOrder(

aoe/binance/api/external/web_socket/exchange_api_default.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ class SingleOrderAPIDefault : public SingleOrderAPIInterface<MemoryPool> {
2121
amend_order_request_maker_;
2222

2323
public:
24-
SingleOrderAPIDefault(WebSocketSessionProviderInterface<MemoryPool>&
25-
web_socket_session_provider)
24+
explicit SingleOrderAPIDefault(
25+
WebSocketSessionProviderInterface<MemoryPool>&
26+
web_socket_session_provider)
2627
: api_(web_socket_session_provider, place_order_request_maker_,
2728
cancel_order_request_maker_, amend_order_request_maker_) {}
2829
void PlaceOrder(boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>

aoe/binance/auth/web_socket/auth.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
2+
#include <cstdint>
3+
24
#include "aoe/auth/web_socket/i_auth.h"
35
#include "aoe/session/web_socket/i_web_socket.h"
46
#include "aoe/signer/ed25519/i_signer.h"
@@ -16,7 +18,7 @@ class Authentificator : public AuthInterface {
1618
: web_socket_session_(web_socket_session), signer_(signer) {}
1719
void Auth() override {
1820
auto api_key = signer_.ApiKey();
19-
long timestamp =
21+
int64_t timestamp =
2022
std::time(nullptr) * 1000; // Unix timestamp in milliseconds
2123
auto request =
2224
fmt::format("apiKey={}&timestamp={}", api_key, timestamp);

aoe/binance/credentials_loader/credentials_loader.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "aoe/credentials/api_key/i_api_key.h"
66
#include "aoe/credentials/secret_key/i_secret_key.h"
77
#include "aoe/credentials_loader/i_credentials_loader.h"
8+
#define TOML_EXCEPTIONS 0
89
#include "toml++/toml.hpp"
910

1011
namespace aoe {
@@ -15,11 +16,11 @@ class CredentialsLoader : public CredentialsLoaderInterface {
1516
bool config_loaded_ = false;
1617

1718
public:
18-
CredentialsLoader(std::string& config_path) {
19-
try {
20-
config_ = toml::parse_file(config_path);
19+
explicit CredentialsLoader(std::string& config_path) {
20+
toml::parse_result result = toml::parse_file(config_path);
21+
if (result) {
2122
config_loaded_ = true;
22-
} catch (const std::exception& e) {
23+
config_ = result.table();
2324
}
2425
};
2526
std::pair<bool, std::string_view> ApiKeyHmacSha256MainNet() override {
@@ -58,7 +59,7 @@ class CredentialsLoader : public CredentialsLoaderInterface {
5859
std::string_view key) const {
5960
if (!config_loaded_) return {false, {}};
6061

61-
auto* table = config_[group][type_key][network].as_table();
62+
const auto* table = config_[group][type_key][network].as_table();
6263
if (!table) return {false, {}};
6364

6465
const auto* value = table->get_as<std::string>(key);
@@ -73,7 +74,7 @@ class CredentialsLoader : public CredentialsLoaderInterface {
7374
std::string_view key) const {
7475
if (!config_loaded_) return {false, {}};
7576

76-
auto* table =
77+
const auto* table =
7778
config_[group][type_key][sub_type_key][network].as_table();
7879
if (!table) return {false, {}};
7980

aoe/binance/enum_printer/enum_printer.h

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ struct EnumValueWithStatus {
99
bool status;
1010
std::string_view value;
1111
};
12-
EnumValueWithStatus ExecTypeToString(ExecType execType) {
12+
13+
inline EnumValueWithStatus ExecTypeToString(ExecType execType) {
1314
switch (execType) {
1415
case ExecType::kTrade:
1516
return {true, "TRADE"};
16-
case ExecType::kUnknown:
17-
return {false, {}};
1817
default:
1918
return {false, {}}; // -1 — неизвестная ошибка
2019
}
20+
return {false, {}};
2121
};
2222

23-
EnumValueWithStatus CategoryToString(Category category) {
23+
inline EnumValueWithStatus CategoryToString(Category category) {
2424
switch (category) {
2525
case Category::kInvalid:
2626
return {false, {}};
@@ -31,9 +31,10 @@ EnumValueWithStatus CategoryToString(Category category) {
3131
default:
3232
return {false, ""};
3333
}
34+
return {false, ""};
3435
}
3536

36-
EnumValueWithStatus StopOrderTypeToString(StopOrderType stopOrderType) {
37+
inline EnumValueWithStatus StopOrderTypeToString(StopOrderType stopOrderType) {
3738
switch (stopOrderType) {
3839
case StopOrderType::kInvalid:
3940
return {false, {}};
@@ -50,7 +51,7 @@ EnumValueWithStatus StopOrderTypeToString(StopOrderType stopOrderType) {
5051
}
5152
}
5253

53-
EnumValueWithStatus OrderStatusToString(OrderStatus orderStatus) {
54+
inline EnumValueWithStatus OrderStatusToString(OrderStatus orderStatus) {
5455
switch (orderStatus) {
5556
case OrderStatus::kInvalid:
5657
return {false, {}};
@@ -77,7 +78,7 @@ EnumValueWithStatus OrderStatusToString(OrderStatus orderStatus) {
7778
}
7879
}
7980

80-
EnumValueWithStatus SideToString(Side side) {
81+
inline EnumValueWithStatus SideToString(Side side) {
8182
switch (side) {
8283
case Side::kInvalid:
8384
return {false, {}};
@@ -90,7 +91,7 @@ EnumValueWithStatus SideToString(Side side) {
9091
}
9192
}
9293

93-
EnumValueWithStatus OrderModeToString(OrderMode orderMode) {
94+
inline EnumValueWithStatus OrderModeToString(OrderMode orderMode) {
9495
switch (orderMode) {
9596
case OrderMode::kInvalid:
9697
return {false, {}};
@@ -103,7 +104,7 @@ EnumValueWithStatus OrderModeToString(OrderMode orderMode) {
103104
}
104105
}
105106

106-
EnumValueWithStatus TimeInForceToString(TimeInForce timeInForce) {
107+
inline EnumValueWithStatus TimeInForceToString(TimeInForce timeInForce) {
107108
switch (timeInForce) {
108109
case TimeInForce::kInvalid:
109110
return {false, {}};
@@ -118,7 +119,7 @@ EnumValueWithStatus TimeInForceToString(TimeInForce timeInForce) {
118119
}
119120
}
120121

121-
EnumValueWithStatus OrderRoutingToString(OrderRouting orderRouting) {
122+
inline EnumValueWithStatus OrderRoutingToString(OrderRouting orderRouting) {
122123
switch (orderRouting) {
123124
case OrderRouting::kInternal:
124125
return {true, "Internal"};
@@ -134,7 +135,7 @@ EnumValueWithStatus OrderRoutingToString(OrderRouting orderRouting) {
134135
}
135136

136137
namespace spot {
137-
EnumValueWithStatus DepthToString(Depth depth) {
138+
inline EnumValueWithStatus DepthToString(Depth depth) {
138139
switch (depth) {
139140
case Depth::k1:
140141
return {true, "1"};
@@ -150,7 +151,8 @@ EnumValueWithStatus DepthToString(Depth depth) {
150151
};
151152
}; // namespace spot
152153
namespace spot {
153-
EnumValueWithStatus DiffUpdateSpeed_ms_ToString(DiffUpdateSpeed_ms speed) {
154+
inline EnumValueWithStatus DiffUpdateSpeed_ms_ToString(
155+
DiffUpdateSpeed_ms speed) {
154156
switch (speed) {
155157
case DiffUpdateSpeed_ms::k100:
156158
return {true, "100ms"};
@@ -163,14 +165,15 @@ EnumValueWithStatus DiffUpdateSpeed_ms_ToString(DiffUpdateSpeed_ms speed) {
163165
}; // namespace spot
164166

165167
namespace futures {
166-
EnumValueWithStatus DiffUpdateSpeed_ms_ToString(DiffUpdateSpeed_ms speed) {
168+
inline EnumValueWithStatus DiffUpdateSpeed_ms_ToString(
169+
DiffUpdateSpeed_ms speed) {
167170
switch (speed) {
168171
case DiffUpdateSpeed_ms::k100:
169172
return {true, "100ms"};
170173
case DiffUpdateSpeed_ms::k250:
171174
return {true, "250ms"};
172175
case DiffUpdateSpeed_ms::k500:
173-
return {true, "250ms"};
176+
return {true, "500ms"};
174177
default:
175178
return {false, ""};
176179
}

0 commit comments

Comments
 (0)