Skip to content

Commit

Permalink
Merge pull request #8 from trungtt198x/iota
Browse files Browse the repository at this point in the history
Add again the IOTA on-chain amount via L1 API
  • Loading branch information
trungtt198x authored Jun 7, 2024
2 parents 662f310 + 4425440 commit 3c0805a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
24 changes: 12 additions & 12 deletions helpers/smr_market_data/smd_shimmer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""""
Copyright © antonionardella 2023 - https://github.com/antonionardella (https://antonionardella.it)
Description:
Get API data for Shimmer from Shimmer API
Get API data for IOTA from IOTA API
Version: 5.5.0
"""
import requests
Expand All @@ -13,24 +13,24 @@
# Load configuration
config = configuration_manager.load_config('config.json')

# Shimmer data
# IOTA data
shimmer_onchain_deposit_alias = config["shimmer_onchain_deposit_alias"]

async def get_shimmer_data():
"""
Get Shimmer API data for the specified on-chain deposit alias.
Get IOTA API data for the specified on-chain deposit alias.
Returns:
dict: Dictionary containing Shimmer's on-chain token amount.
dict: Dictionary containing IOTA's on-chain token amount.
"""
logger.info("Getting data from Shimmer API")
shimmer_explorer_api_url = f"https://api.shimmer.network/api/indexer/v1/outputs/alias/{shimmer_onchain_deposit_alias}"
logger.info("Getting data from IOTA API")
shimmer_explorer_api_url = f"https://api.stardust-mainnet.iotaledger.net/api/indexer/v1/outputs/alias/{shimmer_onchain_deposit_alias}"
headers = {"accept": "application/json"}

try:
shimmer_api_response = requests.get(shimmer_explorer_api_url, headers=headers, timeout=10)
shimmer_api_response.raise_for_status()
logger.debug("Shimmer Explorer API response: %s", shimmer_api_response.text)
logger.debug("IOTA Explorer API response: %s", shimmer_api_response.text)

if shimmer_api_response.status_code == 200:
# Extract and parse the JSON response
Expand All @@ -39,29 +39,29 @@ async def get_shimmer_data():
shimmer_onchain_token_amount = None

if response_output_id:
output_url = f"https://api.shimmer.network/api/core/v2/outputs/{response_output_id}"
output_url = f"https://api.stardust-mainnet.iotaledger.net/api/core/v2/outputs/{response_output_id}"
while True:
response_output_id = requests.get(output_url)
output_id_data = response_output_id.json()

if output_id_data.get("metadata", {}).get("isSpent"):
item_content = output_id_data.get("metadata", {}).get("transactionIdSpent")
output_url = f"https://api.shimmer.network/api/core/v2/outputs/{item_content}"
output_url = f"https://api.stardust-mainnet.iotaledger.net/api/core/v2/outputs/{item_content}"
else:
shimmer_onchain_token_amount = output_id_data.get("output", {}).get("amount")
break

if shimmer_onchain_token_amount is not None:
logger.debug("Shimmer On Chain Amount: %s", shimmer_onchain_token_amount)
logger.debug("IOTA On Chain Amount: %s", shimmer_onchain_token_amount)
return {"shimmer_onchain_token_amount": shimmer_onchain_token_amount}
else:
logger.debug("Shimmer TVL Value not found in the response.")
logger.debug("IOTA TVL Value not found in the response.")

else:
logger.debug("Error: Unable to fetch data from the API.")

except requests.exceptions.Timeout:
logger.error("Shimmer API request timed out.")
logger.error("IOTA API request timed out.")
except requests.exceptions.HTTPError as errh:
logger.error("HTTP Error occurred: %s", errh)
except requests.exceptions.RequestException as err:
Expand Down
4 changes: 2 additions & 2 deletions helpers/smr_market_data_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def build_embed():
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name="Defi Data", value="\u200b", inline=False)
embed.add_field(name="IOTA Rank (DefiLlama)", value=iota_rank, inline=True)
# embed.add_field(name="IOTA Onchain Amount (Shimmer API)", value=f"{await format_currency(await format_shimmer_amount(shimmer_data['shimmer_onchain_token_amount']), 'SMR')}", inline=True)
embed.add_field(name="IOTA on-chain amount (IOTA API)", value=f"{await format_currency(await format_shimmer_amount(shimmer_data['shimmer_onchain_token_amount']), 'IOTA')}", inline=True)
embed.add_field(name="Total Value Locked (DefiLlama)", value=f"{await format_currency(defillama_data['iota_tvl'])}", inline=True)
# embed.add_field(name="24h DeFi Transactions (GeckoTerminal)", value=total_defi_tx_24h, inline=True)
# embed.add_field(name="24h DeFi Volume (GeckoTerminal)", value=f"{await format_currency(geckoterminal_data['defi_total_volume'])}", inline=True)
Expand All @@ -118,7 +118,7 @@ async def build_embed():
# Add additional information
embed.add_field(name="Sources", value="Bitfinex, Coingecko, DefiLlama, GeckoTerminal, IOTA API", inline=False)
embed.add_field(name="Last Data Update", value=f"{discord_timestamp}", inline=False)
embed.set_footer(text="Data updated every 24h\nMade with IOTA-❤️ by Antonio\nOut of beta SOON™")
embed.set_footer(text="Data updated every 24h\nMade with IOTA-❤️ by Holger and Mido")

# Save the embed to a pickle file
with open("assets/embed_shimmer_market_data.pkl", "wb") as f:
Expand Down

0 comments on commit 3c0805a

Please sign in to comment.