def tns_close_locked_grids(self, grid_type):
    '\n        事务对所有对锁网格进行平仓\n        :return:\n        '
    if (self.entrust != 0):
        return
    if (not self.activate_today_lock):
        return
    locked_long_grids = self.gt.get_opened_grids_within_types(direction=Direction.LONG, types=[LOCK_GRID])
    if (len(locked_long_grids) == 0):
        return
    locked_long_dict = {}
    for g in locked_long_grids:
        vt_symbol = g.snapshot.get('mi_symbol', self.vt_symbol)
        volume = (g.volume - g.traded_volume)
        locked_long_dict.update({vt_symbol: (locked_long_dict.get(vt_symbol, 0) + volume)})
        if (g.order_status or g.order_ids):
            self.write_log(u'当前对锁格:{}存在委托,不进行解锁'.format(g.to_json()))
            return
    locked_long_volume = sum(locked_long_dict.values(), 0)
    locked_short_grids = self.gt.get_opened_grids_within_types(direction=Direction.SHORT, types=[LOCK_GRID])
    if (len(locked_short_grids) == 0):
        return
    locked_short_dict = {}
    for g in locked_short_grids:
        vt_symbol = g.snapshot.get('mi_symbol', self.vt_symbol)
        volume = (g.volume - g.traded_volume)
        locked_short_dict.update({vt_symbol: (locked_short_dict.get(vt_symbol, 0) + volume)})
        if (g.order_status or g.order_ids):
            self.write_log(u'当前对锁格:{}存在委托,不进行解锁'.format(g.to_json()))
            return
    locked_short_volume = sum(locked_short_dict.values(), 0)
    self.write_log(u'多单对锁格:{}'.format([g.to_json() for g in locked_long_grids]))
    self.write_log(u'空单对锁格:{}'.format([g.to_json() for g in locked_short_grids]))
    if (locked_long_volume != locked_short_volume):
        self.write_error(u'{}对锁格多空数量不一致,不能解锁.\n多:{},\n空:{}'.format(self.strategy_name, locked_long_volume, locked_short_volume))
        return
    for (vt_symbol, volume) in locked_long_dict.items():
        pos = self.cta_engine.get_position_holding(vt_symbol, None)
        if (pos is None):
            self.write_error(u'{} 没有获取{}得持仓信息,不能解锁')
            return
        if ((pos.long_yd < volume) or (pos.short_yd < volume)):
            self.write_error(u'{}持仓昨仓多单:{},空单:{},不满足解锁数量:{}'.format(vt_symbol, pos.long_yd, pos.short_td, volume))
            return
        if ((pos.long_td > 0) or (pos.short_td > 0)):
            self.write_log(u'{}存在今多仓:{},空仓{},不满足解锁条件'.format(vt_symbol, pos.long_td, pos.short_td))
            return
        price = self.cta_engine.get_price(vt_symbol)
        if (price is None):
            self.write_error(u'{}价格不在tick_dict缓存中,不能解锁'.format(vt_symbol))
    for g in locked_long_grids:
        dist_record = dict()
        dist_record['datetime'] = self.cur_datetime
        dist_record['symbol'] = self.vt_symbol
        dist_record['price'] = self.cur_mi_price
        dist_record['volume'] = g.volume
        dist_record['operation'] = 'close lock[long]'
        self.save_dist(dist_record)
        self.write_log(u'网格 从锁仓 {}=>{}，提升止损价{}=>{}进行离场'.format(LOCK_GRID, grid_type, g.stop_price, (self.cur_99_price / 2)))
        g.type = grid_type
        g.stop_price = (self.cur_99_price / 2)
    for g in locked_short_grids:
        dist_record = dict()
        dist_record['datetime'] = self.cur_datetime
        dist_record['symbol'] = self.vt_symbol
        dist_record['price'] = self.cur_mi_price
        dist_record['volume'] = g.volume
        dist_record['operation'] = 'close lock[short]'
        self.save_dist(dist_record)
        self.write_log(u'网格 从锁仓 {}=>{}，提升止损价{}=>{}进行离场'.format(LOCK_GRID, grid_type, g.stop_price, (self.cur_99_price * 2)))
        g.type = grid_type
        g.stop_price = (self.cur_99_price * 2)
