Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit 46d1af2

Browse files
committed
Fix connection in stream class
1 parent 0d11220 commit 46d1af2

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

xapi/XStationClientStream.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ namespace xapi
55
{
66

77
XStationClientStream::XStationClientStream(boost::asio::io_context &ioContext, const std::string &accountType, const std::string& streamSessionId)
8-
: Connection(ioContext), m_streamUrl(boost::urls::format("wss://ws.xtb.com/{}Stream", accountType)), m_streamSessionId(streamSessionId)
8+
: m_connection(std::make_unique<internals::Connection>(ioContext)), m_streamUrl(boost::urls::format("wss://ws.xtb.com/{}Stream", accountType)), m_streamSessionId(streamSessionId)
99
{
1010
}
1111

1212
boost::asio::awaitable<void> XStationClientStream::open()
1313
{
14-
co_await connect(m_streamUrl);
14+
co_await m_connection->connect(m_streamUrl);
1515
}
1616

1717
boost::asio::awaitable<void> XStationClientStream::close()
1818
{
19-
co_await disconnect();
19+
co_await m_connection->disconnect();
2020
}
2121

2222
boost::asio::awaitable<boost::json::object> XStationClientStream::listen()
2323
{
24-
auto result = co_await waitResponse();
24+
auto result = co_await m_connection->waitResponse();
2525
co_return result;
2626
}
2727

@@ -31,15 +31,15 @@ boost::asio::awaitable<void> XStationClientStream::getBalance()
3131
{"command", "getBalance"},
3232
{"streamSessionId", m_streamSessionId}
3333
};
34-
co_await makeRequest(command);
34+
co_await m_connection->makeRequest(command);
3535
}
3636

3737
boost::asio::awaitable<void> XStationClientStream::stopBalance()
3838
{
3939
boost::json::object command = {
4040
{"command", "stopBalance"}
4141
};
42-
co_await makeRequest(command);
42+
co_await m_connection->makeRequest(command);
4343
}
4444

4545
boost::asio::awaitable<void> XStationClientStream::getCandles(const std::string &symbol)
@@ -49,7 +49,7 @@ boost::asio::awaitable<void> XStationClientStream::getCandles(const std::string
4949
{"streamSessionId", m_streamSessionId},
5050
{"symbol", symbol}
5151
};
52-
co_await makeRequest(command);
52+
co_await m_connection->makeRequest(command);
5353
}
5454

5555
boost::asio::awaitable<void> XStationClientStream::stopCandles(const std::string &symbol)
@@ -58,7 +58,7 @@ boost::asio::awaitable<void> XStationClientStream::stopCandles(const std::string
5858
{"command", "stopCandles"},
5959
{"symbol", symbol}
6060
};
61-
co_await makeRequest(command);
61+
co_await m_connection->makeRequest(command);
6262
}
6363

6464
boost::asio::awaitable<void> XStationClientStream::getKeepAlive()
@@ -67,15 +67,15 @@ boost::asio::awaitable<void> XStationClientStream::getKeepAlive()
6767
{"command", "getKeepAlive"},
6868
{"streamSessionId", m_streamSessionId}
6969
};
70-
co_await makeRequest(command);
70+
co_await m_connection->makeRequest(command);
7171
}
7272

7373
boost::asio::awaitable<void> XStationClientStream::stopKeepAlive()
7474
{
7575
boost::json::object command = {
7676
{"command", "stopKeepAlive"}
7777
};
78-
co_await makeRequest(command);
78+
co_await m_connection->makeRequest(command);
7979
}
8080

8181
boost::asio::awaitable<void> XStationClientStream::getNews()
@@ -84,15 +84,15 @@ boost::asio::awaitable<void> XStationClientStream::getNews()
8484
{"command", "getNews"},
8585
{"streamSessionId", m_streamSessionId}
8686
};
87-
co_await makeRequest(command);
87+
co_await m_connection->makeRequest(command);
8888
}
8989

9090
boost::asio::awaitable<void> XStationClientStream::stopNews()
9191
{
9292
boost::json::object command = {
9393
{"command", "stopNews"}
9494
};
95-
co_await makeRequest(command);
95+
co_await m_connection->makeRequest(command);
9696
}
9797

