def handle_bar(context, bar_dict): # 开始编写你的主要的算法逻辑 # bar_dict[order_book_id] 可以拿到某个证券的bar信息 # context.portfolio 可以拿到现在的投资组合状态信息 # 使用order_shares(id_or_ins, amount)方法进行落单 # TODO: 开始编写你的算法吧! if not context.fired: # order_percent并且传入1代表买入该股票并且使其占有投资组合的100% order_percent(context.s1, 1) context.fired = True
def handle_bar(context, bar_dict): order_id = order_percent(context.s1, 0.0001, style=LimitOrder(context.limitprice)) order = get_order(order_id) order_side = SIDE.BUY if order.quantity > 0 else SIDE.SELL assert order.side == order_side assert order.order_book_id == context.s1 assert order.unfilled_quantity + order.filled_quantity == order.quantity assert order.price == context.limitprice
def handle_bar(context, bar_dict): for each in context.stocks: order_percent(each, 1)