Skip to content

Commit 18b60c4

Browse files
committed
- Introduced infrastructure interfaces and implementations for Bybit Spot and Linear markets.
- Added support for order book syncing, notifier integration, and callback registration for best bid/ask changes. - Integrated subscription builders and WebSocket sessions for order book updates. - Updated dependencies and example directories accordingly.
1 parent 9664264 commit 18b60c4

File tree

14 files changed

+827
-137
lines changed

14 files changed

+827
-137
lines changed

aoe/binance/order_book_sync/order_book_sync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "aoe/binance/session/rest/session.h"
1010
#include "aos/order_book/i_order_book.h"
1111
// #include "aos/order_book/order_book.h"
12-
#include "fmtlog.h"
1312
#include "boost/asio.hpp"
13+
#include "fmtlog.h"
1414

1515
namespace aoe {
1616
namespace binance {

aoe/bybit/constants/constants.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
#include <cstddef>
3+
4+
namespace aoe {
5+
namespace bybit {
6+
7+
constexpr std::size_t kMaximumOrderBookEventsFromExchange = 10000;
8+
// constexpr std::size_t kMaximumSnapshotEventsFromExchange = 10;
9+
10+
/// \brief Initial number of ExecutionEvent objects preallocated in the memory
11+
/// pool.
12+
///
13+
/// This value defines how many ExecutionEvent instances are initially reserved
14+
/// in the pool to reduce dynamic heap allocations during runtime.
15+
constexpr std::size_t kInitialExecutionEventPoolSize = 200;
16+
} // namespace bybit
17+
} // namespace aoe
Lines changed: 133 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,135 @@
11
#pragma once
2+
#include "aos/best_ask/best_ask.h"
3+
#include "aos/best_bid/best_bid.h"
4+
#include "aos/trading_pair/trading_pair.h"
5+
namespace aoe {
6+
namespace bybit {
7+
namespace spot {
8+
namespace main_net {
9+
class InfrastructureInterface {
10+
public:
11+
virtual ~InfrastructureInterface() = default;
12+
virtual void Register(aos::TradingPair trading_pair) = 0;
13+
};
214

3-
// namespace aoe {
4-
// namespace binance {
5-
// class InfrastructureInterface {
6-
// public:
7-
// virtual ~InfrastructureInterface() = default;
8-
// };
9-
// }; // namespace binance
10-
// }; // namespace aoe
15+
template <typename Price, typename Qty>
16+
class InfrastructureNotifierOnBestBidChangeInterface {
17+
public:
18+
virtual ~InfrastructureNotifierOnBestBidChangeInterface() = default;
19+
/**
20+
* @brief Sets a callback to be invoked on best bid changes for a trading
21+
* pair.
22+
*
23+
* If a context exists for the specified trading pair, the callback will be
24+
* registered and the method returns true. Otherwise, no callback is
25+
* registered and the method returns false.
26+
*
27+
* @param cb The callback function to be called when the best bid changes.
28+
* It receives the trading pair and the updated best bid as
29+
* arguments.
30+
* @return true if the context for the trading pair exists and the callback
31+
* was set; false otherwise.
32+
*/
33+
virtual bool SetCallbackOnBestBidChange(
34+
aos::TradingPair trading_pair,
35+
std::function<void(aos::BestBid<Price, Qty>& new_bid)> cb) = 0;
36+
};
37+
38+
template <typename Price, typename Qty>
39+
class InfrastructureNotifierOnBestAskChangeInterface {
40+
public:
41+
virtual ~InfrastructureNotifierOnBestAskChangeInterface() = default;
42+
/**
43+
* @brief Sets a callback to be invoked on best ask changes for a trading
44+
* pair.
45+
*
46+
* If a context exists for the specified trading pair, the callback will be
47+
* registered and the method returns true. Otherwise, no callback is
48+
* registered and the method returns false.
49+
*
50+
* @param cb The callback function to be called when the best ask changes.
51+
* It receives the trading pair and the updated best ask as
52+
* arguments.
53+
* @return true if the context for the trading pair exists and the callback
54+
* was set; false otherwise.
55+
*/
56+
virtual bool SetCallbackOnBestAskChange(
57+
aos::TradingPair trading_pair,
58+
std::function<void(aos::BestAsk<Price, Qty>& new_ask)> cb) = 0;
59+
};
60+
61+
template <typename Price, typename Qty>
62+
class InfrastructureNotifierInterface
63+
: public InfrastructureNotifierOnBestBidChangeInterface<Price, Qty>,
64+
public InfrastructureNotifierOnBestAskChangeInterface<Price, Qty> {
65+
public:
66+
virtual ~InfrastructureNotifierInterface() = default;
67+
};
68+
}; // namespace main_net
69+
}; // namespace spot
70+
71+
namespace linear {
72+
namespace main_net {
73+
class InfrastructureInterface {
74+
public:
75+
virtual ~InfrastructureInterface() = default;
76+
virtual void Register(aos::TradingPair trading_pair) = 0;
77+
};
78+
79+
template <typename Price, typename Qty>
80+
class InfrastructureNotifierOnBestBidChangeInterface {
81+
public:
82+
virtual ~InfrastructureNotifierOnBestBidChangeInterface() = default;
83+
/**
84+
* @brief Sets a callback to be invoked on best bid changes for a trading
85+
* pair.
86+
*
87+
* If a context exists for the specified trading pair, the callback will be
88+
* registered and the method returns true. Otherwise, no callback is
89+
* registered and the method returns false.
90+
*
91+
* @param cb The callback function to be called when the best bid changes.
92+
* It receives the trading pair and the updated best bid as
93+
* arguments.
94+
* @return true if the context for the trading pair exists and the callback
95+
* was set; false otherwise.
96+
*/
97+
virtual bool SetCallbackOnBestBidChange(
98+
aos::TradingPair trading_pair,
99+
std::function<void(aos::BestBid<Price, Qty>& new_bid)> cb) = 0;
100+
};
101+
102+
template <typename Price, typename Qty>
103+
class InfrastructureNotifierOnBestAskChangeInterface {
104+
public:
105+
virtual ~InfrastructureNotifierOnBestAskChangeInterface() = default;
106+
/**
107+
* @brief Sets a callback to be invoked on best ask changes for a trading
108+
* pair.
109+
*
110+
* If a context exists for the specified trading pair, the callback will be
111+
* registered and the method returns true. Otherwise, no callback is
112+
* registered and the method returns false.
113+
*
114+
* @param cb The callback function to be called when the best ask changes.
115+
* It receives the trading pair and the updated best ask as
116+
* arguments.
117+
* @return true if the context for the trading pair exists and the callback
118+
* was set; false otherwise.
119+
*/
120+
virtual bool SetCallbackOnBestAskChange(
121+
aos::TradingPair trading_pair,
122+
std::function<void(aos::BestAsk<Price, Qty>& new_ask)> cb) = 0;
123+
};
124+
125+
template <typename Price, typename Qty>
126+
class InfrastructureNotifierInterface
127+
: public InfrastructureNotifierOnBestBidChangeInterface<Price, Qty>,
128+
public InfrastructureNotifierOnBestAskChangeInterface<Price, Qty> {
129+
public:
130+
virtual ~InfrastructureNotifierInterface() = default;
131+
};
132+
}; // namespace main_net
133+
}; // namespace futures
134+
}; // namespace binance
135+
}; // namespace aoe

0 commit comments

Comments
 (0)