Beispiel #1
0
def test_delete_condition(
    mocker,
    contract: Future,
    order: Order,
    touch_order: TouchOrderExecutor,
    contract_code: str,
    condition_len: int,
):
    touch_order.contracts = contract
    touch_cond = TouchOrderCond(
        touch_cmd=TouchCmd(
            code="TXFC0",
            close=PriceGap(price=11.0, price_type="LimitPrice", trend="Up"),
        ),
        order_cmd=OrderCmd(code="TXFC0", order=order),
    )
    touch_order.conditions = {
        contract_code: [
            StoreCond(
                price=PriceGap(price=11.0, trend="Up"),
                order_contract=touch_order.contracts["TXFC0"],
                order=touch_cond.order_cmd.order,
                excuted=False,
            )
        ]
    }
    touch_order.adjust_condition = mocker.MagicMock(
        return_value=touch_order.conditions[contract_code][0]
    )
    touch_order.delete_condition(touch_cond)
    assert len(touch_order.conditions[contract_code]) == condition_len
Beispiel #2
0
def test_show_condition(
    contract: Future,
    order: Order,
    code: str,
    length: int,
    touch_order: TouchOrderExecutor,
):
    touch_order.conditions = {
        "TXFC0": [
            StoreCond(
                close=PriceGap(price=9928, trend="Up"),
                order_contract=contract["TXFC0"],
                order=order,
            )
        ],
        "TXFD0": [
            StoreCond(
                close=PriceGap(price=9928, trend="Up"),
                order_contract=contract["TXFC0"],
                order=order,
            )
        ],
    }
    res = len(touch_order.show_condition(code))
    assert res == length
Beispiel #3
0
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
Beispiel #4
0
def test_adjust_condition(
    mocker,
    touch_order: TouchOrderExecutor,
    contract: Future,
    order: Order,
    touch_cmd: TouchCmd,
    expected: bool,
):
    touchorder_cond = TouchOrderCond(
        touch_cmd=touch_cmd, order_cmd=OrderCmd(code="TXFC0", order=order),
    )
    touch_order.contracts = contract
    contract = touch_order.contracts["TXFC0"]
    touch_order.set_price = mocker.MagicMock(
        return_value=PriceGap(price=10, trend="Up")
    )
    res = touch_order.adjust_condition(touchorder_cond, contract) is None
    assert res == expected
Beispiel #5
0
                price=PriceGap(price=11.0, trend="Up"),
                order_contract=touch_order.contracts["TXFC0"],
                order=touch_cond.order_cmd.order,
                excuted=False,
            )
        ]
    }
    touch_order.adjust_condition = mocker.MagicMock(
        return_value=touch_order.conditions[contract_code][0]
    )
    touch_order.delete_condition(touch_cond)
    assert len(touch_order.conditions[contract_code]) == condition_len


testcase_touch = [
    ["TXFC0", PriceGap(price=9900, price_type="LimitPrice", trend="Up"), 0, 0],
    ["TXFD0", PriceGap(price=9985, price_type="LimitPrice", trend="Up"), 9986, 1],
    ["TXFD0", PriceGap(price=9985, price_type="LimitPrice", trend="Up"), 9980, 0],
]


@pytest.mark.parametrize("code, price, close_price, order_count", testcase_touch)
def test_touch_storecond(
    mocker,
    contract: Future,
    order: Order,
    touch_order: TouchOrderExecutor,
    code: str,
    price: PriceGap,
    close_price: float,
    order_count: int,
                price=PriceGap(price=11.0, trend="Up"),
                order_contract=touch_order.contracts["TXFC0"],
                order=touch_cond.order_cmd.order,
                excuted=False,
            )
        ]
    }
    touch_order.adjust_condition = mocker.MagicMock(
        return_value=touch_order.conditions[contract_code][0])
    touch_order.delete_condition(touch_cond)
    assert len(touch_order.conditions[contract_code]) == condition_len


testcase_touch = [
    ["TXFC0",
     PriceGap(price=9900, price_type="LimitPrice", trend="Up"), 0, 0],
    [
        "TXFD0",
        PriceGap(price=9985, price_type="LimitPrice", trend="Up"), 9986, 1
    ],
    [
        "TXFD0",
        PriceGap(price=9985, price_type="LimitPrice", trend="Up"), 9980, 0
    ],
]


@pytest.mark.parametrize("code, price, close_price, order_count",
                         testcase_touch)
def test_touch_storecond(
    mocker,
Beispiel #7
0
                price=PriceGap(price=11.0, trend="Up"),
                order_contract=touch_order.contracts["TXFC0"],
                order=touch_cond.order_cmd.order,
                excuted=False,
            )
        ]
    }
    touch_order.adjust_condition = mocker.MagicMock(
        return_value=touch_order.conditions[contract_code][0])
    touch_order.delete_condition(touch_cond)
    assert len(touch_order.conditions[contract_code]) == condition_len


testcase_touch = [
    ["TXFC0",
     PriceGap(price=9900, price_type="LimitPrice", trend="Up"), 0, 0],
    [
        "TXFD0",
        PriceGap(price=9985, price_type="LimitPrice", trend="Up"), 9986, 1
    ],
    [
        "TXFD0",
        PriceGap(price=9985, price_type="LimitPrice", trend="Up"), 9980, 0
    ],
]


@pytest.mark.parametrize("code, price, close_price, order_count",
                         testcase_touch)
def test_touch(
    mocker,