I recent developed a trading stratagy which has performed well within the quantConnect enviornment, and within quantConnect Live Paper trading. A main part of the stratagy requires issueing orders once every couple of seconds or so. So I then went to try running it on alpaca where I plan to actually run the code due to their 0 brokerage fee. However, when running it on alpaca paper account through QuantConnect, after 1 Order I get hit with the error:

Order Error: Insufficient buying power to complete order (Value:89738.84), Reason: Id: 4, Initial Margin: 89738.84, Free Margin: 10258.79

Where the Initial Margin Value is the value traded in the order. Looking on alpaca the first order successfully bought and sold.

It seems to me like that initial margin can't then be touched for a while, I can't trade with it. Any ideas as to why this might be?

I'm current using this as my buy command:

self.SetHoldings(stockToBuy, .9, True) 

Which I believe buys 90% of the selected stock

and this command to sell:

self.Liquidate(stockToSell)

Which I believe sells all stocks and cancels all order.

 

I'm fairly new to algo trading so any advice would be much appriciated.
Thanks!

Author