The call ordering for `next()` vs `notify_order()`
-
Why is
next()
called first, thennotify_order()
for the same day?Here is an example:
End of DAY1:
(1a)next()
is called.
(1b) Thennotify_order()
is called for orders from DAY0.End of DAY2:
(2a)next()
is called.
(2b) Thennotify_order()
is called for orders from DAY1.The use case I am having problem with, is that I want to sell half of my position at the end of DAY1.
But I cannot know what is the half of my position because when
next()
is called,notify_order()
has not been called yet. Due to thenotify_order()
may have successfully sold some positions from previous days.Shouldn't
notify_order()
be called first? Similar to the real world, when we make plans at the end of the day (withnext()
), we should already know what are all the successful/failed execution for that day (withnotify_order()
).Thank you.
-
I think I made a mistake. After double checking my code. It seems the ordering is correct.
It is:
End of DAY1:
(1a)notify_order()
is called for orders from DAY0.
(1b)next()
is called.End of DAY2:
(2a)notify_order()
is called for orders from DAY1.
(2b)next()
is called.Appreciate if anyone can comment on this.
Thank you.
-
Its very difficult to comment without your code. Could you please post the code. In general next () is where BT sends signal to broker instance. If you want to know number of share use self.position.size to access it..
Docs - Position
-
@kegan said in The call ordering for `next()` vs `notify_order()`:
Appreciate if anyone can comment on this.
if you prefer to trust strangers from the internet, but not to
bt
documentation or your own results, than - sequence ofnext()
andnotify_order()
calls is correct and corresponds to reality. -
@ab_trader @rajanprabu I have solved my issue. I was my mistake to begin with. I didn't check my code properly.
Thank you for taking the time to reply :-)