def init_position(self):
    '\n        初始化Positin\n        使用网格的持久化，获取开仓状态的多空单，更新\n        :return:\n        '
    self.write_log(u'init_position(),初始化持仓')
    pos_symbols = set()
    remove_ids = []
    if (len(self.gt.up_grids) <= 0):
        self.position.short_pos = 0
        short_grids = self.gt.load(direction=Direction.SHORT, open_status_filter=[True])
        if (len(short_grids) == 0):
            self.write_log(u'没有持久化的空单数据')
            self.gt.up_grids = []
        else:
            self.gt.up_grids = short_grids
            for sg in short_grids:
                if ((len(sg.order_ids) > 0) or sg.order_status):
                    self.write_log(f'重置委托状态:{sg.order_status},清除委托单：{sg.order_ids}')
                    sg.order_status = False
                    sg.order_ids = []
                short_symbol = sg.snapshot.get('mi_symbol', self.vt_symbol)
                if (sg.traded_volume > 0):
                    if (sg.open_status and (sg.volume == sg.traded_volume)):
                        msg = f'{self.strategy_name} {short_symbol}空单持仓{sg.volume},已成交:{sg.traded_volume}，不加载'
                        self.write_log(msg)
                        self.send_wechat(msg)
                        remove_ids.append(sg.id)
                        continue
                pos_symbols.add(short_symbol)
                self.write_log(u'加载持仓空单[ID:{},vt_symbol:{},价格:{}],[指数:{},价格：{}],数量:{}手'.format(sg.id, short_symbol, sg.snapshot.get('open_price'), self.idx_symbol, sg.open_price, sg.volume))
                self.position.short_pos -= sg.volume
            self.write_log(u'持久化空单，共持仓:{}手'.format(abs(self.position.short_pos)))
            if (len(remove_ids) > 0):
                self.gt.remove_grids_by_ids(direction=Direction.SHORT, ids=remove_ids)
    remove_ids = []
    if (len(self.gt.dn_grids) <= 0):
        self.position.long_pos = 0
        long_grids = self.gt.load(direction=Direction.LONG, open_status_filter=[True])
        if (len(long_grids) == 0):
            self.write_log(u'没有持久化的多单数据')
            self.gt.dn_grids = []
        else:
            self.gt.dn_grids = long_grids
            for lg in long_grids:
                if ((len(lg.order_ids) > 0) or lg.order_status):
                    self.write_log(f'重置委托状态:{lg.order_status},清除委托单：{lg.order_ids}')
                    lg.order_status = False
                    lg.order_ids = []
                long_symbol = lg.snapshot.get('mi_symbol', self.vt_symbol)
                if (lg.traded_volume > 0):
                    if (lg.open_status and (lg.volume == lg.traded_volume)):
                        msg = f'{self.strategy_name} {long_symbol}多单持仓{lg.volume},已成交:{lg.traded_volume}，不加载'
                        self.write_log(msg)
                        self.send_wechat(msg)
                        remove_ids.append(lg.id)
                        continue
                pos_symbols.add(long_symbol)
                self.write_log(u'加载持仓多单[ID:{},vt_symbol:{},价格:{}],[指数{},价格:{}],数量:{}手'.format(lg.id, long_symbol, lg.snapshot.get('open_price'), self.idx_symbol, lg.open_price, lg.volume))
                self.position.long_pos += lg.volume
            self.write_log(f'持久化多单，共持仓:{self.position.long_pos}手')
            if (len(remove_ids) > 0):
                self.gt.remove_grids_by_ids(direction=Direction.LONG, ids=remove_ids)
    self.position.pos = (self.position.long_pos + self.position.short_pos)
    self.write_log(u'{}加载持久化数据完成，多单:{}，空单:{},共:{}手'.format(self.strategy_name, self.position.long_pos, abs(self.position.short_pos), self.position.pos))
    self.pos = self.position.pos
    self.gt.save()
    self.display_grids()
    if ((len(self.vt_symbol) > 0) and (self.vt_symbol not in pos_symbols)):
        pos_symbols.add(self.vt_symbol)
    if (self.idx_symbol and (self.idx_symbol not in pos_symbols)):
        pos_symbols.add(self.idx_symbol)
    for symbol in list(pos_symbols):
        self.write_log(f'新增订阅合约:{symbol}')
        self.cta_engine.subscribe_symbol(strategy_name=self.strategy_name, vt_symbol=symbol)
