# finished orders can never be used again
order_leaf_to_overwrite = `select order_leaf where state = 'finished' order by id asc limit 1;`
if order_leaf_to_overwrite is None:
# oldest open order is less probable to be used later? heuristic
order_leaf_to_overwrite = `select order_leaf order by id asc limit 1;`