File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,9 @@ class Trader {
88
88
.def (" on_execution_updated" , &Trader::onExecutionUpdated, py::arg (" cb" ))
89
89
.def (" on_portfolio_item_updated" , &Trader::onPortfolioItemUpdated, py::arg (" cb" ))
90
90
.def (" on_portfolio_summary_updated" , &Trader::onPortfolioSummaryUpdated, py::arg (" cb" ))
91
- .def (" on_waiting_list_updated" , &Trader::onWaitingListUpdated, py::arg (" cb" ));
91
+ .def (" on_waiting_list_updated" , &Trader::onWaitingListUpdated, py::arg (" cb" ))
92
+ .def (" __enter__" , &Trader::enter, py::return_value_policy::reference)
93
+ .def (" __exit__" , &Trader::exit);
92
94
}
93
95
94
96
Trader ();
@@ -159,6 +161,10 @@ class Trader {
159
161
void onPortfolioSummaryUpdated (const std::function<void (Trader*)>& cb);
160
162
void onPortfolioItemUpdated (const std::function<void (Trader*, const std::string&)>& cb);
161
163
void onWaitingListUpdated (const std::function<void (Trader*)>& cb);
164
+ ;
165
+ // context manager methods
166
+ auto enter () -> Trader*;
167
+ auto exit (py::args args, const py::kwargs& kwargs) -> bool;
162
168
163
169
private:
164
170
shift::FIXInitiator& m_initiator;
Original file line number Diff line number Diff line change @@ -326,3 +326,14 @@ void Trader::onWaitingListUpdated(const std::function<void(Trader*)>& cb)
326
326
{
327
327
m_client->waitingListUpdatedCb = cb;
328
328
}
329
+
330
+ auto Trader::enter () -> Trader*
331
+ {
332
+ return this ;
333
+ }
334
+
335
+ auto Trader::exit (py::args args, const py::kwargs& kwargs) -> bool
336
+ {
337
+ this ->disconnect ();
338
+ return false ;
339
+ }
You can’t perform that action at this time.
0 commit comments