初始化Positin
使用网格的持久化，获取开仓状态的多空单，更新
:return:
def init_position(self):
    '\n        初始化Positin\n        使用网格的持久化，获取开仓状态的多空单，更新\n        :return:\n        '
    self.write_log(u'init_position(),初始化持仓')
    pos_symbols = set()
    remove_ids = []
    if (len(self.gt.up_grids) <= 0):
        self.position.short_pos = 0
        short_grids = self.gt.load(direction=Direction.SHORT, open_status_filter=[True])
        if (len(short_grids) == 0):
            self.write_log(u'没有持久化的空单数据')
            self.gt.up_grids = []
        else:
            self.gt.up_grids = short_grids
            for sg in short_grids:
                if ((len(sg.order_ids) > 0) or sg.order_status):
                    self.write_log(f'重置委托状态:{sg.order_status},清除委托单：{sg.order_ids}')
                    sg.order_status = False
                    sg.order_ids = []
                short_symbol = sg.snapshot.get('mi_symbol', self.vt_symbol)
                if (sg.traded_volume > 0):
                    if (sg.open_status and (sg.volume == sg.traded_volume)):
                        msg = f'{self.strategy_name} {short_symbol}空单持仓{sg.volume},已成交:{sg.traded_volume}，不加载'
                        self.write_log(msg)
                        self.send_wechat(msg)
                        remove_ids.append(sg.id)
                        continue
                pos_symbols.add(short_symbol)
                self.write_log(u'加载持仓空单[ID:{},vt_symbol:{},价格:{}],[指数:{},价格：{}],数量:{}手'.format(sg.id, short_symbol, sg.snapshot.get('open_price'), self.idx_symbol, sg.open_price, sg.volume))
                self.position.short_pos -= sg.volume
            self.write_log(u'持久化空单，共持仓:{}手'.format(abs(self.position.short_pos)))
            if (len(remove_ids) > 0):
                self.gt.remove_grids_by_ids(direction=Direction.SHORT, ids=remove_ids)
    remove_ids = []
    if (len(self.gt.dn_grids) <= 0):
        self.position.long_pos = 0
        long_grids = self.gt.load(direction=Direction.LONG, open_status_filter=[True])
        if (len(long_grids) == 0):
            self.write_log(u'没有持久化的多单数据')
            self.gt.dn_grids = []
        else:
            self.gt.dn_grids = long_grids
            for lg in long_grids:
                if ((len(lg.order_ids) > 0) or lg.order_status):
                    self.write_log(f'重置委托状态:{lg.order_status},清除委托单：{lg.order_ids}')
                    lg.order_status = False
                    lg.order_ids = []
                long_symbol = lg.snapshot.get('mi_symbol', self.vt_symbol)
                if (lg.traded_volume > 0):
                    if (lg.open_status and (lg.volume == lg.traded_volume)):
                        msg = f'{self.strategy_name} {long_symbol}多单持仓{lg.volume},已成交:{lg.traded_volume}，不加载'
                        self.write_log(msg)
                        self.send_wechat(msg)
                        remove_ids.append(lg.id)
                        continue
                pos_symbols.add(long_symbol)
                self.write_log(u'加载持仓多单[ID:{},vt_symbol:{},价格:{}],[指数{},价格:{}],数量:{}手'.format(lg.id, long_symbol, lg.snapshot.get('open_price'), self.idx_symbol, lg.open_price, lg.volume))
                self.position.long_pos += lg.volume
            self.write_log(f'持久化多单，共持仓:{self.position.long_pos}手')
            if (len(remove_ids) > 0):
                self.gt.remove_grids_by_ids(direction=Direction.LONG, ids=remove_ids)
    self.position.pos = (self.position.long_pos + self.position.short_pos)
    self.write_log(u'{}加载持久化数据完成，多单:{}，空单:{},共:{}手'.format(self.strategy_name, self.position.long_pos, abs(self.position.short_pos), self.position.pos))
    self.pos = self.position.pos
    self.gt.save()
    self.display_grids()
    if ((len(self.vt_symbol) > 0) and (self.vt_symbol not in pos_symbols)):
        pos_symbols.add(self.vt_symbol)
    if (self.idx_symbol and (self.idx_symbol not in pos_symbols)):
        pos_symbols.add(self.idx_symbol)
    for symbol in list(pos_symbols):
        self.write_log(f'新增订阅合约:{symbol}')
        self.cta_engine.subscribe_symbol(strategy_name=self.strategy_name, vt_symbol=symbol)