why inspect is used in update_position func
chloe-wang opened this issue · 4 comments
hi, just want to know why we are using inspect in update_position func in position_handler.py? Any response will be appreciated!
Hi @chloe-wang,
Thank you for your question. Here is the particular code in question: https://github.com/mhallsmoore/qstrader/blob/master/qstrader/broker/portfolio/position_handler.py#L45-L68
From what I can recall it was coded this way to avoid a lot of repetitive code of the following type, especially as more attributes were added to the Position
:
if quantity is not None:
position.quantity = quantity
if current_price is not None:
position.current_price = current_price
..
..
However, in retrospect the code intent is probably a little unclear. It may be worth a refactor in the future!
Kind regards,
Mike.
hi @mhallsmoore :
Thanks for the quick reply. Yes I kind of getting the idea of using inspect here. Like you said, it may be worth a refactor since the task here is basically quite straightforward, but inspect is making it mysterious. Thanks again for your kind explanations, and it really helps a lot!
Hi @chloe-wang,
Just to let you know that this issue has now been fixed in the latest 0.1.4 release. Here is the appropriate commit: 7faf70c
Kind regards,
Mike.
@mhallsmoore thanks a lot.