@@ -23,7 +23,7 @@ def exchange_servicer():
2323 return ConfigurableExchangeV2QueryServicer ()
2424
2525
26- class TestChainGrpcBankApi :
26+ class TestChainGrpcExchangeV2Api :
2727 @pytest .mark .asyncio
2828 async def test_fetch_exchange_params (
2929 self ,
@@ -1554,6 +1554,50 @@ async def test_fetch_positions(
15541554
15551555 assert positions == expected_positions
15561556
1557+ @pytest .mark .asyncio
1558+ async def test_fetch_positions_in_market (
1559+ self ,
1560+ exchange_servicer ,
1561+ ):
1562+ position = exchange_pb .Position (
1563+ isLong = True ,
1564+ quantity = "1000000000000000" ,
1565+ entry_price = "2000000000000000000" ,
1566+ margin = "2000000000000000000000000000000000" ,
1567+ cumulative_funding_entry = "4000000" ,
1568+ )
1569+ derivative_position = exchange_pb .DerivativePosition (
1570+ subaccount_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20000000000000000000000000" ,
1571+ market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" ,
1572+ position = position ,
1573+ )
1574+ exchange_servicer .positions_in_market_responses .append (
1575+ exchange_query_pb .QueryPositionsInMarketResponse (state = [derivative_position ])
1576+ )
1577+
1578+ api = self ._api_instance (servicer = exchange_servicer )
1579+
1580+ positions = await api .fetch_positions_in_market (
1581+ market_id = "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6" ,
1582+ )
1583+ expected_positions = {
1584+ "state" : [
1585+ {
1586+ "subaccountId" : derivative_position .subaccount_id ,
1587+ "marketId" : derivative_position .market_id ,
1588+ "position" : {
1589+ "isLong" : position .isLong ,
1590+ "quantity" : position .quantity ,
1591+ "entryPrice" : position .entry_price ,
1592+ "margin" : position .margin ,
1593+ "cumulativeFundingEntry" : position .cumulative_funding_entry ,
1594+ },
1595+ },
1596+ ],
1597+ }
1598+
1599+ assert positions == expected_positions
1600+
15571601 @pytest .mark .asyncio
15581602 async def test_fetch_subaccount_positions (
15591603 self ,
0 commit comments