chore(trading): refactor order status test (#5991)
This commit is contained in:
parent
0f5b712034
commit
7620f0b67d
@ -1,9 +1,14 @@
|
||||
import pytest
|
||||
from playwright.sync_api import Page, expect
|
||||
from vega_sim.service import PeggedOrder
|
||||
from vega_sim.null_service import VegaServiceNull
|
||||
from conftest import auth_setup, init_page, init_vega, risk_accepted_setup, cleanup_container
|
||||
from fixtures.market import setup_continuous_market, setup_simple_market
|
||||
from conftest import (
|
||||
auth_setup,
|
||||
init_page,
|
||||
init_vega,
|
||||
risk_accepted_setup,
|
||||
cleanup_container,
|
||||
)
|
||||
from fixtures.market import setup_continuous_market
|
||||
from actions.utils import wait_for_toast_confirmation
|
||||
|
||||
order_tab = "tab-orders"
|
||||
@ -12,37 +17,27 @@ order_tab = "tab-orders"
|
||||
@pytest.fixture(scope="module")
|
||||
def setup_environment(request, browser):
|
||||
# Initialize Vega with cleanup
|
||||
with init_vega(request) as vega_instance:
|
||||
request.addfinalizer(lambda: cleanup_container(vega_instance))
|
||||
with init_vega(request) as vega:
|
||||
request.addfinalizer(lambda: cleanup_container(vega))
|
||||
|
||||
# Setup multiple markets
|
||||
markets = {
|
||||
"market_1": setup_continuous_market(vega_instance, custom_market_name="market-1"),
|
||||
"market_2": setup_continuous_market(vega_instance, custom_market_name="market-2"),
|
||||
"market_3": setup_continuous_market(vega_instance, custom_market_name="market-3"),
|
||||
"market_4": setup_continuous_market(vega_instance, custom_market_name="market-4"),
|
||||
"market_5": setup_simple_market(vega_instance, custom_market_name="market-5"),
|
||||
}
|
||||
market_id = setup_continuous_market(vega, custom_market_name="market-1")
|
||||
|
||||
# Execute a series of orders across different markets
|
||||
# Example for market_1 orders, adjust as necessary for your test scenario
|
||||
vega_instance.submit_order(
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_1"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_SELL",
|
||||
volume=100,
|
||||
price=130,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_1"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_SELL",
|
||||
@ -50,13 +45,12 @@ def setup_environment(request, browser):
|
||||
price=88,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_1"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_SELL",
|
||||
@ -64,13 +58,12 @@ def setup_environment(request, browser):
|
||||
price=88,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_1"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_SELL",
|
||||
@ -79,40 +72,38 @@ def setup_environment(request, browser):
|
||||
wait=False,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_2"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_IOC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_BUY",
|
||||
volume=100,
|
||||
price=104,
|
||||
)
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_3"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_GTT",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_SELL",
|
||||
volume=10,
|
||||
price=120,
|
||||
expires_at=vega_instance.get_blockchain_time() + 5 * 1e9,
|
||||
expires_at=vega.get_blockchain_time() + 5 * 1e9,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
market_id=markets["market_4"],
|
||||
vega.submit_order(
|
||||
market_id=market_id,
|
||||
trading_key="Key 1",
|
||||
side="SIDE_BUY",
|
||||
order_type="TYPE_LIMIT",
|
||||
@ -121,12 +112,11 @@ def setup_environment(request, browser):
|
||||
volume=20,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
market_id=markets["market_4"],
|
||||
vega.submit_order(
|
||||
market_id=market_id,
|
||||
trading_key="Key 1",
|
||||
side="SIDE_BUY",
|
||||
order_type="TYPE_LIMIT",
|
||||
@ -135,12 +125,11 @@ def setup_environment(request, browser):
|
||||
volume=40,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
market_id=markets["market_4"],
|
||||
vega.submit_order(
|
||||
market_id=market_id,
|
||||
trading_key="Key 1",
|
||||
side="SIDE_SELL",
|
||||
order_type="TYPE_LIMIT",
|
||||
@ -149,12 +138,11 @@ def setup_environment(request, browser):
|
||||
volume=60,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
market_id=markets["market_5"],
|
||||
vega.submit_order(
|
||||
market_id=market_id,
|
||||
trading_key="Key 1",
|
||||
side="SIDE_SELL",
|
||||
order_type="TYPE_LIMIT",
|
||||
@ -164,26 +152,25 @@ def setup_environment(request, browser):
|
||||
volume=60,
|
||||
)
|
||||
|
||||
vega_instance.forward("2s")
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_2"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_SELL",
|
||||
volume=10,
|
||||
price=150,
|
||||
)
|
||||
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_2"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_SELL",
|
||||
@ -191,12 +178,12 @@ def setup_environment(request, browser):
|
||||
price=160,
|
||||
)
|
||||
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
vega_instance.submit_order(
|
||||
vega.submit_order(
|
||||
trading_key="Key 1",
|
||||
market_id=markets["market_3"],
|
||||
market_id=market_id,
|
||||
time_in_force="TIME_IN_FORCE_GTC",
|
||||
order_type="TYPE_LIMIT",
|
||||
side="SIDE_BUY",
|
||||
@ -204,19 +191,18 @@ def setup_environment(request, browser):
|
||||
price=60,
|
||||
)
|
||||
|
||||
vega_instance.wait_fn(1)
|
||||
vega_instance.wait_for_total_catchup()
|
||||
# Initialize page and setup
|
||||
|
||||
yield vega_instance, markets
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
|
||||
yield vega, market_id
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def page(setup_environment, browser, request):
|
||||
vega_instance, markets = setup_environment
|
||||
with init_page(vega_instance, browser, request) as page:
|
||||
vega, market_id = setup_environment
|
||||
with init_page(vega, browser, request) as page:
|
||||
risk_accepted_setup(page)
|
||||
auth_setup(vega_instance, page)
|
||||
auth_setup(vega, page)
|
||||
page.goto("/")
|
||||
page.get_by_test_id("All").click()
|
||||
yield page
|
||||
@ -232,22 +218,9 @@ def after_each(page: Page):
|
||||
# 7002-SORD-040 (as all the tests are about status)
|
||||
|
||||
|
||||
def test_order_sorted(page: Page):
|
||||
# 7003-MORD-002
|
||||
orders_update_date = page.locator(
|
||||
'.ag-center-cols-container [col-id="updatedAt"]'
|
||||
).all_text_contents()
|
||||
|
||||
orders_update_date_sorted = sorted(orders_update_date, reverse=True)
|
||||
|
||||
assert all([a == b for a, b in zip(orders_update_date, orders_update_date_sorted)])
|
||||
|
||||
|
||||
def test_order_status_active(page: Page):
|
||||
# 7002-SORD-041
|
||||
expect(page.locator('[row-index="2"]').first).to_contain_text(
|
||||
"market-2Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="2"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="2"]').nth(1)).to_contain_text(
|
||||
"0" + "-10" + "Limit" + "Active" + "150.00" + "GTC"
|
||||
)
|
||||
@ -255,9 +228,7 @@ def test_order_status_active(page: Page):
|
||||
|
||||
def test_status_expired(page: Page):
|
||||
# 7002-SORD-042
|
||||
expect(page.locator('[row-index="7"]').first).to_contain_text(
|
||||
"market-3Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="7"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="7"]').nth(1)).to_contain_text(
|
||||
"0" + "-10" + "Limit" + "Expired" + "120.00" + "GTT:"
|
||||
)
|
||||
@ -265,9 +236,7 @@ def test_status_expired(page: Page):
|
||||
|
||||
def test_order_status_Stopped(page: Page):
|
||||
# 7002-SORD-044
|
||||
expect(page.locator('[row-index="12"]').first).to_contain_text(
|
||||
"market-1Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="12"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="12"]').nth(1)).to_contain_text(
|
||||
"0" + "-100" + "Limit" + "Stopped" + "130.00" + "IOC"
|
||||
)
|
||||
@ -275,20 +244,17 @@ def test_order_status_Stopped(page: Page):
|
||||
|
||||
def test_order_status_partially_filled(page: Page):
|
||||
# 7002-SORD-045
|
||||
expect(page.locator('[row-index="8"]').first).to_contain_text(
|
||||
"market-2Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="8"]').nth(1)).to_contain_text(
|
||||
"99" + "+100" + "Limit" + "Partially Filled" + "104.00" + "IOC"
|
||||
page.pause()
|
||||
expect(page.locator('[row-index="10"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="10"]').nth(1)).to_contain_text(
|
||||
"1" + "-100" + "Limit" + "Partially Filled" + "88.00" + "IOC"
|
||||
)
|
||||
|
||||
|
||||
def test_order_status_filled(page: Page):
|
||||
# 7002-SORD-046
|
||||
# 7003-MORD-020
|
||||
expect(page.locator('[row-index="11"]').first).to_contain_text(
|
||||
"market-1Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="11"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="11"]').nth(1)).to_contain_text(
|
||||
"100" + "-100" + "Limit" + "Filled" + "88.00" + "GTC"
|
||||
)
|
||||
@ -297,9 +263,7 @@ def test_order_status_filled(page: Page):
|
||||
def test_order_status_rejected(page: Page):
|
||||
# 7002-SORD-047
|
||||
# 7003-MORD-018
|
||||
expect(page.locator('[row-index="9"]').first).to_contain_text(
|
||||
"market-1Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="9"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="9"]').nth(1)).to_contain_text(
|
||||
"0"
|
||||
+ "-10,000,000,000"
|
||||
@ -310,68 +274,31 @@ def test_order_status_rejected(page: Page):
|
||||
)
|
||||
|
||||
|
||||
def test_order_status_parked(page: Page):
|
||||
# 7002-SORD-048
|
||||
# 7003-MORD-016
|
||||
expect(page.locator('[row-index="3"]').first).to_contain_text(
|
||||
"market-5Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="3"]').nth(1)).to_contain_text(
|
||||
"0"
|
||||
+ "-60"
|
||||
+ "Ask + 15.00 Peg limit"
|
||||
+ "Parked"
|
||||
+ "0.00"
|
||||
+ "GTC"
|
||||
)
|
||||
|
||||
|
||||
def test_order_status_pegged_ask(page: Page):
|
||||
# 7003-MORD-016
|
||||
expect(page.locator('[row-index="4"]').first).to_contain_text(
|
||||
"market-4Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="4"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="4"]').nth(1)).to_contain_text(
|
||||
"0"
|
||||
+ "-60"
|
||||
+ "Ask + 15.00 Peg limit"
|
||||
+ "Active"
|
||||
+ "125.00"
|
||||
+ "GTC"
|
||||
"0" + "-60" + "Ask + 15.00 Peg limit" + "Active" + "125.00" + "GTC"
|
||||
)
|
||||
|
||||
|
||||
def test_order_status_pegged_bid(page: Page):
|
||||
# 7003-MORD-016
|
||||
expect(page.locator('[row-index="5"]').first).to_contain_text(
|
||||
"market-4Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="5"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="5"]').nth(1)).to_contain_text(
|
||||
"0"
|
||||
+ "+40"
|
||||
+ "Bid - 10.00 Peg limit"
|
||||
+ "Active"
|
||||
+ "85.00"
|
||||
+ "GTC"
|
||||
"0" + "+40" + "Bid - 10.00 Peg limit" + "Active" + "50.00" + "GTC"
|
||||
)
|
||||
|
||||
|
||||
def test_order_status_pegged_mid(page: Page):
|
||||
# 7003-MORD-016
|
||||
expect(page.locator('[row-index="6"]').first).to_contain_text(
|
||||
"market-4Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="6"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="6"]').nth(1)).to_contain_text(
|
||||
"0"
|
||||
+ "+20"
|
||||
+ "Mid - 5.00 Peg limit"
|
||||
+ "Active"
|
||||
+ "97.50"
|
||||
+ "GTC"
|
||||
"0" + "+20" + "Mid - 5.00 Peg limit" + "Active" + "80.00" + "GTC"
|
||||
)
|
||||
|
||||
|
||||
def test_order_amend_order(setup_environment, page:Page):
|
||||
def test_order_amend_order(setup_environment, page: Page):
|
||||
vega, markets = setup_environment
|
||||
# 7002-SORD-053
|
||||
# 7003-MORD-012
|
||||
@ -385,15 +312,13 @@ def test_order_amend_order(setup_environment, page:Page):
|
||||
wait_for_toast_confirmation(page, timeout=5000)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
expect(page.locator('[row-index="1"]').first).to_contain_text(
|
||||
"market-2Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="1"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="1"]').nth(1)).to_contain_text(
|
||||
"0" + "-15" + "Limit" + "Active" + "170.00" + "GTC"
|
||||
)
|
||||
|
||||
|
||||
def test_order_cancel_single_order(setup_environment, page:Page):
|
||||
def test_order_cancel_single_order(setup_environment, page: Page):
|
||||
vega, markets = setup_environment
|
||||
# 7003-MORD-009
|
||||
# 7003-MORD-010
|
||||
@ -403,15 +328,13 @@ def test_order_cancel_single_order(setup_environment, page:Page):
|
||||
wait_for_toast_confirmation(page, timeout=5000)
|
||||
vega.wait_fn(1)
|
||||
vega.wait_for_total_catchup()
|
||||
expect(page.locator('[row-index="0"]').first).to_contain_text(
|
||||
"market-3Futr"
|
||||
)
|
||||
expect(page.locator('[row-index="0"]').first).to_contain_text("market-1Futr")
|
||||
expect(page.locator('[row-index="0"]').nth(1)).to_contain_text(
|
||||
"0" + "+10" + "Limit" + "Cancelled" + "60.00" + "GTC"
|
||||
)
|
||||
|
||||
|
||||
def test_order_cancel_all_orders(setup_environment, page:Page):
|
||||
def test_order_cancel_all_orders(setup_environment, page: Page):
|
||||
vega, markets = setup_environment
|
||||
# 7003-MORD-009
|
||||
# 7003-MORD-010
|
||||
|
Loading…
Reference in New Issue
Block a user