Hi everyone, please can someone can help me find whatever (likely stupid and obvious) mistake I've made?!

I'm using self.Portfolio.MarginRemaining (and self.Portfolio.CashBook["USD"].Amount gives the same problem) to get my available USD balance, then using that to calculate a quantity for an order, but in page 30 of the orders all orders come back invalid with the following error:

"Order Error: id: 294, Insufficient buying power to complete order (Value:493.1365), Reason: Your portfolio holds 493.6146195684653 USD, 0 USD of which are reserved for open orders, but your Buy order is for 3.73107731 ETH. Your order requires a total value of 493.1364880627 USD, but only a total value of 492.8710531713554 USD is available."

Seems to me that self.Portfolio.MarginRemaining is giving the wrong value, but there's a good chance I'm missing something obvious?

I'm new to Quantconnect so this algo was supposed to be an easy exercise to get me used to the platform. I've got a bit of experience with Python from my days as an engineering student, but I'm sure that my code is somewhat lacking, so i've tried to make up for it with a tonne of comments to keep things organised.

Would really appreciate any input, either to fix the problem or just any improvements I can make to my code!

Thanks, Ben



 

Author