My first post here so I hope this isn't a redundant question.

I have been experimenting with pairs trading and noticed that self.SetHoldings is used when there is a trigger to enter a long and short position. However, some of the stocks I am exploring are quite small and potentially illiquid. Is there a way to check whether the stock is available for shorting before executing the commend? Alternatively, is there a way to ensure long position is only entered once short is filled, otherwise it ignores the request?

 

 

elif i.touch == -1:
if i.error > i.mean_error - self.open_size*i.sd and i.last_error < i.mean_error - self.open_size*i.sd:
self.Log('long %s and short %s'%(str(i.a),str(i.b)))
self.Log('Margin remaining: '+str(self.Portfolio.MarginRemaining))
i.record_model = i.model
i.record_mean_error = i.mean_error
i.record_sd = i.sd
self.trading_pairs.append(i)
self.SetHoldings(i.a, 1.0/(len(self.selected_pair)))
self.SetHoldings(i.b, -1.0/(len(self.selected_pair)))