Skip to content

Commit

Permalink
Merge pull request #284 from InjectiveLabs/feat/add_new_indexer_posit…
Browse files Browse the repository at this point in the history
…ion_endpoints

Feat/add new indexer position endpoints
  • Loading branch information
aarmoa committed Dec 26, 2023
2 parents b0ffc20 + 33436cc commit 2aeca6a
Show file tree
Hide file tree
Showing 31 changed files with 411 additions and 826 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ clean-all:
$(call clean_repos)

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

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

clone-cometbft:
git clone https://github.com/cometbft/cometbft.git -b v0.37.2 --depth 1 --single-branch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async def main() -> None:
skip = 4
limit = 4
pagination = PaginationOption(skip=skip, limit=limit)
positions = await client.fetch_derivative_positions(
positions = await client.fetch_derivative_positions_v2(
market_ids=market_ids,
subaccount_id=subaccount_id,
direction=direction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ async def main() -> None:
network = Network.testnet()
client = AsyncClient(network)
account_address = "inj1clw20s2uxeyxtam6f7m84vgae92s9eh7vygagt"
portfolio = await client.fetch_account_portfolio(account_address=account_address)
portfolio = await client.fetch_account_portfolio_balances(account_address=account_address)
print(portfolio)


Expand Down
18 changes: 10 additions & 8 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2105,9 +2105,9 @@ async def listen_derivative_trades_updates(

async def get_derivative_positions(self, **kwargs):
"""
This method is deprecated and will be removed soon. Please use `fetch_derivative_positions` instead
This method is deprecated and will be removed soon. Please use `fetch_derivative_positions_v2` instead
"""
warn("This method is deprecated. Use fetch_derivative_positions instead", DeprecationWarning, stacklevel=2)
warn("This method is deprecated. Use fetch_derivative_positions_v2 instead", DeprecationWarning, stacklevel=2)
req = derivative_exchange_rpc_pb.PositionsRequest(
market_id=kwargs.get("market_id"),
market_ids=kwargs.get("market_ids"),
Expand All @@ -2119,15 +2119,15 @@ async def get_derivative_positions(self, **kwargs):
)
return await self.stubDerivativeExchange.Positions(req)

async def fetch_derivative_positions(
async def fetch_derivative_positions_v2(
self,
market_ids: Optional[List[str]] = None,
subaccount_id: Optional[str] = None,
direction: Optional[str] = None,
subaccount_total_positions: Optional[bool] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.exchange_derivative_api.fetch_positions(
return await self.exchange_derivative_api.fetch_positions_v2(
market_ids=market_ids,
subaccount_id=subaccount_id,
direction=direction,
Expand Down Expand Up @@ -2344,14 +2344,16 @@ async def fetch_binary_options_market(self, market_id: str) -> Dict[str, Any]:

async def get_account_portfolio(self, account_address: str):
"""
This method is deprecated and will be removed soon. Please use `fetch_account_portfolio` instead
This method is deprecated and will be removed soon. Please use `fetch_account_portfolio_balances` instead
"""
warn("This method is deprecated. Use fetch_account_portfolio instead", DeprecationWarning, stacklevel=2)
warn(
"This method is deprecated. Use fetch_account_portfolio_balances instead", DeprecationWarning, stacklevel=2
)
req = portfolio_rpc_pb.AccountPortfolioRequest(account_address=account_address)
return await self.stubPortfolio.AccountPortfolio(req)

async def fetch_account_portfolio(self, account_address: str) -> Dict[str, Any]:
return await self.exchange_portfolio_api.fetch_account_portfolio(account_address=account_address)
async def fetch_account_portfolio_balances(self, account_address: str) -> Dict[str, Any]:
return await self.exchange_portfolio_api.fetch_account_portfolio_balances(account_address=account_address)

async def stream_account_portfolio(self, account_address: str, **kwargs):
"""
Expand Down
24 changes: 24 additions & 0 deletions pyinjective/client/indexer/grpc/indexer_grpc_derivative_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,30 @@ async def fetch_positions(

return response

async def fetch_positions_v2(
self,
market_ids: Optional[List[str]] = None,
subaccount_id: Optional[str] = None,
direction: Optional[str] = None,
subaccount_total_positions: Optional[bool] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
pagination = pagination or PaginationOption()
request = exchange_derivative_pb.PositionsV2Request(
market_ids=market_ids,
subaccount_id=subaccount_id,
skip=pagination.skip,
limit=pagination.limit,
start_time=pagination.start_time,
end_time=pagination.end_time,
direction=direction,
subaccount_total_positions=subaccount_total_positions,
)

response = await self._execute_call(call=self._stub.PositionsV2, request=request)

return response

async def fetch_liquidable_positions(
self,
market_id: Optional[str] = None,
Expand Down
6 changes: 6 additions & 0 deletions pyinjective/client/indexer/grpc/indexer_grpc_portfolio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ async def fetch_account_portfolio(self, account_address: str) -> Dict[str, Any]:

return response

async def fetch_account_portfolio_balances(self, account_address: str) -> Dict[str, Any]:
request = exchange_portfolio_pb.AccountPortfolioBalancesRequest(account_address=account_address)
response = await self._execute_call(call=self._stub.AccountPortfolioBalances, request=request)

return response

async def _execute_call(self, call: Callable, request) -> Dict[str, Any]:
return await self._assistant.execute_call(call=call, request=request)
8 changes: 4 additions & 4 deletions pyinjective/proto/cosmos/ics23/v1/proofs_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2aeca6a

Please sign in to comment.