Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cee3bfb
(fix) Updated the cookie assistant to support the exchange server not…
Feb 29, 2024
8cebde5
(fix) Changed cookie expiration info parsing in the Kubernetes cookie…
Feb 29, 2024
83152b2
Merge pull request #308 from InjectiveLabs/fix/update_indexer_cookie_…
aarmoa Feb 29, 2024
10491af
(fix) Changed version number for dev branch
Jan 16, 2024
4bba9cd
(feat) Cleaned up the markets initialization logic
Jan 17, 2024
c526eac
(feat) Refactored all examples to remove references to private keys. …
Feb 6, 2024
f02435c
(fix) Changed version number for dev branch
Jan 16, 2024
7573faa
(fix) Updated dependencies versions in poetry.lock
Feb 12, 2024
9235c41
(feat) Refactored all examples to remove references to private keys. …
Feb 6, 2024
9ff8783
(fix) Changed version number for dev branch
Jan 16, 2024
51f1752
(feat) Added support for all `distribution` module queries. Added als…
Feb 9, 2024
d976f69
(fix) Fix error due to incomplete rename
Feb 9, 2024
873e8c7
(feat) Added support in Composer to create all missing messages from …
Feb 12, 2024
364f022
(feat) Added support for all chain exchange module queries. Included …
Feb 20, 2024
17524af
(feat) Added support for all chain exchange module messages in Compos…
Feb 27, 2024
189354a
(feat) Adde CodeRabbit configuration file
Feb 27, 2024
4dfde9a
(feat) Added support for all chain exchange module queries. Included …
Feb 20, 2024
4725ad2
(feat) Added support for all chain exchange module messages in Compos…
Feb 27, 2024
1b6953a
(fix) Fix in CodeRabbit confir YAML file
Feb 27, 2024
5e8b13b
(feat) Added support for a missing endpoint in the chain exchange mod…
Mar 5, 2024
13ff9a8
(fix) Updated CHANGELOG.md file
Mar 5, 2024
aa397a0
Merge branch 'dev' of https://github.com/InjectiveLabs/sdk-python int…
Mar 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

## [1.4.0] - 2024-03-11
### Added
- Added support for all queries and messages in the chain 'distribution' module
- Added support for all queries and messages in the chain 'exchange' module
- Use of python-dotenv in all example scripts to load private keys from a .env file

## [1.3.1] - 2024-02-29
### Changed
- Updated cookie assistant logic to support the Indexer exchange server not using cookies and the chain server using them

## [1.3.0] - 2024-02-12
### Changed
- Removed `asyncio` from the dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ async def main() -> None:
subaccount_id=subaccount_id,
fee_recipient=fee_recipient,
price=Decimal(50000),
quantity=Decimal(0.01),
quantity=Decimal(0.1),
margin=composer.calculate_margin(
quantity=Decimal(0.01), price=Decimal(50000), leverage=Decimal(3), is_reduce_only=False
quantity=Decimal(0.1), price=Decimal(50000), leverage=Decimal(1), is_reduce_only=False
),
order_type="BUY",
Comment on lines +46 to +50

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adjustments made to the main function in creating a derivative market order are clear and align with the described objectives. However, consider the following:

  • Validation and Error Handling: Ensure that the values for quantity, price, and leverage are validated before use to prevent invalid transactions. Additionally, consider adding error handling around the transaction simulation and broadcast steps to gracefully handle potential failures.
  • Parameterization: The market_id, fee_recipient, price, quantity, leverage, and order_type are hardcoded. For enhanced usability, consider allowing these values to be passed as arguments or read from environment variables.
+ # Example validation (simplified)
+ if quantity <= 0 or price <= 0 or leverage <= 0:
+     raise ValueError("Quantity, price, and leverage must be greater than 0.")
+ try:
+     # Transaction simulation and broadcast code...
+ except Exception as e:
+     print(f"Failed to create derivative market order: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
quantity=Decimal(0.1),
margin=composer.calculate_margin(
quantity=Decimal(0.01), price=Decimal(50000), leverage=Decimal(3), is_reduce_only=False
quantity=Decimal(0.1), price=Decimal(50000), leverage=Decimal(1), is_reduce_only=False
),
order_type="BUY",
quantity=Decimal(0.1),
margin=composer.calculate_margin(
quantity=Decimal(0.1), price=Decimal(50000), leverage=Decimal(1), is_reduce_only=False
),
order_type="BUY",

cid=str(uuid.uuid4()),
)

Expand Down
32 changes: 32 additions & 0 deletions examples/chain_client/exchange/query/41_TradeRewardCampaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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())

campaign = await client.fetch_trade_reward_campaign()
print(campaign)


if __name__ == "__main__":
Comment on lines +11 to +31

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example script for querying trade reward campaigns is well-structured and follows the project's conventions for async operations. However, there are a few areas for improvement:

  • Error Handling: Consider adding error handling around the await client.fetch_trade_reward_campaign() call to gracefully handle potential exceptions that could arise from network issues or API changes.
  • Environment Variables: The script assumes the presence of an environment variable INJECTIVE_PRIVATE_KEY. It's good practice to check if the variable is not None after retrieval and provide a meaningful error message if it's missing.
  • Hardcoded Network: The network is hardcoded to testnet. For better flexibility, consider allowing the network type to be passed as an argument or environment variable.
+ if configured_private_key is None:
+     raise ValueError("INJECTIVE_PRIVATE_KEY environment variable is not set.")
+ try:
+     campaign = await client.fetch_trade_reward_campaign()
+     print(campaign)
+ except Exception as e:
+     print(f"Failed to fetch trade reward campaign: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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())
campaign = await client.fetch_trade_reward_campaign()
print(campaign)
if __name__ == "__main__":
async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
+ if configured_private_key is None:
+ raise ValueError("INJECTIVE_PRIVATE_KEY environment variable is not set.")
# 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())
+ try:
+ campaign = await client.fetch_trade_reward_campaign()
+ print(campaign)
+ except Exception as e:
+ print(f"Failed to fetch trade reward campaign: {e}")
if __name__ == "__main__":

asyncio.get_event_loop().run_until_complete(main())
34 changes: 34 additions & 0 deletions examples/chain_client/exchange/query/42_FeeDiscountAccountInfo.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())

fee_discount = await client.fetch_fee_discount_account_info(
account=address.to_acc_bech32(),
)
print(fee_discount)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +11 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script for querying fee discount account information is consistent with the project's standards. Similar to previous files, consider the following enhancements:

  • Error Handling: Add error handling for the await client.fetch_fee_discount_account_info(...) call to ensure the script can handle exceptions gracefully.
  • Environment Variable Check: Validate the INJECTIVE_PRIVATE_KEY environment variable to ensure it's set before proceeding.
+ if configured_private_key is None:
+     raise ValueError("INJECTIVE_PRIVATE_KEY environment variable is not set.")
+ try:
+     fee_discount = await client.fetch_fee_discount_account_info(
+         account=address.to_acc_bech32(),
+     )
+     print(fee_discount)
+ except Exception as e:
+     print(f"Failed to fetch fee discount account info: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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())
fee_discount = await client.fetch_fee_discount_account_info(
account=address.to_acc_bech32(),
)
print(fee_discount)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
+ if configured_private_key is None:
+ raise ValueError("INJECTIVE_PRIVATE_KEY environment variable is not set.")
# 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())
+ try:
+ fee_discount = await client.fetch_fee_discount_account_info(
+ account=address.to_acc_bech32(),
+ )
+ print(fee_discount)
+ except Exception as e:
+ print(f"Failed to fetch fee discount account info: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

19 changes: 19 additions & 0 deletions examples/chain_client/exchange/query/43_FeeDiscountSchedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

schedule = await client.fetch_fee_discount_schedule()
print(schedule)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous example, this script demonstrates the usage of the fetch_fee_discount_schedule method effectively. To improve robustness and clarity:

  • Implement error handling around the async call to manage potential exceptions gracefully.
  • Enhance the output formatting for a better understanding of the returned data, particularly for users unfamiliar with the data structure.
-    schedule = await client.fetch_fee_discount_schedule()
+    try:
+        schedule = await client.fetch_fee_discount_schedule()
+        # Consider adding more detailed formatting or processing here
+        print(schedule)
+    except Exception as e:
+        print(f"Failed to fetch Fee Discount Schedule: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
schedule = await client.fetch_fee_discount_schedule()
print(schedule)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
schedule = await client.fetch_fee_discount_schedule()
# Consider adding more detailed formatting or processing here
print(schedule)
except Exception as e:
print(f"Failed to fetch Fee Discount Schedule: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

19 changes: 19 additions & 0 deletions examples/chain_client/exchange/query/44_BalanceMismatches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

mismatches = await client.fetch_balance_mismatches(dust_factor=1)
print(mismatches)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this script, which introduces the fetch_balance_mismatches method, consider the following improvements:

  • Implement error handling around the async call to ensure the script is resilient to exceptions.
  • Enhance the output formatting to help users navigate and understand the data structure returned by the query.
-    mismatches = await client.fetch_balance_mismatches(dust_factor=1)
+    try:
+        mismatches = await client.fetch_balance_mismatches(dust_factor=1)
+        # Suggest enhancing output formatting for data clarity
+        print(mismatches)
+    except Exception as e:
+        print(f"Failed to fetch Balance Mismatches: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
mismatches = await client.fetch_balance_mismatches(dust_factor=1)
print(mismatches)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
mismatches = await client.fetch_balance_mismatches(dust_factor=1)
# Suggest enhancing output formatting for data clarity
print(mismatches)
except Exception as e:
print(f"Failed to fetch Balance Mismatches: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

19 changes: 19 additions & 0 deletions examples/chain_client/exchange/query/45_BalanceWithBalanceHolds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

balance = await client.fetch_balance_with_balance_holds()
print(balance)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with the other examples, this script effectively demonstrates the fetch_balance_with_balance_holds method. To further enhance this example:

  • Add error handling to manage exceptions from the async call, improving the script's robustness.
  • Consider improving the output formatting to help users better understand the complex data structures returned by the query.
-    balance = await client.fetch_balance_with_balance_holds()
+    try:
+        balance = await client.fetch_balance_with_balance_holds()
+        # Enhance output formatting for better clarity
+        print(balance)
+    except Exception as e:
+        print(f"Failed to fetch Balance with Balance Holds: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
balance = await client.fetch_balance_with_balance_holds()
print(balance)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
balance = await client.fetch_balance_with_balance_holds()
# Enhance output formatting for better clarity
print(balance)
except Exception as e:
print(f"Failed to fetch Balance with Balance Holds: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

statistics = await client.fetch_fee_discount_tier_statistics()
print(statistics)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example, showcasing the fetch_fee_discount_tier_statistics method, could be improved by:

  • Adding error handling to better manage exceptions from the async call.
  • Enhancing the output formatting to provide a clearer representation of the complex data returned.
-    statistics = await client.fetch_fee_discount_tier_statistics()
+    try:
+        statistics = await client.fetch_fee_discount_tier_statistics()
+        # Recommend improving output formatting for clarity
+        print(statistics)
+    except Exception as e:
+        print(f"Failed to fetch Fee Discount Tier Statistics: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
statistics = await client.fetch_fee_discount_tier_statistics()
print(statistics)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
statistics = await client.fetch_fee_discount_tier_statistics()
# Recommend improving output formatting for clarity
print(statistics)
except Exception as e:
print(f"Failed to fetch Fee Discount Tier Statistics: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

19 changes: 19 additions & 0 deletions examples/chain_client/exchange/query/47_MitoVaultInfos.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

infos = await client.fetch_mito_vault_infos()
print(infos)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example script is well-structured and demonstrates the usage of the fetch_mito_vault_infos method effectively. However, there are a couple of areas that could be improved for robustness and clarity:

  • Consider adding error handling around the async call to fetch_mito_vault_infos to manage potential exceptions that could arise from network issues or API changes.
  • Enhancing the output formatting could provide users with a clearer understanding of the data structure returned by the query, especially for complex data types.
-    infos = await client.fetch_mito_vault_infos()
+    try:
+        infos = await client.fetch_mito_vault_infos()
+        # Consider adding more detailed formatting or processing here
+        print(infos)
+    except Exception as e:
+        print(f"Failed to fetch Mito Vault Infos: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
infos = await client.fetch_mito_vault_infos()
print(infos)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
infos = await client.fetch_mito_vault_infos()
# Consider adding more detailed formatting or processing here
print(infos)
except Exception as e:
print(f"Failed to fetch Mito Vault Infos: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

19 changes: 19 additions & 0 deletions examples/chain_client/exchange/query/48_QueryMarketIDFromVault.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

market_id = await client.fetch_market_id_from_vault(vault_address="inj1qg5ega6dykkxc307y25pecuufrjkxkag6xhp6y")
print(market_id)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this script, which demonstrates the fetch_market_id_from_vault method, consider the following enhancements:

  • Implement error handling for the async call to handle exceptions more gracefully.
  • Enhance the output formatting to provide users with a clearer understanding of the returned data, especially for complex structures.
-    market_id = await client.fetch_market_id_from_vault(vault_address="inj1qg5ega6dykkxc307y25pecuufrjkxkag6xhp6y")
+    try:
+        market_id = await client.fetch_market_id_from_vault(vault_address="inj1qg5ega6dykkxc307y25pecuufrjkxkag6xhp6y")
+        # Suggest adding detailed output formatting
+        print(market_id)
+    except Exception as e:
+        print(f"Failed to fetch Market ID from Vault: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
market_id = await client.fetch_market_id_from_vault(vault_address="inj1qg5ega6dykkxc307y25pecuufrjkxkag6xhp6y")
print(market_id)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
market_id = await client.fetch_market_id_from_vault(vault_address="inj1qg5ega6dykkxc307y25pecuufrjkxkag6xhp6y")
# Suggest adding detailed output formatting
print(market_id)
except Exception as e:
print(f"Failed to fetch Market ID from Vault: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

21 changes: 21 additions & 0 deletions examples/chain_client/exchange/query/49_HistoricalTradeRecords.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)

records = await client.fetch_historical_trade_records(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
)
print(records)


if __name__ == "__main__":
Comment on lines +7 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script, showcasing the fetch_historical_trade_records method, could be improved by:

  • Adding error handling to manage exceptions from the async call effectively.
  • Improving the output formatting to aid users in understanding the returned data, particularly for complex data structures.
-    records = await client.fetch_historical_trade_records(
+    try:
+        records = await client.fetch_historical_trade_records(
+            market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
+        )
+        # Recommend enhancing output formatting for clarity
+        print(records)
+    except Exception as e:
+        print(f"Failed to fetch Historical Trade Records: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
records = await client.fetch_historical_trade_records(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
)
print(records)
if __name__ == "__main__":
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
records = await client.fetch_historical_trade_records(
market_id="0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
)
# Recommend enhancing output formatting for clarity
print(records)
except Exception as e:
print(f"Failed to fetch Historical Trade Records: {e}")
if __name__ == "__main__":

asyncio.get_event_loop().run_until_complete(main())
34 changes: 34 additions & 0 deletions examples/chain_client/exchange/query/50_IsOptedOutOfRewards.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())

is_opted_out = await client.fetch_is_opted_out_of_rewards(
account=address.to_acc_bech32(),
)
print(is_opted_out)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +11 to +34

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script for checking if an account has opted out of rewards is well-implemented and adheres to the project's coding standards. Recommendations for improvement are similar to those for the previous files:

  • Error Handling: Implement error handling around the await client.fetch_is_opted_out_of_rewards(...) call to manage exceptions effectively.
  • Environment Variable Validation: Ensure the INJECTIVE_PRIVATE_KEY environment variable is checked for None before proceeding with its use.
+ if configured_private_key is None:
+     raise ValueError("INJECTIVE_PRIVATE_KEY environment variable is not set.")
+ try:
+     is_opted_out = await client.fetch_is_opted_out_of_rewards(
+         account=address.to_acc_bech32(),
+     )
+     print(is_opted_out)
+ except Exception as e:
+     print(f"Failed to check if opted out of rewards: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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())
is_opted_out = await client.fetch_is_opted_out_of_rewards(
account=address.to_acc_bech32(),
)
print(is_opted_out)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
dotenv.load_dotenv()
configured_private_key = os.getenv("INJECTIVE_PRIVATE_KEY")
if configured_private_key is None:
raise ValueError("INJECTIVE_PRIVATE_KEY environment variable is not set.")
# 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())
try:
is_opted_out = await client.fetch_is_opted_out_of_rewards(
account=address.to_acc_bech32(),
)
print(is_opted_out)
except Exception as e:
print(f"Failed to check if opted out of rewards: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

opted_out = await client.fetch_opted_out_of_rewards_accounts()
print(opted_out)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script, demonstrating the fetch_opted_out_of_rewards_accounts method, follows the established pattern. To enhance it:

  • Implement error handling for the async call to gracefully handle potential exceptions.
  • Improve the output formatting to aid users in understanding the returned data, especially if it involves complex structures.
-    opted_out = await client.fetch_opted_out_of_rewards_accounts()
+    try:
+        opted_out = await client.fetch_opted_out_of_rewards_accounts()
+        # Suggest adding detailed output formatting
+        print(opted_out)
+    except Exception as e:
+        print(f"Failed to fetch Opted Out of Rewards Accounts: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
opted_out = await client.fetch_opted_out_of_rewards_accounts()
print(opted_out)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
opted_out = await client.fetch_opted_out_of_rewards_accounts()
# Suggest adding detailed output formatting
print(opted_out)
except Exception as e:
print(f"Failed to fetch Opted Out of Rewards Accounts: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

30 changes: 30 additions & 0 deletions examples/chain_client/exchange/query/52_MarketVolatility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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)

market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
trade_grouping_sec = 10
max_age = 0
include_raw_history = True
include_metadata = True
volatility = await client.fetch_market_volatility(
market_id=market_id,
trade_grouping_sec=trade_grouping_sec,
max_age=max_age,
include_raw_history=include_raw_history,
include_metadata=include_metadata,
)
print(volatility)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +30

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script for querying market volatility is clear and follows the established pattern for async operations within the project. A few suggestions for enhancement include:

  • Parameterization: The market_id, trade_grouping_sec, max_age, include_raw_history, and include_metadata are hardcoded. Consider parameterizing these values to increase the script's flexibility and usability for different use cases.
  • Error Handling: Similar to the previous file, adding error handling around the await client.fetch_market_volatility(...) call would improve the script's robustness by gracefully handling potential exceptions.
+ try:
+     volatility = await client.fetch_market_volatility(
+         market_id=market_id,
+         trade_grouping_sec=trade_grouping_sec,
+         max_age=max_age,
+         include_raw_history=include_raw_history,
+         include_metadata=include_metadata,
+     )
+     print(volatility)
+ except Exception as e:
+     print(f"Failed to fetch market volatility: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
trade_grouping_sec = 10
max_age = 0
include_raw_history = True
include_metadata = True
volatility = await client.fetch_market_volatility(
market_id=market_id,
trade_grouping_sec=trade_grouping_sec,
max_age=max_age,
include_raw_history=include_raw_history,
include_metadata=include_metadata,
)
print(volatility)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
market_id = "0x0611780ba69656949525013d947713300f56c37b6175e02f26bffa495c3208fe"
trade_grouping_sec = 10
max_age = 0
include_raw_history = True
include_metadata = True
try:
volatility = await client.fetch_market_volatility(
market_id=market_id,
trade_grouping_sec=trade_grouping_sec,
max_age=max_age,
include_raw_history=include_raw_history,
include_metadata=include_metadata,
)
print(volatility)
except Exception as e:
print(f"Failed to fetch market volatility: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

19 changes: 19 additions & 0 deletions examples/chain_client/exchange/query/53_BinaryOptionsMarkets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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)

markets = await client.fetch_chain_binary_options_markets(status="Active")
print(markets)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +7 to +19

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example, which utilizes the fetch_chain_binary_options_markets method, could benefit from:

  • Adding error handling to address potential exceptions from the async call.
  • Improving the output formatting to make the complex data structures more accessible and understandable to users.
-    markets = await client.fetch_chain_binary_options_markets(status="Active")
+    try:
+        markets = await client.fetch_chain_binary_options_markets(status="Active")
+        # Recommend improving output formatting for better data clarity
+        print(markets)
+    except Exception as e:
+        print(f"Failed to fetch Binary Options Markets: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
markets = await client.fetch_chain_binary_options_markets(status="Active")
print(markets)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
async def main() -> None:
# select network: local, testnet, mainnet
network = Network.testnet()
# initialize grpc client
client = AsyncClient(network)
try:
markets = await client.fetch_chain_binary_options_markets(status="Active")
# Recommend improving output formatting for better data clarity
print(markets)
except Exception as e:
print(f"Failed to fetch Binary Options Markets: {e}")
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_trader_derivative_conditional_orders(
subaccount_id=subaccount_id,
market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
)
print(orders)


if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
Comment on lines +11 to +37

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script for querying trader derivative conditional orders is well-structured. Recommendations for further improvement include:

  • Error Handling: Implement error handling around the await client.fetch_trader_derivative_conditional_orders(...) call to better manage potential exceptions.
  • Parameterization: The subaccount_id and market_id are derived from the loaded account and hardcoded, respectively. Consider allowing these values to be passed as arguments or read from environment variables for greater flexibility.
+ try:
+     orders = await client.fetch_trader_derivative_conditional_orders(
+         subaccount_id=subaccount_id,
+         market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
+     )
+     print(orders)
+ except Exception as e:
+     print(f"Failed to fetch trader derivative conditional orders: {e}")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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_trader_derivative_conditional_orders(
subaccount_id=subaccount_id,
market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
)
print(orders)
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())
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)
try:
orders = await client.fetch_trader_derivative_conditional_orders(
subaccount_id=subaccount_id,
market_id="0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6",
)
print(orders)
except Exception as e:
print(f"Failed to fetch trader derivative conditional orders: {e}")
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

Loading