Skip to content

Commit 8a2d9e3

Browse files
committed
Refactor AOE headers & exchange APIs, unify interfaces, and improve io_context management
- Swap default websocket exchange_api_default.h for c_exchange_api.h across Binance & Bybit - Consolidate i_exchange_api interfaces into aoe::api/i_exchange_api and re‑export via using‑aliases - Delete redundant SingleOrderAPIDefault implementations; wire up c_exchange_api - Reorder and deduplicate #includes in aoe/aoe.h - Add Start() method to RestSessionRW and WebSocketSessionRW; switch co_spawn to detached use - Introduce executor_work_guard for io_context in Infrastructure and OrderBookInfraContextDefault to prevent run() from exiting - Move thread launch into constructor bodies (jthread default‑construct + assign in ctor) to ensure proper this initialization - Refine OrderMinQtyCalculator alignment check to use rounding - Extend Strategy & StrategyEngine interfaces with SetBidPrice/SetAskPrice and wire into implementation - Update examples (29, 30, 33, 41, CMakeLists) to use new exchange API, session Start(), and proper ioc.run() sequencing
1 parent 22accb4 commit 8a2d9e3

File tree

31 files changed

+910
-383
lines changed

31 files changed

+910
-383
lines changed

aoe/aoe.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#pragma once
22

3+
#include "aoe/api/exchange_api.h"
4+
#include "aoe/api/i_exchange_api.h"
35
#include "aoe/auth/web_socket/i_auth.h"
46
#include "aoe/binance/api/external/rest/exchange_api.h"
5-
#include "aoe/binance/api/external/web_socket/exchange_api_default.h"
7+
#include "aoe/binance/api/external/web_socket/c_exchange_api.h"
68
#include "aoe/binance/api/external/web_socket/exchange_api.h"
79
#include "aoe/binance/api/i_exchange_api.h"
810
#include "aoe/binance/api/internal/exchange_api.h"
@@ -75,7 +77,7 @@
7577
#include "aoe/binance/subscription_builder/subscription_builder_default.h"
7678
#include "aoe/binance/subscription_builder/subscription_builder.h"
7779
#include "aoe/bybit/api/external/rest/exchange_api.h"
78-
#include "aoe/bybit/api/external/web_socket/exchange_api_default.h"
80+
#include "aoe/bybit/api/external/web_socket/c_exchange_api.h"
7981
#include "aoe/bybit/api/external/web_socket/exchange_api.h"
8082
#include "aoe/bybit/api/i_exchange_api.h"
8183
#include "aoe/bybit/api/internal/exchange_api.h"

