Skip to content

Commit 7de5a56

Browse files
committed
Refactor code for consistency and improvements
- Renamed `ExecutionEventParserInterface` to `TradeEventParserInterface` for clarity - Made `Acceptor` constructor explicit in funding rate event handler - Simplified WebSocket error handling logic by removing redundant checks - Updated `MarketType` and `ActionType` enums to use `k` prefix (e.g., `kSpot`, `kBuy`) - Added missing `#include <cstdint>` in trading_pair_triangle.h - Improved enum formatting in `fmt::formatter` specialization - Cleaned up example main functions (removed unused args, fixed scope) - Minor code style improvements (variable naming, comments)
1 parent 66a80bf commit 7de5a56

File tree

9 files changed

+22
-27
lines changed

9 files changed

+22
-27
lines changed

aoe/binance/parser/json/ws/trade_response/i_trade_event_parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
namespace aoe {
77
namespace binance {
88
template <template <typename> typename MemoryPool, typename PositionT>
9-
class ExecutionEventParserInterface {
9+
class TradeEventParserInterface {
1010
public:
11-
virtual ~ExecutionEventParserInterface() = default;
11+
virtual ~TradeEventParserInterface() = default;
1212
using EventPtr =
1313
boost::intrusive_ptr<ExecutionEventInterface<MemoryPool, PositionT>>;
1414
virtual std::pair<bool, EventPtr> ParseAndCreate(

aoe/binance/parser/json/ws/trade_response/trade_event_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace spot {
1616
namespace impl {
1717
template <template <typename> typename MemoryPool, typename PositionT>
1818
class TradeEventParser
19-
: public ExecutionEventParserInterface<MemoryPool, PositionT> {
19+
: public TradeEventParserInterface<MemoryPool, PositionT> {
2020
using EventPtr =
2121
boost::intrusive_ptr<ExecutionEventInterface<MemoryPool, PositionT>>;
2222
using Key = std::string_view;

aoe/bybit/events_acceptor/funding_rate_event/acceptor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Acceptor
2121
bool received_snapshot_success_ = false;
2222

2323
public:
24-
Acceptor(boost::asio::thread_pool& thread_pool
25-
/*need pass entity to process funding rate event*/)
24+
explicit Acceptor(boost::asio::thread_pool& thread_pool
25+
/*need pass entity to process funding rate event*/)
2626
: strand_(boost::asio::make_strand(thread_pool)) {}
2727
~Acceptor() override = default;
2828
void OnEvent(

aoe/session/web_socket/web_socket.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,10 @@ class WebSocketSessionRW : public WebSocketSessionWritableInterface,
212212

213213
// Обрабатываем результат чтения
214214
if (read_ec) {
215-
if (read_ec == boost::asio::error::operation_aborted) {
216-
// CloseSessionFast();
217-
break;
218-
} else {
215+
if (read_ec != boost::asio::error::operation_aborted) {
219216
loge("Read error: {}", read_ec.message());
220-
// CloseSessionFast();
221-
break;
222217
}
218+
break;
223219
}
224220

225221
logi("invoke callback received_bytes:{}", n);
@@ -467,12 +463,10 @@ class WebSocketSessionW : public WebSocketSessionWritableInterface {
467463

468464
// Обрабатываем результат чтения
469465
if (read_ec) {
470-
if (read_ec == boost::asio::error::operation_aborted) {
471-
break;
472-
} else {
466+
if (read_ec != boost::asio::error::operation_aborted) {
473467
loge("Read error: {}", read_ec.message());
474-
break;
475468
}
469+
break;
476470
}
477471

478472
logi("invoke callback received_bytes:{}", n);

aos/market_type/market_type.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
namespace aos {
55
enum class MarketType : uint8_t {
6-
Spot,
7-
Margin, // Cross
8-
IsolatedMargin
6+
kSpot,
7+
kMargin, // Cross
8+
kIsolatedMargin
99
};
1010
};
1111

aos/trading_pair_triangle/trading_pair_triangle.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#pragma once
22
#include <array>
3+
#include <cstdint>
34

45
#include "aos/converters/tickers_to_trading_pair/converter.h"
56
#include "aos/market_type/market_type.h"
67
#include "aos/trading_pair/trading_pair.h"
78

89
namespace aos {
910

10-
enum class ActionType { Buy, Sell };
11+
enum class ActionType : uint8_t { kBuy, kSell };
1112

1213
struct Action {
1314
ActionType action_type;
@@ -17,11 +18,11 @@ struct Action {
1718

1819
namespace spot {
1920
inline Action Buy(TradingPair trading_pair) {
20-
return Action{ActionType::Buy, MarketType::Spot, trading_pair};
21+
return Action{ActionType::kBuy, MarketType::kSpot, trading_pair};
2122
}
2223

2324
inline Action Sell(TradingPair trading_pair) {
24-
return Action{ActionType::Sell, MarketType::Spot, trading_pair};
25+
return Action{ActionType::kSell, MarketType::kSpot, trading_pair};
2526
}
2627
} // namespace spot
2728

@@ -49,9 +50,9 @@ class fmt::formatter<aos::Action> {
4950
template <typename Context>
5051
constexpr auto format(const aos::Action& foo, Context& ctx) const {
5152
auto action_type = foo.action_type;
52-
std::string actionStr =
53-
(action_type == aos::ActionType::Buy ? "BUY" : "SELL");
54-
return fmt::format_to(ctx.out(), "{} {} on {}", actionStr,
53+
std::string action_str =
54+
(action_type == aos::ActionType::kBuy ? "BUY" : "SELL");
55+
return fmt::format_to(ctx.out(), "{} {} on {}", action_str,
5556
foo.trading_pair, foo.market_type);
5657
}
5758
};

examples/example45/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "aos/order_book_level/order_book_level.h"
1111
#include "concurrentqueue.h"
1212

13-
int main(int, char** argv) {
13+
int main(int, char**) {
1414
try {
1515
boost::asio::thread_pool thread_pool;
1616
LogPolling log_polling(thread_pool, std::chrono::microseconds(1));

examples/example46/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "aos/logger/mylog.h"
55
#include "aos/trading_pair_triangle/trading_pair_triangle.h"
66

7-
int main(int, char** argv) {
7+
int main() {
88
{
99
auto t = aos::MakeTriangle(aos::spot::Buy(aos::TradingPair::kETHUSDT),
1010
aos::spot::Sell(aos::TradingPair::kETHBTC),

examples/example47/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ void wait_for_user_input(std::promise<void>& exit_signal) {
136136

137137
int main(int, char**) {
138138
{
139-
boost::asio::thread_pool thread_pool;
140139
try {
140+
boost::asio::thread_pool thread_pool;
141141
using HashT = uint64_t;
142142
using Price = double;
143143
fmtlog::setLogLevel(fmtlog::LogLevel::DBG);

0 commit comments

Comments
 (0)