Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix/only update position if order succeeded #585
Fix/only update position if order succeeded #585
Changes from all commits
777bfff
ecd1b5e
01f393c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
I remembered another thing 😅
It was on purpose that we updated the position immediately after submitting the order in case we have a closing scenarios - this update is basically what sets the button state to
Closing
in the UI so the user does not click it again.I think the best way would be updating the position to
Closing
immediately in case we are in a closing scenarios, but resetting it to open in case we fail to submit the order. I think resetting the state to open was missing, not necessarily moving the update to a later point.Sorry, I did not think about this detail yesterday.
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.
Best would be to change the state in the UI to set it to
Closing
upon clock until we get an update from the backend. But that might be a bit tricky as well :)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.
I perceive the risk from this being small: the action is swiping not just clicking and we get the success dialog in between.
(e.g. one can't fat-finger twice accidentally the same way as with buttons).
This is a shortcoming though, and I'll work to solve it!
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.
I understand that we want to check this, but for me it's unexpected that the check is happening implicitly when calling
get_position_matching_order
.I think it would be clearer if we extracted this into a separate function
does_order_close_position
and just call it if we do have an order in the database. It's two calls rather than one, but the current behaviour is surprising to me.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.
I'm happy to work on that as a follow-up.
my goal was to change as little as possible, as the previous one accidentally changed the logic during the refactor.
(including keeping the flow of error handling etc.)
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.
Fair enough. I guess now that you extracted this function it just feels weird that this new function can error like this, whereas originally it didn't bother me. It's a minor detail, specially since as you say it was already effectively the same before your changes.
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.
I agree with @luckysori that
does_order_close_position
is a better name thanget_position_matching_order
- the function was newly introduced. I think it'd be great to rename it.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.
@da-kami : @luckysori didn't want to rename this, we wanted to extract one more function, probably with
bool
return. I opted to not do this for now, out of fear of last-minute in-adverted changes to the logic.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.
Let's fix that up when we're removing
PositionState
from being stored in the db.