def test_add_condition( mocker, contract: Future, order: Order, touch_order: TouchOrderExecutor, code: str ): touch_order.contracts = {"TXFC0": contract["TXFC0"], "TXFD0": contract["TXFC0"]} store_cond = StoreCond( close=PriceGap(price=10, trend="Up"), order_contract=touch_order.contracts["TXFC0"], order=order, ) condition = TouchOrderCond( touch_cmd=TouchCmd(code=code, close=Price(price=10, trend="Up")), order_cmd=OrderCmd(code="TXFC0", order=order), ) touch_order.conditions = {"TXFC0": [store_cond]} touch_order.update_snapshot = mocker.MagicMock() touch_order.adjust_condition = mocker.MagicMock() touch_order.add_condition(condition) touch_order.update_snapshot.assert_called_once_with( touch_order.contracts[condition.touch_cmd.code] ) touch_order.adjust_condition.assert_called_with( condition, touch_order.contracts[condition.touch_cmd.code] ) touch_order.api.quote.subscribe.assert_called_with( touch_order.contracts[condition.touch_cmd.code], quote_type="bidask" ) assert touch_order.api.quote.subscribe.call_count == 2 res = touch_order.conditions.get(condition.touch_cmd.code) assert not res == False
def test_set_price( touch_order: TouchOrderExecutor, contract: Future, price_type: PriceType, excepted: float, ): price_info = Price(price=9999.0, price_type=price_type, trend="Up") touch_order.contracts = contract res = touch_order.set_price(price_info, contract["TXFC0"]) assert res.price == dict(contract["TXFC0"]).get(excepted, price_info.price)
buy_volume=1710.0, sell_price=10451.0, sell_volume=9, volume_ratio=2.34, ) ] ) touch_order.update_snapshot(contract["TXFC0"]) if not in_infos: assert touch_order.api.snapshots.call_count == 1 testcase_adjust_condition = [ [ TouchCmd( code="TXFC0", close=Price(price=3, trend="Up", price_type="LimitDown") ), False, ], [TouchCmd(code="TXFC0", volume=Qty(qty=3)), False], [TouchCmd(code="TXFC0"), True], ] @pytest.mark.parametrize("touch_cmd, expected", testcase_adjust_condition) def test_adjust_condition( mocker, touch_order: TouchOrderExecutor, contract: Future, order: Order, touch_cmd: TouchCmd,
buy_price=10450.0, buy_volume=1710.0, sell_price=10451.0, sell_volume=9, volume_ratio=2.34, ) ]) touch_order.update_snapshot(contract["TXFC0"]) if not in_infos: assert touch_order.api.snapshots.call_count == 1 testcase_adjust_condition = [ [ TouchCmd(code="TXFC0", close=Price(price=3, trend="Up", price_type="LimitDown")), False, ], [TouchCmd(code="TXFC0", volume=Qty(qty=3)), False], [TouchCmd(code="TXFC0"), True], ] @pytest.mark.parametrize("touch_cmd, expected", testcase_adjust_condition) def test_adjust_condition( mocker, touch_order: TouchOrderExecutor, contract: Future, order: Order, touch_cmd: TouchCmd, expected: bool,