def short_margin_ratio(cls, strcontract): try: return cls._get_info().loc[strcontract.upper(), 'short_margin_ratio'] except KeyError: log.warn("Can't not find contract: %s" % strcontract) return 1
def update_signal(self, event): """ 处理策略函数产生的下单事件。 可能产生一系列order事件,在bar的开盘时间交易。 """ assert event.route == Event.SIGNAL new_orders = [] for order in event.orders: errmsg = self._valid_order(order) if errmsg == '': order.datetime = self._datetime new_orders.append(order) if order.side == TradeSide.OPEN: self.holding['cash'] -= \ order.order_margin(self._bars[order.contract].open) else: log.warn(errmsg) # six.print_(len(event.orders), len(new_orders)) continue self.open_orders.update(new_orders) # 改变对象的值,不改变对象地址。 self._all_orders.extend(new_orders) for order in new_orders: self.api.order(copy.deepcopy(order)) for order in new_orders: if order.side == TradeSide.CLOSE: pos = self.positions[PositionKey(order.contract, order.direction)] pos.closable -= order.quantity
def long_margin_ratio(cls, strcontract): try: ## @todo 确保CONTRACTS.csv里面没有重复的项,否则有可能返回数组. return cls._get_info().loc[strcontract.upper(), 'long_margin_ratio'] except KeyError: log.warn("Can't not find contract: %s" % strcontract) return 1
def __init__(self): self._src, type_ = get_setting_datasource() if Contract.source_type and Contract.source_type != type_: log.warn("数据源发生了切换!之前可能以另外一个数据源调用Contract.xxx") Contract.info = self._src.get_contracts() Contract.source_type = type_
def volume_multiple(cls, strcontract): try: return cls._get_info().loc[strcontract.upper(), 'volume_multiple'] except KeyError: log.warn("Can't not find contract: %s" % strcontract) return 1