9898
boost::asio::awaitable<void> XStationClientStream::getProfits()
@@ -101,15 +101,15 @@ boost::asio::awaitable<void> XStationClientStream::getProfits()
101101
{"command", "getProfits"},
102102
{"streamSessionId", m_streamSessionId}
103103
};
104-
co_await makeRequest(command);
104+
co_await m_connection->makeRequest(command);
105105
}
106106

107107
boost::asio::awaitable<void> XStationClientStream::stopProfits()
108108
{
109109
boost::json::object command = {
110110
{"command", "stopProfits"}
111111
};
112-
co_await makeRequest(command);
112+
co_await m_connection->makeRequest(command);
113113
}
114114

115115
boost::asio::awaitable<void> XStationClientStream::getTickPrices(const std::string &symbol, int minArrivalTime, int maxLevel)
@@ -121,7 +121,7 @@ boost::asio::awaitable<void> XStationClientStream::getTickPrices(const std::stri
121121
{"minArrivalTime", minArrivalTime},
122122
{"maxLevel", maxLevel}
123123
};
124-
co_await makeRequest(command);
124+
co_await m_connection->makeRequest(command);
125125
}
126126

127127
boost::asio::awaitable<void> XStationClientStream::stopTickPrices(const std::string &symbol)
@@ -130,7 +130,7 @@ boost::asio::awaitable<void> XStationClientStream::stopTickPrices(const std::str
130130
{"command", "stopTickPrices"},
131131
{"symbol", symbol}
132132
};
133-
co_await makeRequest(command);
133+
co_await m_connection->makeRequest(command);
134134
}
135135

136136
boost::asio::awaitable<void> XStationClientStream::getTrades()
@@ -139,15 +139,15 @@ boost::asio::awaitable<void> XStationClientStream::getTrades()
139139
{"command", "getTrades"},
140140
{"streamSessionId", m_streamSessionId}
141141
};
142-
co_await makeRequest(command);
142+
co_await m_connection->makeRequest(command);
143143
}
144144

145145
boost::asio::awaitable<void> XStationClientStream::stopTrades()
146146
{
147147
boost::json::object command = {
148148
{"command", "stopTrades"}
149149
};
150-
co_await makeRequest(command);
150+
co_await m_connection->makeRequest(command);
151151
}
152152

153153
boost::asio::awaitable<void> XStationClientStream::getTradeStatus()
@@ -156,15 +156,15 @@ boost::asio::awaitable<void> XStationClientStream::getTradeStatus()
156156
{"command", "getTradeStatus"},
157157
{"streamSessionId", m_streamSessionId}
158158
};
159-
co_await makeRequest(command);
159+
co_await m_connection->makeRequest(command);
160160
}
161161

162162
boost::asio::awaitable<void> XStationClientStream::stopTradeStatus()
163163
{
164164
boost::json::object command = {
165165
{"command", "stopTradeStatus"}
166166
};
167-
co_await makeRequest(command);
167+
co_await m_connection->makeRequest(command);
168168
}
169169

170170
boost::asio::awaitable<void> XStationClientStream::ping()
@@ -173,7 +173,7 @@ boost::asio::awaitable<void> XStationClientStream::ping()
173173
{"command", "ping"},
174174
{"streamSessionId", m_streamSessionId}
175175
};
176-
co_await makeRequest(command);
176+
co_await m_connection->makeRequest(command);
177177
}
178178

179179
} // namespace xapi

xapi/XStationClientStream.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace xapi
1919
* The XStationClientStream class provides a high-level interface for streaming real-time data
2020
* from xAPI.
2121
*/
22-
class XStationClientStream : protected internals::Connection
22+
class XStationClientStream
2323
{
2424
public:
2525
XStationClientStream() = delete;
@@ -35,7 +35,7 @@ class XStationClientStream : protected internals::Connection
3535
* @param ioContext The IO context for asynchronous operations.
3636
*/
3737
explicit XStationClientStream(boost::asio::io_context &ioContext, const std::string &accountType, const std::string& streamSessionId);
38-
~XStationClientStream() override = default;
38+
~XStationClientStream() = default;
3939

4040
/**
4141
* @brief Opens a connection to the streaming server.
@@ -95,6 +95,8 @@ class XStationClientStream : protected internals::Connection
9595
boost::asio::awaitable<void> ping();
9696

9797
private:
98+
std::unique_ptr<internals::IConnection> m_connection;
99+
98100
// The stream session ID.
99101
const boost::url m_streamUrl;
100102
const std::string m_streamSessionId;

0 commit comments

Comments
 (0)