Fix bad-fqme test, adjust prices based on buy/sell

rekt_pps
Tyler Goodlet 2023-04-10 22:21:22 -04:00
parent 589232d12d
commit 7de914d54c
1 changed files with 33 additions and 16 deletions

View File

@ -159,21 +159,27 @@ def load_and_check_pos(
yield pp yield pp
@pytest.mark.trio def test_ems_err_on_bad_broker(
async def test_ems_err_on_bad_broker(
open_test_pikerd: Services, open_test_pikerd: Services,
loglevel: str, loglevel: str,
): ):
async def load_bad_fqme():
try: try:
async with open_ems( async with (
'doggy.smiles', open_test_pikerd() as (_, _, _, services),
open_ems(
'doggycoin.doggy',
mode='paper', mode='paper',
loglevel=loglevel, loglevel=loglevel,
) as _: ) as _
):
pytest.fail('EMS is working on non-broker!?') pytest.fail('EMS is working on non-broker!?')
except ModuleNotFoundError: except ModuleNotFoundError:
pass pass
run_and_tollerate_cancels(load_bad_fqme)
async def match_ppmsgs_on_ems_boot( async def match_ppmsgs_on_ems_boot(
ppmsgs: list[BrokerdPosition], ppmsgs: list[BrokerdPosition],
@ -264,12 +270,14 @@ async def submit_and_check(
od: dict od: dict
for od in fills: for od in fills:
print(f'Sending order {od} for fill') print(f'Sending order {od} for fill')
size = od['size']
sent, msgs = await order_and_and_wait_for_ppmsg( sent, msgs = await order_and_and_wait_for_ppmsg(
client, client,
trades_stream, trades_stream,
fqme, fqme,
action='buy', action='buy' if size > 0 else 'sell',
size=od['size'], price=100e3 if size > 0 else 0,
size=size,
) )
last_order: Order = sent[-1] last_order: Order = sent[-1]
@ -300,7 +308,8 @@ async def submit_and_check(
{'size': 0.001}, {'size': 0.001},
), ),
# multi-partial entry and exits. # multi-partial entry and exits from net-zero, to short and back
# to net-zero.
( (
# enters # enters
{'size': 0.001}, {'size': 0.001},
@ -314,10 +323,18 @@ async def submit_and_check(
{'size': 0.001}, {'size': 0.001},
{'size': 0.002}, {'size': 0.002},
# exits to get back to zero. # nearly back to zero.
{'size': -0.001}, {'size': -0.001},
# switch to net-short
{'size': -0.025}, {'size': -0.025},
{'size': -0.0195}, {'size': -0.0195},
# another entry
{'size': 0.001},
# final cover to net-zero again.
{'size': 0.038},
), ),
], ],
ids='fills={}'.format, ids='fills={}'.format,
@ -328,7 +345,7 @@ def test_multi_fill_positions(
fills: tuple[dict], fills: tuple[dict],
check_cross_session: bool = True, check_cross_session: bool = False,
) -> None: ) -> None: