-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) Added support for all chain exchange module queries. Included …
…new example scripts for all the queries and unit tests.
- Loading branch information
abel
committed
Feb 27, 2024
1 parent
0c61c63
commit 4d6ce1b
Showing
87 changed files
with
5,229 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
23
examples/chain_client/exchange/query/12_FullSpotMarkets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
examples/chain_client/exchange/query/15_TraderSpotOrders.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
35 changes: 35 additions & 0 deletions
35
examples/chain_client/exchange/query/16_AccountAddressSpotOrders.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
38
examples/chain_client/exchange/query/17_SpotOrdersByHashes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
37
examples/chain_client/exchange/query/18_SubaccountOrders.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
37 changes: 37 additions & 0 deletions
37
examples/chain_client/exchange/query/19_TraderSpotTransientOrders.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
examples/chain_client/exchange/query/1_SubaccountDeposits.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
21
examples/chain_client/exchange/query/20_SpotMidPriceAndTOB.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
21 changes: 21 additions & 0 deletions
21
examples/chain_client/exchange/query/21_DerivativeMidPriceAndTOB.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Oops, something went wrong.