-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Exchange] fix open position check and set_symbol_position_mode #807
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,4 +40,5 @@ cdef class Trader(util.Initializable): | |
cpdef object set_risk(self, object risk) | ||
cpdef object convert_order_to_trade(self, object order) | ||
|
||
cdef bint _has_open_position(self, str symbol) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember if cpdef works with any() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doenst work, I tried both cdef and cpdef There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. generators don't work with cython. We gotta consume the generator into a list and use this list into any() for it to be cythonizable. here it would mean doing this:
Not sure it's worth it though. Usually doing this is faster and cythonizable:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to your second suggestion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you want to apply those changes or should we merge like this ? |
||
# any() cant be cythonized | ||
# cdef bool _has_open_position(self, str symbol) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -677,5 +677,8 @@ def _has_open_position(self, symbol): | |
:param symbol: the position symbol | ||
:return: True if open position for :symbol: exists | ||
""" | ||
return len(self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions( | ||
symbol=symbol)) != 0 | ||
return any( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't this change break the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I get that right. As far as it looks to me, we can change the mode on an 0 size position, but we cant when size != 0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok then let's forget what i said, your change is right 💯 |
||
position.size | ||
for position in self.exchange_manager.exchange_personal_data.positions_manager.get_symbol_positions( | ||
symbol=symbol | ||
)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😮