Skip to content

Commit

Permalink
Merge pull request #279 from InjectiveLabs/feat/add_trade_v2_indexer_…
Browse files Browse the repository at this point in the history
…endpoints

feat/add trade v2 indexer endpoints
  • Loading branch information
aarmoa authored Dec 7, 2023
2 parents 0204942 + 99f3021 commit b0ffc20
Show file tree
Hide file tree
Showing 40 changed files with 1,899 additions and 133 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.5-testnet --depth 1 --single-branch
git clone https://github.com/InjectiveLabs/injective-core.git -b v1.12.6-testnet --depth 1 --single-branch

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

clone-cometbft:
git clone https://github.com/cometbft/cometbft.git -b v0.37.2 --depth 1 --single-branch
Expand Down
8 changes: 4 additions & 4 deletions pyinjective/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ async def fetch_spot_trades(
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.exchange_spot_api.fetch_trades(
return await self.exchange_spot_api.fetch_trades_v2(
market_ids=market_ids,
subaccount_ids=subaccount_ids,
execution_side=execution_side,
Expand Down Expand Up @@ -1617,7 +1617,7 @@ async def listen_spot_trades_updates(
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
):
await self.exchange_spot_stream_api.stream_trades(
await self.exchange_spot_stream_api.stream_trades_v2(
callback=callback,
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
Expand Down Expand Up @@ -1915,7 +1915,7 @@ async def fetch_derivative_trades(
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
return await self.exchange_derivative_api.fetch_trades(
return await self.exchange_derivative_api.fetch_trades_v2(
market_ids=market_ids,
subaccount_ids=subaccount_ids,
execution_side=execution_side,
Expand Down Expand Up @@ -2088,7 +2088,7 @@ async def listen_derivative_trades_updates(
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
):
return await self.exchange_derivative_stream_api.stream_trades(
return await self.exchange_derivative_stream_api.stream_trades_v2(
callback=callback,
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
Expand Down
32 changes: 32 additions & 0 deletions pyinjective/client/indexer/grpc/indexer_grpc_derivative_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,5 +287,37 @@ async def fetch_orders_history(

return response

async def fetch_trades_v2(
self,
market_ids: Optional[List[str]] = None,
subaccount_ids: Optional[List[str]] = None,
execution_side: Optional[str] = None,
direction: Optional[str] = None,
execution_types: Optional[List[str]] = None,
trade_id: Optional[str] = None,
account_address: Optional[str] = None,
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
pagination = pagination or PaginationOption()
request = exchange_derivative_pb.TradesV2Request(
market_ids=market_ids,
subaccount_ids=subaccount_ids,
execution_side=execution_side,
direction=direction,
skip=pagination.skip,
limit=pagination.limit,
start_time=pagination.start_time,
end_time=pagination.end_time,
execution_types=execution_types,
trade_id=trade_id,
account_address=account_address,
cid=cid,
)

response = await self._execute_call(call=self._stub.TradesV2, 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)
32 changes: 32 additions & 0 deletions pyinjective/client/indexer/grpc/indexer_grpc_spot_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,37 @@ async def fetch_atomic_swap_history(

return response

async def fetch_trades_v2(
self,
market_ids: Optional[List[str]] = None,
subaccount_ids: Optional[List[str]] = None,
execution_side: Optional[str] = None,
direction: Optional[str] = None,
execution_types: Optional[List[str]] = None,
trade_id: Optional[str] = None,
account_address: Optional[str] = None,
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
) -> Dict[str, Any]:
pagination = pagination or PaginationOption()
request = exchange_spot_pb.TradesV2Request(
market_ids=market_ids,
subaccount_ids=subaccount_ids,
execution_side=execution_side,
direction=direction,
skip=pagination.skip,
limit=pagination.limit,
start_time=pagination.start_time,
end_time=pagination.end_time,
execution_types=execution_types,
trade_id=trade_id,
account_address=account_address,
cid=cid,
)

response = await self._execute_call(call=self._stub.TradesV2, 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)
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,42 @@ async def stream_orders_history(
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
)

async def stream_trades_v2(
self,
callback: Callable,
on_end_callback: Optional[Callable] = None,
on_status_callback: Optional[Callable] = None,
market_ids: Optional[List[str]] = None,
execution_side: Optional[str] = None,
direction: Optional[str] = None,
subaccount_ids: Optional[List[str]] = None,
execution_types: Optional[List[str]] = None,
trade_id: Optional[str] = None,
account_address: Optional[str] = None,
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
):
pagination = pagination or PaginationOption()
request = exchange_derivative_pb.StreamTradesV2Request(
execution_side=execution_side,
direction=direction,
skip=pagination.skip,
limit=pagination.limit,
start_time=pagination.start_time,
end_time=pagination.end_time,
market_ids=market_ids,
subaccount_ids=subaccount_ids,
execution_types=execution_types,
trade_id=trade_id,
account_address=account_address,
cid=cid,
)

await self._assistant.listen_stream(
call=self._stub.StreamTradesV2,
request=request,
callback=callback,
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
)
39 changes: 39 additions & 0 deletions pyinjective/client/indexer/grpc_stream/indexer_grpc_spot_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,42 @@ async def stream_orders_history(
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
)

async def stream_trades_v2(
self,
callback: Callable,
on_end_callback: Optional[Callable] = None,
on_status_callback: Optional[Callable] = None,
market_ids: Optional[List[str]] = None,
subaccount_ids: Optional[List[str]] = None,
execution_side: Optional[str] = None,
direction: Optional[str] = None,
execution_types: Optional[List[str]] = None,
trade_id: Optional[str] = None,
account_address: Optional[str] = None,
cid: Optional[str] = None,
pagination: Optional[PaginationOption] = None,
):
pagination = pagination or PaginationOption()
request = exchange_spot_pb.StreamTradesV2Request(
execution_side=execution_side,
direction=direction,
skip=pagination.skip,
limit=pagination.limit,
start_time=pagination.start_time,
end_time=pagination.end_time,
market_ids=market_ids,
subaccount_ids=subaccount_ids,
execution_types=execution_types,
trade_id=trade_id,
account_address=account_address,
cid=cid,
)

await self._assistant.listen_stream(
call=self._stub.StreamTradesV2,
request=request,
callback=callback,
on_end_callback=on_end_callback,
on_status_callback=on_status_callback,
)
10 changes: 5 additions & 5 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 b0ffc20

Please sign in to comment.