This is a common place to share some generally useful snippets of code you wrote. Note that indenting in code snippets is broken currently, but we are working on a fix!
Over time we will move these helper functions into the library so that you can just use them without having to copy them.
This is from Andrew Parker, instead of ordering a fixed number of shares, it orders shares for a fixed number of cash.
def order_in_cash(data, security, cash): shares = cash // data[security].price if shares < 0: shares += 1 # to fix python's flooring of negative integer division. order(security, shares)