Skip to content

Repository files navigation

Injective Quants Chain Stream

Additive Chain Stream client for events that are not yet available in the official injective-py release. It is installed alongside the official SDK and uses a separate Python namespace, injective_quants.

The client supports every Chain Stream v2 filter and response type, including:

  • bank balances and subaccount deposits
  • spot and derivative trades
  • spot and derivative orders and orderbooks
  • positions and oracle prices
  • order failures and conditional-order trigger failures
  • perpetual market funding updates

Installation

The package installs the compatible official SDK automatically:

pip install "injective-quants-chainstream @ git+ssh://git@github.com/InjectiveLabs/sdk-python-quants.git@v0.1.0"

Both namespaces can then be imported in the same process:

from injective_quants import ChainStreamClient, chain_stream_pb
from pyinjective.async_client_v2 import AsyncClient
from pyinjective.core.network import Network

Chain Stream example

This example subscribes to derivative trades and funding updates for the BTC and INJ perpetual markets:

import asyncio

from injective_quants import ChainStreamClient, chain_stream_pb
from pyinjective.core.network import Network


BTC_USDC_PERP = "0x0ee7ca44147bab6ec81ac293b5fe7915488e612af59964b2d663d6008d861dee"
INJ_USDC_PERP = "0x790aee464fbbd02cf4476444554c71d1225f7edfe15e6dc7f874c455fd883d31"


async def process_event(event):
    for trade in event["derivativeTrades"]:
        print("trade", trade)

    for funding in event["marketFundingUpdates"]:
        print("funding", funding)


async def main():
    network = Network.mainnet()
    client = ChainStreamClient(network)
    market_ids = [BTC_USDC_PERP, INJ_USDC_PERP]

    try:
        await client.listen(
            callback=process_event,
            derivative_trades_filter=chain_stream_pb.TradesFilter(market_ids=market_ids),
            market_funding_filter=chain_stream_pb.MarketFundingFilter(market_ids=market_ids),
        )
    finally:
        await client.close()


if __name__ == "__main__":
    asyncio.run(main())

The complete runnable example is in examples/chain_client/7_ChainStream.py.

For an example that subscribes to the complete set of quant-relevant events, see examples/chain_client/8_QuantsChainStream.py.

Development

poetry install
poetry run pytest tests/injective_quants
poetry build

Compatibility

  • Python >=3.10,<3.15
  • injective-py >=1.16,<1.17
  • Chain Stream v2 endpoint with the requested event types enabled

License

Apache License 2.0. See LICENSE.md.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages