Skip to content

Commit

Permalink
(feat) Added support for all chain exchange module queries. Included …
Browse files Browse the repository at this point in the history
…new example scripts for all the queries and unit tests.
  • Loading branch information
abel committed Feb 27, 2024
1 parent 0c61c63 commit 4d6ce1b
Show file tree
Hide file tree
Showing 87 changed files with 5,229 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions examples/chain_client/exchange/query/10_SpotMarkets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

spot_markets = await client.fetch_chain_spot_markets(
status="Active",
market_ids=["0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"],
)
print(spot_markets)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
21 changes: 21 additions & 0 deletions examples/chain_client/exchange/query/11_SpotMarket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

spot_market = await client.fetch_chain_spot_market(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
)
print(spot_market)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
23 changes: 23 additions & 0 deletions examples/chain_client/exchange/query/12_FullSpotMarkets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

spot_markets = await client.fetch_chain_full_spot_markets(
status="Active",
market_ids=["0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"],
with_mid_price_and_tob=True,
)
print(spot_markets)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
22 changes: 22 additions & 0 deletions examples/chain_client/exchange/query/13_FullSpotMarket.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

spot_market = await client.fetch_chain_full_spot_market(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
with_mid_price_and_tob=True,
)
print(spot_market)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
26 changes: 26 additions & 0 deletions examples/chain_client/exchange/query/14_SpotOrderbook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.client.model.pagination import PaginationOption
from pyinjective.core.network import Network


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

pagination = PaginationOption(limit=2)

orderbook = await client.fetch_chain_spot_orderbook(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
order_side="Buy",
pagination=pagination,
)
print(orderbook)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
37 changes: 37 additions & 0 deletions examples/chain_client/exchange/query/15_TraderSpotOrders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import asyncio
import os

import dotenv

from pyinjective import PrivateKey
from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

# load account
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

subaccount_id = address.get_subaccount_id(index=0)

orders = await client.fetch_chain_trader_spot_orders(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
subaccount_id=subaccount_id,
)
print(orders)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import asyncio
import os

import dotenv

from pyinjective import PrivateKey
from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

# load account
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

orders = await client.fetch_chain_account_address_spot_orders(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
account_address=address.to_acc_bech32(),
)
print(orders)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
38 changes: 38 additions & 0 deletions examples/chain_client/exchange/query/17_SpotOrdersByHashes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import asyncio
import os

import dotenv

from pyinjective import PrivateKey
from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

# load account
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

subaccount_id = address.get_subaccount_id(index=0)

orders = await client.fetch_chain_spot_orders_by_hashes(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
subaccount_id=subaccount_id,
order_hashes=["0x57a01cd26f1e2080860af3264e865d7c9c034a701e30946d01c1dc7a303cf2c1"],
)
print(orders)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
37 changes: 37 additions & 0 deletions examples/chain_client/exchange/query/18_SubaccountOrders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import asyncio
import os

import dotenv

from pyinjective import PrivateKey
from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

# load account
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

subaccount_id = address.get_subaccount_id(index=0)

orders = await client.fetch_chain_subaccount_orders(
subaccount_id=subaccount_id,
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
)
print(orders)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import asyncio
import os

import dotenv

from pyinjective import PrivateKey
from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

# load account
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

subaccount_id = address.get_subaccount_id(index=0)

orders = await client.fetch_chain_trader_spot_transient_orders(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
subaccount_id=subaccount_id,
)
print(orders)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
34 changes: 34 additions & 0 deletions examples/chain_client/exchange/query/1_SubaccountDeposits.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import asyncio
import os

import dotenv

from pyinjective import PrivateKey
from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")

# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

# load account
priv_key = PrivateKey.from_hex(configured_private_key)
pub_key = priv_key.to_public_key()
address = pub_key.to_address()
await client.fetch_account(address.to_acc_bech32())

subaccount_id = address.get_subaccount_id(index=0)

deposits = await client.fetch_subaccount_deposits(subaccount_id=subaccount_id)
print(deposits)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
21 changes: 21 additions & 0 deletions examples/chain_client/exchange/query/20_SpotMidPriceAndTOB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

prices = await client.fetch_spot_mid_price_and_tob(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe",
)
print(prices)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import asyncio

from pyinjective.async_client import AsyncClient
from pyinjective.core.network import Network


async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()

# initialize grpc client
client = AsyncClient(network)

prices = await client.fetch_derivative_mid_price_and_tob(
market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
)
print(prices)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Loading

0 comments on commit 4d6ce1b

Please sign in to comment.