事务对所有对锁网格进行平仓
:return:
def tns_close_locked_grids(self, grid_type):
    '\n        事务对所有对锁网格进行平仓\n        :return:\n        '
    if (self.entrust != 0):
        return
    if (not self.activate_today_lock):
        return
    locked_long_grids = self.gt.get_opened_grids_within_types(direction=Direction.LONG, types=[LOCK_GRID])
    if (len(locked_long_grids) == 0):
        return
    locked_long_dict = {}
    for g in locked_long_grids:
        vt_symbol = g.snapshot.get('mi_symbol', self.vt_symbol)
        volume = (g.volume - g.traded_volume)
        locked_long_dict.update({vt_symbol: (locked_long_dict.get(vt_symbol, 0) + volume)})
        if (g.order_status or g.order_ids):
            self.write_log(u'当前对锁格:{}存在委托,不进行解锁'.format(g.to_json()))
            return
    locked_long_volume = sum(locked_long_dict.values(), 0)
    locked_short_grids = self.gt.get_opened_grids_within_types(direction=Direction.SHORT, types=[LOCK_GRID])
    if (len(locked_short_grids) == 0):
        return
    locked_short_dict = {}
    for g in locked_short_grids:
        vt_symbol = g.snapshot.get('mi_symbol', self.vt_symbol)
        volume = (g.volume - g.traded_volume)
        locked_short_dict.update({vt_symbol: (locked_short_dict.get(vt_symbol, 0) + volume)})
        if (g.order_status or g.order_ids):
            self.write_log(u'当前对锁格:{}存在委托,不进行解锁'.format(g.to_json()))
            return
    locked_short_volume = sum(locked_short_dict.values(), 0)
    self.write_log(u'多单对锁格:{}'.format([g.to_json() for g in locked_long_grids]))
    self.write_log(u'空单对锁格:{}'.format([g.to_json() for g in locked_short_grids]))
    if (locked_long_volume != locked_short_volume):
        self.write_error(u'{}对锁格多空数量不一致,不能解锁.\n多:{},\n空:{}'.format(self.strategy_name, locked_long_volume, locked_short_volume))
        return
    for (vt_symbol, volume) in locked_long_dict.items():
        pos = self.cta_engine.get_position_holding(vt_symbol, None)
        if (pos is None):
            self.write_error(u'{} 没有获取{}得持仓信息,不能解锁')
            return
        if ((pos.long_yd < volume) or (pos.short_yd < volume)):
            self.write_error(u'{}持仓昨仓多单:{},空单:{},不满足解锁数量:{}'.format(vt_symbol, pos.long_yd, pos.short_td, volume))
            return
        if ((pos.long_td > 0) or (pos.short_td > 0)):
            self.write_log(u'{}存在今多仓:{},空仓{},不满足解锁条件'.format(vt_symbol, pos.long_td, pos.short_td))
            return
        price = self.cta_engine.get_price(vt_symbol)
        if (price is None):
            self.write_error(u'{}价格不在tick_dict缓存中,不能解锁'.format(vt_symbol))
    for g in locked_long_grids:
        dist_record = dict()
        dist_record['datetime'] = self.cur_datetime
        dist_record['symbol'] = self.vt_symbol
        dist_record['price'] = self.cur_mi_price
        dist_record['volume'] = g.volume
        dist_record['operation'] = 'close lock[long]'
        self.save_dist(dist_record)
        self.write_log(u'网格 从锁仓 {}=>{}，提升止损价{}=>{}进行离场'.format(LOCK_GRID, grid_type, g.stop_price, (self.cur_99_price / 2)))
        g.type = grid_type
        g.stop_price = (self.cur_99_price / 2)
    for g in locked_short_grids:
        dist_record = dict()
        dist_record['datetime'] = self.cur_datetime
        dist_record['symbol'] = self.vt_symbol
        dist_record['price'] = self.cur_mi_price
        dist_record['volume'] = g.volume
        dist_record['operation'] = 'close lock[short]'
        self.save_dist(dist_record)
        self.write_log(u'网格 从锁仓 {}=>{}，提升止损价{}=>{}进行离场'.format(LOCK_GRID, grid_type, g.stop_price, (self.cur_99_price * 2)))
        g.type = grid_type
        g.stop_price = (self.cur_99_price * 2)