aoe/api/exchange_api.h

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#pragma once
2+
3+
#include "aoe/api/i_exchange_api.h"
4+
5+
namespace aoe::impl {
6+
7+
template <template <typename> typename MemoryPool>
8+
class PlaceOrderDummy : public aoe::PlaceOrderInterface<MemoryPool> {
9+
public:
10+
~PlaceOrderDummy() override = default;
11+
12+
/**
13+
* @brief Dummy implementation — does nothing.
14+
*
15+
* This method is intentionally left empty as this is a stub implementation
16+
* of the PlaceOrderInterface, used for testing or fallback logic.
17+
*/
18+
void PlaceOrder(
19+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
20+
};
21+
22+
template <template <typename> typename MemoryPool>
23+
class AmendOrderDummy : public aoe::AmendOrderInterface<MemoryPool> {
24+
public:
25+
~AmendOrderDummy() override = default;
26+
27+
/**
28+
* @brief Dummy implementation — does nothing.
29+
*
30+
* This method is intentionally left empty as this is a stub implementation
31+
* of the AmendOrderInterface, used for testing or fallback logic.
32+
*/
33+
void AmendOrder(
34+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
35+
};
36+
37+
template <template <typename> typename MemoryPool>
38+
class CancelOrderDummy : public aoe::CancelOrderInterface<MemoryPool> {
39+
public:
40+
~CancelOrderDummy() override = default;
41+
42+
/**
43+
* @brief Dummy implementation — does nothing.
44+
*
45+
* This method is intentionally left empty as this is a stub implementation
46+
* of the CancelOrderInterface, used for testing or fallback logic.
47+
*/
48+
void CancelOrder(
49+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
50+
};
51+
52+
template <template <typename> typename MemoryPool>
53+
class CancelAllOrderDummy : public aoe::CancelAllOrderInterface<MemoryPool> {
54+
public:
55+
~CancelAllOrderDummy() override = default;
56+
57+
/**
58+
* @brief Dummy implementation — does nothing.
59+
*
60+
* This method is intentionally left empty as this is a stub implementation
61+
* of the CancelAllOrderInterface, used for testing or fallback logic.
62+
*/
63+
void CancelAllOrder(
64+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
65+
};
66+
67+
template <template <typename> typename MemoryPool>
68+
class PlaceBatchOrderDummy : public aoe::PlaceBatchOrderInterface<MemoryPool> {
69+
public:
70+
~PlaceBatchOrderDummy() override = default;
71+
72+
/**
73+
* @brief Dummy implementation — does nothing.
74+
*
75+
* This method is intentionally left empty as this is a stub implementation
76+
* of the PlaceBatchOrderInterface, used for testing or fallback logic.
77+
*/
78+
void PlaceBatchOrder(
79+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
80+
};
81+
82+
template <template <typename> typename MemoryPool>
83+
class AmendBatchOrderDummy : public aoe::AmendBatchOrderInterface<MemoryPool> {
84+
public:
85+
~AmendBatchOrderDummy() override = default;
86+
87+
/**
88+
* @brief Dummy implementation — does nothing.
89+
*
90+
* This method is intentionally left empty as this is a stub implementation
91+
* of the AmendBatchOrderInterface, used for testing or fallback logic.
92+
*/
93+
void AmendBatchOrder(
94+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
95+
};
96+
97+
template <template <typename> typename MemoryPool>
98+
class CancelBatchOrderDummy
99+
: public aoe::CancelBatchOrderInterface<MemoryPool> {
100+
public:
101+
~CancelBatchOrderDummy() override = default;
102+
103+
/**
104+
* @brief Dummy implementation — does nothing.
105+
*
106+
* This method is intentionally left empty as this is a stub implementation
107+
* of the CancelBatchOrderInterface, used for testing or fallback logic.
108+
*/
109+
void CancelBatchOrder(
110+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
111+
};
112+
113+
template <template <typename> typename MemoryPool>
114+
class SingleOrderAPIDummy : public aoe::SingleOrderAPIInterface<MemoryPool> {
115+
public:
116+
~SingleOrderAPIDummy() override = default;
117+
118+
/**
119+
* @brief Dummy implementation — does nothing.
120+
*/
121+
void PlaceOrder(
122+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
123+
124+
/**
125+
* @brief Dummy implementation — does nothing.
126+
*/
127+
void AmendOrder(
128+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
129+
130+
/**
131+
* @brief Dummy implementation — does nothing.
132+
*/
133+
void CancelOrder(
134+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
135+
136+
/**
137+
* @brief Dummy implementation — does nothing.
138+
*/
139+
void CancelAllOrder(
140+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
141+
};
142+
143+
template <template <typename> typename MemoryPool>
144+
class BatchOrderAPIDummy : public aoe::BatchOrderAPIInterface<MemoryPool> {
145+
public:
146+
~BatchOrderAPIDummy() override = default;
147+
148+
/**
149+
* @brief Dummy implementation — does nothing.
150+
*/
151+
void PlaceBatchOrder(
152+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
153+
154+
/**
155+
* @brief Dummy implementation — does nothing.
156+
*/
157+
void AmendBatchOrder(
158+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
159+
160+
/**
161+
* @brief Dummy implementation — does nothing.
162+
*/
163+
void CancelBatchOrder(
164+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) override {}
165+
};
166+
167+
} // namespace aoe::impl

aoe/api/i_exchange_api.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#pragma once
2+
#include "aos/request/i_request.h"
3+
#include "boost/intrusive_ptr.hpp"
4+
5+
namespace aoe {
6+
template <template <typename> typename MemoryPool>
7+
class PlaceOrderInterface {
8+
public:
9+
virtual ~PlaceOrderInterface() = default;
10+
virtual void PlaceOrder(
11+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
12+
};
13+
14+
template <template <typename> typename MemoryPool>
15+
class AmendOrderInterface {
16+
public:
17+
virtual ~AmendOrderInterface() = default;
18+
virtual void AmendOrder(
19+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
20+
};
21+
22+
template <template <typename> typename MemoryPool>
23+
class CancelOrderInterface {
24+
public:
25+
virtual ~CancelOrderInterface() = default;
26+
virtual void CancelOrder(
27+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
28+
};
29+
30+
template <template <typename> typename MemoryPool>
31+
class CancelAllOrderInterface {
32+
public:
33+
virtual ~CancelAllOrderInterface() = default;
34+
virtual void CancelAllOrder(
35+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
36+
};
37+
38+
template <template <typename> typename MemoryPool>
39+
class PlaceBatchOrderInterface {
40+
public:
41+
virtual ~PlaceBatchOrderInterface() = default;
42+
virtual void PlaceBatchOrder(
43+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
44+
};
45+
46+
template <template <typename> typename MemoryPool>
47+
class AmendBatchOrderInterface {
48+
public:
49+
virtual ~AmendBatchOrderInterface() = default;
50+
virtual void AmendBatchOrder(
51+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
52+
};
53+
54+
template <template <typename> typename MemoryPool>
55+
class CancelBatchOrderInterface {
56+
public:
57+
virtual ~CancelBatchOrderInterface() = default;
58+
virtual void CancelBatchOrder(
59+
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
60+
};
61+
62+
template <template <typename> typename MemoryPool>
63+
class SingleOrderAPIInterface : public PlaceOrderInterface<MemoryPool>,
64+
public AmendOrderInterface<MemoryPool>,
65+
public CancelOrderInterface<MemoryPool>,
66+
public CancelAllOrderInterface<MemoryPool> {
67+
public:
68+
~SingleOrderAPIInterface() override = default;
69+
};
70+
71+
template <template <typename> typename MemoryPool>
72+
class BatchOrderAPIInterface : public PlaceBatchOrderInterface<MemoryPool>,
73+
public AmendBatchOrderInterface<MemoryPool>,
74+
public CancelBatchOrderInterface<MemoryPool> {
75+
public:
76+
~BatchOrderAPIInterface() override = default;
77+
};
78+
} // namespace aoe

aoe/binance/api/external/web_socket/exchange_api_default.h renamed to aoe/binance/api/external/web_socket/c_exchange_api.h

File renamed without changes.

aoe/binance/api/i_exchange_api.h

Lines changed: 13 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,20 @@
11
#pragma once
2-
#include "aos/request/i_request.h"
3-
#include "boost/intrusive_ptr.hpp"
2+
#include "aoe/api/i_exchange_api.h"
3+
// #include "aos/request/i_request.h"
4+
// #include "boost/intrusive_ptr.hpp"
5+
46
namespace aoe {
57
namespace binance {
68

7-
template <template <typename> typename MemoryPool>
8-
class PlaceOrderInterface {
9-
public:
10-
virtual ~PlaceOrderInterface() = default;
11-
virtual void PlaceOrder(
12-
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
13-
};
14-
15-
template <template <typename> typename MemoryPool>
16-
class AmendOrderInterface {
17-
public:
18-
virtual ~AmendOrderInterface() = default;
19-
virtual void AmendOrder(
20-
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
21-
};
22-
23-
template <template <typename> typename MemoryPool>
24-
class CancelOrderInterface {
25-
public:
26-
virtual ~CancelOrderInterface() = default;
27-
virtual void CancelOrder(
28-
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
29-
};
30-
31-
template <template <typename> typename MemoryPool>
32-
class CancelAllOrderInterface {
33-
public:
34-
virtual ~CancelAllOrderInterface() = default;
35-
virtual void CancelAllOrder(
36-
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
37-
};
38-
39-
template <template <typename> typename MemoryPool>
40-
class PlaceBacthOrderInterface {
41-
public:
42-
virtual ~PlaceBacthOrderInterface() = default;
43-
virtual void PlaceBatchOrder(
44-
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
45-
};
46-
47-
template <template <typename> typename MemoryPool>
48-
class AmendBatchOrderInterface {
49-
public:
50-
virtual ~AmendBatchOrderInterface() = default;
51-
virtual void AmendBatchOrder(
52-
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
53-
};
54-
55-
template <template <typename> typename MemoryPool>
56-
class CancelBatchOrderInterface {
57-
public:
58-
virtual ~CancelBatchOrderInterface() = default;
59-
virtual void CancelBatchOrder(
60-
boost::intrusive_ptr<aos::RequestInterface<MemoryPool>>) = 0;
61-
};
62-
63-
template <template <typename> typename MemoryPool>
64-
class SingleOrderAPIInterface : public PlaceOrderInterface<MemoryPool>,
65-
public AmendOrderInterface<MemoryPool>,
66-
public CancelOrderInterface<MemoryPool>,
67-
public CancelAllOrderInterface<MemoryPool> {
68-
public:
69-
virtual ~SingleOrderAPIInterface() = default;
70-
};
71-
72-
template <template <typename> typename MemoryPool>
73-
class BatchOrderAPIInterface : public PlaceBacthOrderInterface<MemoryPool>,
74-
public AmendBatchOrderInterface<MemoryPool>,
75-
public CancelBatchOrderInterface<MemoryPool> {
76-
public:
77-
virtual ~BatchOrderAPIInterface() = default;
78-
};
79-
9+
using aoe::AmendBatchOrderInterface;
10+
using aoe::AmendOrderInterface;
11+
using aoe::BatchOrderAPIInterface;
12+
using aoe::CancelAllOrderInterface;
13+
using aoe::CancelBatchOrderInterface;
14+
using aoe::CancelOrderInterface;
15+
using aoe::PlaceBatchOrderInterface;
16+
using aoe::PlaceOrderInterface;
17+
using aoe::SingleOrderAPIInterface;
8018
//--------------------------------------------------------------------------
8119
template <template <typename> typename MemoryPool>
8220
class SnapshotRequesterInterface {

0 commit comments

Comments
 (0)