QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.86k stars 3.27k forks source link

Add maximum order size check #6287

Open varuk opened 2 years ago

varuk commented 2 years ago

Expected Behavior

The maximum order quantity is defined by the brokerage[crypto]

Actual Behavior

we have a minimum order size but not a maximum order size[crypto]

Potential Solution

Reproducing the Problem

Place order for quantity greater than 62000 in any crypto

System Information

Checklist

Martin-Molinero commented 2 years ago

Hey @varuk!

Could you please add some basic algorithm reproducing the issue, adding the lean sys logs it would be helpful too 👍. Is this an issue only in backtesting or livetrading?

Orders blocked by Lean due to absence of a maximum order size

Mind expanding what do you mean with blocked?

Thanks!

AlexCatarino commented 2 years ago

@Martin-Molinero , the problem was raised by this community forum thread: https://www.quantconnect.com/forum/discussion/13510/crypto-live-trading-usdt-error

2022-04-13 00:00:00 :New Order Event: Time: 04/13/2022 00:00:00 OrderID: 1 EventID: 1 Symbol: SHIBUSDT Status: Invalid
Quantity: 3700611 Message: Brokerage failed to place order2022-04-13 00:00:00 :Brokerage failed to place order: 1

The maximum quantity to trade SHIBUSDT is 62,000 USDT (link): image (36)

Martin-Molinero commented 2 years ago

Got it 👍 in this case the order isn't blocked by Lean, but by the brokerage directly. What can be done here is improve the error message so that Lean can invalidate the order as not valid due to exceeding maximum order size even before it hits the brokerage, which should also happen in backtesting 💯