You have to do this:
context.long_weight = weight
context.short_weight = -weight
Or simply use:
context.weight = weight
Then, when you order the shorts, you can use:
To keep the gross leverage at 1.0, you need to consider that for less than 67 securities in your universe, you'll have a problem, since 1/66 = 0.0152 (and 1/67 = 0.0149) which is greater than your limit of 0.015, so you'd need to drop the gross leverage to less than 1.0 for less than 67 securities. For a universe of 67 or larger, if you want equal weights, then you'll always be within the limit of 0.015, and maintain a gross leverage of 1.0.
So, I'm confused what you are trying to do. If you want "even position sizing" and 0.015 max weight and gross leverage of 1.0, then it seems you are just talking about a constraint on the number of securities in your universe, right? Or am I missing something?