async def test_get_account_funds(self): with mock_client_request(response=BetfairResponses. account_funds_no_exposure()) as mock_request: funds = await self.client.get_account_funds() assert funds["availableToBetBalance"] == 1000.0 result = mock_request.call_args.kwargs expected = BetfairRequests.account_funds() assert result == expected
async def test_list_navigation(self): with mock_client_request(response=BetfairResponses. navigation_list_navigation()) as mock_request: nav = await self.client.list_navigation() assert len(nav["children"]) == 28 result = mock_request.call_args.kwargs expected = BetfairRequests.navigation_list_navigation() assert result == expected
async def test_get_account_details(self): with mock_client_request( response=BetfairResponses.account_details()) as mock_request: account = await self.client.get_account_details() assert account["pointsBalance"] == 10 result = mock_request.call_args.kwargs expected = BetfairRequests.account_details() assert result == expected
async def test_connect(self): self.client.session_token = None with mock_client_request( response=BetfairResponses.cert_login()) as mock_request: await self.client.connect() assert self.client.session_token result = mock_request.call_args.kwargs expected = BetfairRequests.cert_login() assert result == expected
async def test_cancel_orders(self): instrument = BetfairTestStubs.betting_instrument() cancel_command = BetfairTestStubs.cancel_order_command() cancel_order = order_cancel_to_betfair(command=cancel_command, instrument=instrument) with mock_client_request(response=BetfairResponses. betting_place_order_success()) as req: resp = await self.client.cancel_orders(**cancel_order) assert resp expected = BetfairRequests.betting_cancel_order() result = req.call_args.kwargs["json"] assert result == expected
async def test_list_market_catalogue(self): market_filter = { "eventTypeIds": ["7"], "marketBettingTypes": ["ODDS"], } with mock_client_request( response=BetfairResponses.betting_list_market_catalogue( )) as mock_request: catalogue = await self.client.list_market_catalogue( filter_=market_filter) assert catalogue result = mock_request.call_args.kwargs expected = BetfairRequests.betting_list_market_catalogue() assert result == expected
async def test_replace_orders_single(self): instrument = BetfairTestStubs.betting_instrument() update_order_command = BetfairTestStubs.modify_order_command( instrument_id=instrument.id, client_order_id=ClientOrderId("1628717246480-1.186260932-rpl-0"), ) replace_order = order_update_to_betfair( command=update_order_command, venue_order_id=VenueOrderId("240718603398"), side=OrderSide.BUY, instrument=instrument, ) with mock_client_request(response=BetfairResponses. betting_replace_orders_success()) as req: resp = await self.client.replace_orders(**replace_order) assert resp expected = BetfairRequests.betting_replace_order() result = req.call_args.kwargs["json"] assert result == expected
async def test_place_orders(self): instrument = BetfairTestStubs.betting_instrument() limit_order = TestExecStubs.limit_order( instrument_id=instrument.id, order_side=OrderSide.BUY, price=Price.from_str("0.50"), quantity=Quantity.from_int(10), ) command = TestCommandStubs.submit_order_command(order=limit_order) place_orders = order_submit_to_betfair(command=command, instrument=instrument) place_orders["instructions"][0][ "customerOrderRef"] = "O-20210811-112151-000" with mock_client_request(response=BetfairResponses. betting_place_order_success()) as req: await self.client.place_orders(**place_orders) expected = BetfairRequests.betting_place_order() result = req.call_args.kwargs["json"] assert result == expected
async def test_place_orders_market_on_close(self): instrument = BetfairTestStubs.betting_instrument() market_on_close_order = BetfairTestStubs.market_order( side=OrderSide.BUY, time_in_force=TimeInForce.AT_THE_CLOSE, ) submit_order_command = SubmitOrder( trader_id=TestIdStubs.trader_id(), strategy_id=TestIdStubs.strategy_id(), position_id=PositionId("1"), order=market_on_close_order, command_id=UUID4("be7dffa0-46f2-fce5-d820-c7634d022ca1"), ts_init=0, ) place_orders = order_submit_to_betfair(command=submit_order_command, instrument=instrument) with mock_client_request(response=BetfairResponses. betting_place_order_success()) as req: resp = await self.client.place_orders(**place_orders) assert resp expected = BetfairRequests.betting_place_order_bsp() result = req.call_args.kwargs["json"] assert result == expected