-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
How to get notified when order can't be opened? #1216
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
Comments
It's not random. It's only when the specified relative size sums to be not even a single unit. backtesting.py/backtesting/backtesting.py Lines 945 to 955 in 1dfe96b
It's kind of like the broker refusing the order straight. I'm not sure this is in line with orders being GTC as mentioned in the docs. 🤔 What alternative do you suggest? |
The logic is good, I was just saying that it would be nice to have some kind of feedback, like: # If order size was specified proportionally,
# precompute true size in units, accounting for margin and spread/commissions
size = order.size
if -1 < size < 1:
size = copysign(int((self.margin_available * self._leverage * abs(size))
// adjusted_price_plus_commission), size)
# Not enough cash/margin even for a single unit
if not size:
# XXX: The order is canceled by the broker?
print(f'WARNING: order removed due to not sufficient margin')
self.orders.remove(order)
continue This is useful when someone is trying to backtest using limit/stop orders with a dynamic position sizing. Maybe the logic is not good and some orders does not get opened, it would be good to inform the user about that. |
Thank you so much! This is amazing. |
Hi, currently when I set a stop/limit order and the sizing of the order exceed the equity, then the order simply gets deleted when price reaches the stop/limit level, without giving any error.
... I spent like one hour trying to understand why orders gets randomly deleted when price reaches the entry levels... Some kind of alarm would be good to have, specially for those that use dynamic position sizing.
Thank's.
The text was updated successfully, but these errors were encountered: