I have one of my algorithms live trading right now, and it looks like there's a slight issue with the way that order_value works, and I'm wondering if there's a reasonable way of handling it.
I had $304 in my IB account, so my algorithm placed an order_value() on a symbol with $304 as the target dollar amount. However, order_value submitted the buy order as 15 shares, but by the time the order went through, the price per share went up slightly, such that the order would have cost $310 - so IB rejected the order.
In the case of my particular algorithm it doesn't really matter if a particular purchase gets rejected (since a different purchase will be attempted on the next frame), but I do worry that IB might get upset about too many rejected orders coming through, and some algorithms may be negatively impacted by this. Also, if I did have a margin account, the order would have gone through and put my account in debt.
Is there any way for Quantopian to submit the order to IB based on maximum dollar amount, rather than based on a share count? Or any way for Quantopian to at least automatically apply a limit to a fill-or-kill order so that the share price doesn't cause the purchase price to exceed the available funds? Or something I should be doing differently from the algorithm's point of view?
Also, depending on the implementation of order_value, it might be possible to bring the computation of the share count closer to the submission of the order to reduce the window of opportunity for this race condition. Obviously there's no way to solve it perfectly, but if order_value were to get the current share price as soon as possible before calculating the number of shares, that would reduce the possibility somewhat. I don't know if you're doing this already though. :)