Hello,
I'm rounding my orders based on the target USD by using the formula:
target = 28
q = target / data[symbol].Close
lot = self.Securities[symbol].SymbolProperties.LotSize
lotSize = float(lot)
quantity = lotSize * round(q / lotSize)
order = self.MarketOrder(symbol, quantity, True))
This works fine paper trading and backtesting but when I livetrade with the Bitfinex I get the error that the quantity is nor a whole multiple of UnitQuantity
2021-05-14 15:45:29 New Order Event: Time: 05/14/2021 15:45:29 OrderID: 1 EventID: 1 Symbol: LTCUSD Status: Submitted Quantity: 0.05382936 Message: Bitfinex Order Event
2021-05-14 15:45:29 New Order Event: Time: 05/14/2021 15:45:29 OrderID: 1 EventID: 2 Symbol: LTCUSD Status: Filled Quantity: 0.05382936 FillQuantity: 0.0178164415728 FillPrice: 334.51 OrderFee: 0.0360129184272 USD Message: Bitfinex Order Event Buy
2021-05-14 15:45:32 Runtime Error: InvalidOperationException : Position.Quantity must be a whole number multiple of the UnitQuantity.
at QuantConnect.Securities.Positions.Position..ctor(Symbol symbol, Decimal quantity, Decimal unitQuantity) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Securities/Positions/Position.cs:line 57
(...)
/LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Algorithm/QCAlgorithm.Trading.cs:line 190
at OnData
order = self.MarketOrder(symbol in main.py:line 330
2021-05-14 15:45:33 New order: LTCUSD quantity 0.05382936 lot 1e-08 price 352.56527
It seems the LotSize is 1e-8 and my Order is for 0.05382936 which match. I've tried rounding to 2 decimal places and 4 but same result everytime.
Can someone give a tip on how to round the position correctly? Should I be using Decimal instead of Float?
I don't need much precision on my Strategy but would like to keep it dynamic and not dependent on the symbol.
Thanks a lot!
Tiago Silva
I'm testing now buying 1 unit of NEOUSD, about 100 USD.
With fixed quantity I get error when I try the Limit Order for -1:
Position.Quantity must be a whole number multiple of the UnitQuantity. at OnData limit = self.LimitOrder(str(symbol) in main.py:line 73
Market order works fine though.
Attached backtest but it only happens when I connect to Bitfinex. Thanks
Nodeflow GmbH
Hey Tiago,
same problem here. I use a target setHoldings on Bitfinex. Backtesting works fine, but Live trading throws your error mentioned above: must be a whole number.
BTW: I am rounding the holdings to two decimals, but no effect. I am also getting the error: PositionGroup.Quantity must be a whole number.
Thanks for further help
Derek Melchin
Hi Tiago & Nodeflow,
This issue was recently resolved. Please try again. If it's still occurring, please contact support@quantconnect.com with the deployment attached.
Best,
Derek Melchin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Tiago Silva
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!