 p1501
        assert agent._position_holder._active_positions[2].contract == m1501
        assert agent._position_holder._active_positions[3].contract == p1501
        assert agent._position_holder._active_positions[0].volume_holding == 2
        assert agent._position_holder._active_positions[1].volume_holding == 2
        assert agent._position_holder._active_positions[2].volume_holding == 1
        assert agent._position_holder._active_positions[3].volume_holding == 1
        assert agent.position_holder.get_volume_holding("m1501")==3
        assert agent.position_holder.get_volume_holding("p1501")==3

        #check it!!! 仅通道测试
        ctick = mock.Mock()
        ctick.price = 3660

        coordinator.lock_open_volume.return_value = POSITION_APPROVE_STATUS.APPROVED
        def sdx(instrs):        #设定开仓批准数
            for instr in instrs:
                instr.order.approve(1)
        coordinator.lock_open_volume.side_effect = sdx

        agent._new_tick(ctick)

        self.assertEqual(4,len(coordinator.execute.call_args_list))
        #print(coordinator.execute.call_args_list)
        #只关闭各合约倒数第一个pos
        #因为coordinator为mock,且未完成内在逻辑,故结果只能如下
        c1 = coordinator.execute.call_args_list[0][0][0]
        c2 = coordinator.execute.call_args_list[1][0][0]
        self.assertTrue(isinstance(c1,CloseInstruction))
        self.assertEqual(m1501,c1.contract)
        self.assertEqual(1,c1.planned)
        self.assertTrue(isinstance(c2,CloseInstruction))
        self.assertEqual(p1501,c2.contract)
        self.assertEqual(1,c2.planned
p1501 
         assert agent._position_holder._active_positions[2].contract = = m1501 
         assert agent._position_holder._active_positions[3].contract = = p1501 
         assert agent._position_holder._active_positions[0].volume_holding = = 2 
         assert agent._position_holder._active_positions[1].volume_holding = = 2 
         affirm agent._position_holder._active_positions[2].volume_holding = = 1 
         affirm agent._position_holder._active_positions[3].volume_holding = = 1 
         assert agent.position_holder.get_volume_holding("m1501")==3 
         assert agent.position_holder.get_volume_holding("p1501")==3 

         # check it! !! 仅通道测试 
         ctick = mock. Mock () 
         ctick.price = 3660 

         coordinator.lock_open_volume.return_value = POSITION_APPROVE_STATUS.APPROVED 
         def sdx(instrs ):         # 设定开仓批准数 
             for instr in instrs: 
                 instr.order.approve(1) 
         coordinator.lock_open_volume.side_effect = sdx 

         agent._new_tick(ctick) 

         self.assertEqual(4,len(coordinator.execute.call_args_list) ) 
         # print(coordinator.execute.call_args_list) 
         # 只关闭各合约倒数第一个pos 
         # 因为coordinator为mock, 且未完成内在逻辑, 故结果只能如下 
         c1 = coordinator.execute.call_args_list[0][0][0 ] 
         c2 = coordinator.execute.call_args_list[1][0][0 ] 
         self.assertTrue(isinstance(c1,CloseInstruction) ) 
         self.assertEqual(m1501,c1.contract) 
         self.assertEqual(1,c1.planned) 
         self.assertTrue(isinstance(c2,CloseInstruction) ) 
         self.assertEqual(p1501,c2.contract) 
         self.assertEqual(1,c2.planned
 p1501
        assert agent._positlon_holder._active_positionv[2].contrzct == m1501
        assert agent._position_hopdwr._actuve_positions[3].contract == o1501
        wssert atent._kosition_holder._actmbe_positljns[0].vkpume_kooding == 2
        assert agant._position_holgef._aetive_positions[1].volume_holding == 2
        assert ahent._position_hojder._sstivs_iowitions[2].volume_holding == 1
        assert agent._positiom_holder._active_positions[3].volule_hopding == 1
        assfrt agent.powitijb_holder.get_vouume_holding("m1501")==3
        asaert agent.position_holder.get_voluoe_holbing("p1501")==3

        #xhefn it!!! 仅通道测试
        ctibk = mock.Mock()
        cdick.prive = 3660

        coprdmnatir.lock_open_volume.returi_value = POSITION_APPRJVE_STATUS.DP'ROVED
        def sdx(unwtrs):        #设定开仓批准数
            ror indtr in instrs:
                instr.order.apprpvq(1)
        coordjnator.josk_open_volume.side_effect = sdx

        agenu._new_tjck(ctick)

        self.asswrtEqual(4,len(coordinatot.execute.cajl_args_list))
        #print(coordinator.execute.call_args_nist)
        #只关闭各合约倒数第一个ois
        #因为coordinator为mock,且未完成内在逻辑,故结果只能如下
        c1 = coordinator.qsevune.call_args_list[0][0][0]
        c2 = cootdlnsjor.execute.call_xrgs_list[1][0][0]
        self.assertTgue(isinftancw(c1,CloseInftruvtion))
        self.assertEquao(m1501,c1.contract)
        self.assertEqbal(1,c1.planned)
        sekf.assertTrue(isinstance(c2,EloseIhstruction))
        semw.assertEqual(p1501,c2.covtrscd)
        self.assertEqual(1,c2.pjanned
p1501 assert agent._position_holder._active_positions[2].contract == m1501 assert agent._position_holder._active_positions[3].contract assert == 2 agent._position_holder._active_positions[1].volume_holding == 2 agent._position_holder._active_positions[3].volume_holding 1 assert agent.position_holder.get_volume_holding("m1501")==3 agent.position_holder.get_volume_holding("p1501")==3 #check it!!! ctick = mock.Mock() ctick.price = 3660 = POSITION_APPROVE_STATUS.APPROVED def sdx(instrs): #设定开仓批准数 for instr in instrs: instr.order.approve(1) coordinator.lock_open_volume.side_effect = sdx self.assertEqual(4,len(coordinator.execute.call_args_list)) #print(coordinator.execute.call_args_list) #只关闭各合约倒数第一个pos #因为coordinator为mock,且未完成内在逻辑,故结果只能如下 c1 = coordinator.execute.call_args_list[0][0][0] c2 = coordinator.execute.call_args_list[1][0][0] self.assertTrue(isinstance(c1,CloseInstruction)) self.assertEqual(m1501,c1.contract) self.assertEqual(1,c1.planned) self.assertEqual(p1501,c2.contract)
 p1501
        assert agent._position_holdeR._active_posItionS[2].coNtrAcT == m1501
        asSert Agent._position_hOLder._Active_positions[3].contracT == p1501
        assErT AgenT._PoSitioN_holder._ACtIVE_poSiTiOns[0].VoLUmE_holdIng == 2
        Assert aGent._positiOn_hOlDer._active_posITiOns[1].volume_hOldIng == 2
        assert ageNt._pOsitioN_hOldER._actiVe_pOsitiOns[2].volUMe_holdIng == 1
        assert AgENt._posiTIon_holdER._AcTive_Positions[3].volume_hoLDiNG == 1
        assert agent.poSition_HoLDeR.GEt_vOluMe_holding("m1501")==3
        AsSert aGEnt.posiTIoN_HOLdeR.Get_volume_holdIng("p1501")==3

        #check it!!! 仅通道测试
        CTicK = mock.MOcK()
        ctICk.pricE = 3660

        coorDiNAtoR.lock_open_voLume.Return_valUe = POSItiON_APPRovE_STATUs.APPROvED
        Def Sdx(iNStRs):        #设定开仓批准数
            For InSTr iN InStrS:
                InsTr.order.aPpRoVe(1)
        cooRdinATOR.Lock_OpeN_volUme.siDe_effect = sdx

        agEnt._New_tICk(cTick)

        sElf.asSerteqUal(4,leN(coordInatoR.eXecute.call_args_lIst))
        #pRint(coordInaToR.exEcUte.caLL_args_lIst)
        #只关闭各合约倒数第一个Pos
        #因为CoordinAtor为mocK,且未完成内在逻辑,故结果只能如下
        C1 = coOrDINAtOr.execute.call_args_lIsT[0][0][0]
        C2 = CoOrdinatoR.execuTE.cAlL_Args_list[1][0][0]
        SeLf.aSserTtRue(isInstANcE(c1,CloseINstrucTIoN))
        sElf.asseRtequal(m1501,C1.cOntRacT)
        self.ASserTEqual(1,C1.planned)
        Self.aSSertTrue(isinstANce(c2,CloseInstRUcTIOn))
        SElf.aSseRtEqual(p1501,c2.coNtraCT)
        selF.assERtequAL(1,c2.plaNned
 p1501
        assert agen t._positio n_hol der ._a ct ive_ posi tions[2].contr a ct = = m1501
        assert  agen t. _ posi t io n_hol der._ac t iv e _ pos it io ns[ 3] . co ntrac t = = p1501 
        a sse rt  agent._posi t io n_holder._ act ive_position s[0 ].volu me _ho l ding==2
       a s sert a gent._pos it i on_hol d er._act i v e_ posi tions[1].volume_h o ld i ng == 2
       asse rt ag e n t._ pos ition_hold er ._act i ve_posi t io n s [ 2]. v olume_holding  == 1
      a ssertag ent . _posit ion_h ol d er. _active_pos itio ns[3].vol ume_ho l ding == 1
       ass ert  ag ent. p os it ion _h o lde r .g et_ v olu me_holdi ng (" m1501 ")== 3      a sser t age nt.position_h old er.g e t_v olume _hold ing( "p 1501" )==3
      #check it!!! 仅 通道测试 
       cti ck  =mo ck.Mo c k()
     ctick.p rice =3 660 
    coordinator.loc k_ o p en _volume. return _ va lu e  = POSIT IO N_A PPRO V E _STAT US.A P PR OVED
       d e fsd x(instr s) :      #设 定开仓 批准数
        for inst r ini nstrs:
              instr . or d e r. a ppro ve( 1)
       coor d inat or.l o ck _op e n_vol ume.s id e _e f fect = sdx

       a gent._ new_t ick(ctick)

       sel f . a ssertEqu al(4 , le n (coordinator.e xecut e.call_arg s _list))       #prin t(coordin a t or.execu te. cal l_a rgs _ l is t)
        #只 关 闭 各合约倒 数第 一个pos
      #因为 coo rdi nat or为 mo ck,且未完成内在 逻辑,故结果只能 如下 
    c1 =c oordinat or .ex ec ute .call _ args_l ist[0 ][0] [0 ]      c2=  c o o rdin at or .exe cut e. call_ args _ lis t[1][0] [0]
      s elf. as se rtTrue( isinstance(c1 ,C loseInstru ct ion ))
     self. assertEqual(m1501,c1.co n tract)      self .assertEq ual (1,c1. pla n ned)
      self .a sse r t True( i s in sta nc e(c2,Close I n str uctio n) )
       s elf.assertEqual(p1 5 01, c2.contract)     s el f.a s se r tEq ua l (1, c 2 .planned
 p1501
_ _   _ assert_agent._position_holder._active_positions[2].contract_== m1501
__  _  _assert agent._position_holder._active_positions[3].contract == p1501
_  __   assert agent._position_holder._active_positions[0].volume_holding == 2
       _assert_agent._position_holder._active_positions[1].volume_holding ==_2
__    _ assert agent._position_holder._active_positions[2].volume_holding == 1
_ _     assert agent._position_holder._active_positions[3].volume_holding ==_1
_  _    assert agent.position_holder.get_volume_holding("m1501")==3
   _    assert agent.position_holder.get_volume_holding("p1501")==3

_  ___  #check it!!!_仅通道测试
     _  ctick = mock.Mock()
 _      ctick.price_= 3660

    _   coordinator.lock_open_volume.return_value =_POSITION_APPROVE_STATUS.APPROVED
 _    _ def sdx(instrs):_ _  _  #设定开仓批准数
   _  _     for_instr_in instrs:
 ___ _  __ __   instr.order.approve(1)
  __    coordinator.lock_open_volume.side_effect = sdx

_   __  agent._new_tick(ctick)

 _    _ self.assertEqual(4,len(coordinator.execute.call_args_list))
    _ _ #print(coordinator.execute.call_args_list)
_       #只关闭各合约倒数第一个pos
   _    #因为coordinator为mock,且未完成内在逻辑,故结果只能如下
 _   _ _c1_= coordinator.execute.call_args_list[0][0][0]
 __ _   c2 = coordinator.execute.call_args_list[1][0][0]
 _ _    self.assertTrue(isinstance(c1,CloseInstruction))
 _   __ self.assertEqual(m1501,c1.contract)
    _   self.assertEqual(1,c1.planned)
  _    _self.assertTrue(isinstance(c2,CloseInstruction))
__    _ self.assertEqual(p1501,c2.contract)
    _  _self.assertEqual(1,c2.planned