Skip to content

Commit 2aeca6a

Browse files
authored
Merge pull request #284 from InjectiveLabs/feat/add_new_indexer_position_endpoints
Feat/add new indexer position endpoints
2 parents b0ffc20 + 33436cc commit 2aeca6a

31 files changed

+411
-826
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ clean-all:
2828
$(call clean_repos)
2929

3030
clone-injective-core:
31-
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.12.6-testnet --depth 1 --single-branch
31+
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.12.8-testnet --depth 1 --single-branch
3232

3333
clone-injective-indexer:
34-
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.12.59 --depth 1 --single-branch
34+
git clone https://github.com/InjectiveLabs/injective-indexer.git -b v1.12.67 --depth 1 --single-branch
3535

3636
clone-cometbft:
3737
git clone https://github.com/cometbft/cometbft.git -b v0.37.2 --depth 1 --single-branch

examples/exchange_client/derivative_exchange_rpc/7_Positions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def main() -> None:
1919
skip = 4
2020
limit = 4
2121
pagination = PaginationOption(skip=skip, limit=limit)
22-
positions = await client.fetch_derivative_positions(
22+
positions = await client.fetch_derivative_positions_v2(
2323
market_ids=market_ids,
2424
subaccount_id=subaccount_id,
2525
direction=direction,

examples/exchange_client/portfolio_rpc/1_AccountPortfolio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async def main() -> None:
99
network = Network.testnet()
1010
client = AsyncClient(network)
1111
account_address = "inj1clw20s2uxeyxtam6f7m84vgae92s9eh7vygagt"
12-
portfolio = await client.fetch_account_portfolio(account_address=account_address)
12+
portfolio = await client.fetch_account_portfolio_balances(account_address=account_address)
1313
print(portfolio)
1414

1515

pyinjective/async_client.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,9 +2105,9 @@ async def listen_derivative_trades_updates(
21052105

21062106
async def get_derivative_positions(self, **kwargs):
21072107
"""
2108-
This method is deprecated and will be removed soon. Please use `fetch_derivative_positions` instead
2108+
This method is deprecated and will be removed soon. Please use `fetch_derivative_positions_v2` instead
21092109
"""
2110-
warn("This method is deprecated. Use fetch_derivative_positions instead", DeprecationWarning, stacklevel=2)
2110+
warn("This method is deprecated. Use fetch_derivative_positions_v2 instead", DeprecationWarning, stacklevel=2)
21112111
req = derivative_exchange_rpc_pb.PositionsRequest(
21122112
market_id=kwargs.get("market_id"),
21132113
market_ids=kwargs.get("market_ids"),
@@ -2119,15 +2119,15 @@ async def get_derivative_positions(self, **kwargs):
21192119
)
21202120
return await self.stubDerivativeExchange.Positions(req)
21212121

2122-
async def fetch_derivative_positions(
2122+
async def fetch_derivative_positions_v2(
21232123
self,
21242124
market_ids: Optional[List[str]] = None,
21252125
subaccount_id: Optional[str] = None,
21262126
direction: Optional[str] = None,
21272127
subaccount_total_positions: Optional[bool] = None,
21282128
pagination: Optional[PaginationOption] = None,
21292129
) -> Dict[str, Any]:
2130-
return await self.exchange_derivative_api.fetch_positions(
2130+
return await self.exchange_derivative_api.fetch_positions_v2(
21312131
market_ids=market_ids,
21322132
subaccount_id=subaccount_id,
21332133
direction=direction,
@@ -2344,14 +2344,16 @@ async def fetch_binary_options_market(self, market_id: str) -> Dict[str, Any]:
23442344

23452345
async def get_account_portfolio(self, account_address: str):
23462346
"""
2347-
This method is deprecated and will be removed soon. Please use `fetch_account_portfolio` instead
2347+
This method is deprecated and will be removed soon. Please use `fetch_account_portfolio_balances` instead
23482348
"""
2349-
warn("This method is deprecated. Use fetch_account_portfolio instead", DeprecationWarning, stacklevel=2)
2349+
warn(
2350+
"This method is deprecated. Use fetch_account_portfolio_balances instead", DeprecationWarning, stacklevel=2
2351+
)
23502352
req = portfolio_rpc_pb.AccountPortfolioRequest(account_address=account_address)
23512353
return await self.stubPortfolio.AccountPortfolio(req)
23522354

2353-
async def fetch_account_portfolio(self, account_address: str) -> Dict[str, Any]:
2354-
return await self.exchange_portfolio_api.fetch_account_portfolio(account_address=account_address)
2355+
async def fetch_account_portfolio_balances(self, account_address: str) -> Dict[str, Any]:
2356+
return await self.exchange_portfolio_api.fetch_account_portfolio_balances(account_address=account_address)
23552357

23562358
async def stream_account_portfolio(self, account_address: str, **kwargs):
23572359
"""

pyinjective/client/indexer/grpc/indexer_grpc_derivative_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,30 @@ async def fetch_positions(
127127

128128
return response
129129

130+
async def fetch_positions_v2(
131+
self,
132+
market_ids: Optional[List[str]] = None,
133+
subaccount_id: Optional[str] = None,
134+
direction: Optional[str] = None,
135+
subaccount_total_positions: Optional[bool] = None,
136+
pagination: Optional[PaginationOption] = None,
137+
) -> Dict[str, Any]:
138+
pagination = pagination or PaginationOption()
139+
request = exchange_derivative_pb.PositionsV2Request(
140+
market_ids=market_ids,
141+
subaccount_id=subaccount_id,
142+
skip=pagination.skip,
143+
limit=pagination.limit,
144+
start_time=pagination.start_time,
145+
end_time=pagination.end_time,
146+
direction=direction,
147+
subaccount_total_positions=subaccount_total_positions,
148+
)
149+
150+
response = await self._execute_call(call=self._stub.PositionsV2, request=request)
151+
152+
return response
153+
130154
async def fetch_liquidable_positions(
131155
self,
132156
market_id: Optional[str] = None,

pyinjective/client/indexer/grpc/indexer_grpc_portfolio_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@ async def fetch_account_portfolio(self, account_address: str) -> Dict[str, Any]:
2020

2121
return response
2222

23+
async def fetch_account_portfolio_balances(self, account_address: str) -> Dict[str, Any]:
24+
request = exchange_portfolio_pb.AccountPortfolioBalancesRequest(account_address=account_address)
25+
response = await self._execute_call(call=self._stub.AccountPortfolioBalances, request=request)
26+
27+
return response
28+
2329
async def _execute_call(self, call: Callable, request) -> Dict[str, Any]:
2430
return await self._assistant.execute_call(call=call, request=request)

pyinjective/proto/cosmos/ics23/v1/proofs_pb2.py

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)