Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IOTA-related market data #3

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 7 additions & 7 deletions cogs/smr_market.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:
Shimmer market data
IOTA market data

Version: 5.5.0
"""
Expand Down Expand Up @@ -32,13 +32,13 @@ def __init__(self, bot):
@commands.cooldown(1, 360, commands.BucketType.user)
@commands.hybrid_command(
name="smr-market",
description="Shares the Shimmer market data",
description="Shares the IOTA market data",
)
# This will only allow non-blacklisted members to execute the command
@checks.not_blacklisted()
async def shimmer_market_data(self, context: Context) -> None:
"""
This command prints an embed with the Shimmer Market data
This command prints an embed with the IOTA Market data

:param context: The application command context.
"""
Expand All @@ -61,27 +61,27 @@ async def shimmer_market_data(self, context: Context) -> None:
@commands.cooldown(1, 360, commands.BucketType.user)
@commands.hybrid_command(
name="updatesmd",
description="Force updates the Shimmer market data (Admin only)",
description="Force updates the IOTA market data (Admin only)",
)
# This will only allow owners to execute the command
@checks.is_owner()
async def updatesmd(self, context: Context) -> None:
"""
This command forces an update of Shimmer Market data
This command forces an update of IOTA Market data

:param context: The application command context.
"""
try:
await context.send(
"Hello! Shimmer Market Data update launced...", ephemeral=True
"Hello! IOTA Market Data update launced...", ephemeral=True
)
await build_embed()

except Exception:
print(traceback.format_exc())

await context.send(
"Hello! Shimmer Market Data update finished.", ephemeral=True
"Hello! IOTA Market Data update finished.", ephemeral=True
)

# And then we finally add the cog to the bot so that it can load, unload, reload and use it's content.
Expand Down
4 changes: 2 additions & 2 deletions helpers/embed_and_messages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
""""
Copyright © antonionardella 2023 - https://github.com/antonionardella (https://linkfree.antonionardella.it)
Description:
This file contains functions for the Shimmer data
This file contains functions for the IOTA data

Version: 5.4
"""
Expand All @@ -11,7 +11,7 @@


async def create_empty_embed_and_messages():
embed = discord.Embed(title="Shimmer Market Data", color=0x00FF00)
embed = discord.Embed(title="IOTA Market Data", color=0x00FF00)

embed.add_field(name="Updates: ", value="Every 24h")
embed.add_field(
Expand Down
10 changes: 5 additions & 5 deletions helpers/smr_market_data/smd_coingecko.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 CoinGecko API
Get API data for IOTA from CoinGecko API
Version: 5.5.0
"""
import requests
Expand All @@ -13,17 +13,17 @@
# Load configuration
config = configuration_manager.load_config('config.json')

# Shimmer data
# IOTA data
coingecko_coin_id = config["coingecko_coin_id"]
coingecko_exchange_id = config["coingecko_exchange_id"]


async def get_coingecko_exchange_data():
"""
Get Coingecko exchange data for Shimmer (SMR) cryptocurrency.
Get Coingecko exchange data for IOTA cryptocurrency.

Returns:
dict: A dictionary containing the latest USD price and 24h total volume for Shimmer.
dict: A dictionary containing the latest USD price and 24h total volume for IOTA.
Example: {"usd_price": 0.1234, "total_volume": 1234567.89}
Raises:
requests.exceptions.RequestException: If there is an issue with the HTTP request to the Coingecko API.
Expand All @@ -45,7 +45,7 @@ async def get_coingecko_exchange_data():
twentyfourh_volume = usd_volume + usdt_volume

logger.debug("Last USD Price: %s", usd_price)
logger.debug("Total USD Converted Volume for Shimmer: %s", twentyfourh_volume)
logger.debug("Total USD Converted Volume for IOTA: %s", twentyfourh_volume)

return {"usd_price": usd_price, "total_volume": twentyfourh_volume}

Expand Down
22 changes: 11 additions & 11 deletions helpers/smr_market_data/smd_defillama.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 DefiLlama API
Get API data for IOTA from DefiLlama API
Version: 5.5.0
"""
import requests
Expand All @@ -15,15 +15,15 @@

async def get_defillama_data():
"""
Get DefiLlama TVL data for ShimmerEVM.
Get DefiLlama TVL data for IOTA EVM.

Returns:
dict: Dictionary containing ShimmerEVM TVL and rank.
dict: Dictionary containing IOTA EVM TVL and rank.
"""
logger.info("Getting the DefiLlama TVL and rank")
defillama_url = "https://api.llama.fi/v2/chains"
headers = {"accept": "*/*"}
shimmer_tvl = None
iota_tvl = None
rank = None

try:
Expand All @@ -33,17 +33,17 @@ async def get_defillama_data():

if tvl_response.status_code == 200:
tvl_data = tvl_response.json()
shimmer_entry = next((entry for entry in tvl_data if entry.get("name") == "ShimmerEVM"), None)
iota_entry = next((entry for entry in tvl_data if entry.get("name") == "IOTA EVM"), None)

if shimmer_entry:
shimmer_tvl = shimmer_entry.get("tvl")
if iota_entry:
iota_tvl = iota_entry.get("tvl")
tvl_data.sort(key=lambda x: x.get("tvl", 0), reverse=True)
rank = tvl_data.index(shimmer_entry) + 1
rank = tvl_data.index(iota_entry) + 1

logger.debug("Shimmer TVL Value: %s", shimmer_tvl)
logger.debug("Shimmer TVL Rank: %s", rank)
logger.debug("IOTA TVL Value: %s", iota_tvl)
logger.debug("IOTA TVL Rank: %s", rank)

return {"shimmer_tvl": shimmer_tvl, "shimmer_rank": rank}
return {"iota_tvl": iota_tvl, "iota_rank": rank}

except requests.exceptions.Timeout:
logger.error("DefiLlama API request timed out.")
Expand Down
14 changes: 7 additions & 7 deletions helpers/smr_market_data/smd_geckoterminal.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 GeckoTerminal API
Get API data for IOTA from GeckoTerminal API
Version: 5.5.0
"""
import requests
Expand All @@ -13,18 +13,18 @@
# Load configuration
config = configuration_manager.load_config('config.json')

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


async def get_geckoterminal_data():
"""
Get GeckoTerminal Defi Volume data for ShimmerEVM.
Get GeckoTerminal Defi Volume data for IOTA EVM.

Returns:
dict: Dictionary containing ShimmerEVM's total 24h volume and total 24h transactions.
dict: Dictionary containing IOTA EVM's total 24h volume and total 24h transactions.
"""
logger.info("Getting GeckoTerminal Defi Volume data for ShimmerEVM")
logger.info("Getting GeckoTerminal Defi Volume data for IOTA EVM")
geckoterminal_url = f"https://api.geckoterminal.com/api/v2/networks/{geckoterminal_ticker}/pools"
headers = {"accept": "application/json"}
total_defi_volume_usd_h24 = 0
Expand Down Expand Up @@ -54,12 +54,12 @@ async def get_geckoterminal_data():
total_defi_tx_24h += buys_h24 + sells_h24

logger.debug("Total USD 24h Volume for all pools: %s", total_defi_volume_usd_h24)
logger.debug("Total 24h Defi Transactions for ShimmerEVM: %s", total_defi_tx_24h)
logger.debug("Total 24h Defi Transactions for IOTA EVM: %s", total_defi_tx_24h)

if total_defi_volume_usd_h24 > 0 and total_defi_tx_24h > 0:
return {"defi_total_volume": total_defi_volume_usd_h24, "total_defi_tx_24h": total_defi_tx_24h}
else:
logger.debug("Shimmer Total Volume or Total Transactions not found in the response.")
logger.debug("IOTA Total Volume or Total Transactions not found in the response.")
elif defi_volume.status_code == 404:
logger.error("404 Client Error: Not Found for URL: %s", defi_volume.url)
else:
Expand Down
23 changes: 12 additions & 11 deletions helpers/smr_market_data_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def build_embed():
total_defi_tx_24h = geckoterminal_data["total_defi_tx_24h"]
shimmer_rank = defillama_data["shimmer_rank"]
discord_timestamp = await generate_discord_timestamp()

"""
# Set up Bitfinex order book depth
bitfinex_order_book_data = await calculate_total_bitfinex_depth(coingecko_data['usd_price'])
logger.debug("Final bitfinex_order_book_data: %s", bitfinex_order_book_data)
Expand All @@ -56,6 +56,7 @@ async def build_embed():
positive_order_book_depth_str_20_percent = ""
negative_order_book_depth_str_20_percent = ""


# Iterate through the order book data and format the strings
for percentage, data in bitfinex_order_book_data['total_order_book_depth'].items():

Expand Down Expand Up @@ -91,7 +92,7 @@ async def build_embed():
positive_order_book_depth_str_10_percent += buy_sell_info
elif int(percentage[:-1]) == 20:
positive_order_book_depth_str_20_percent += buy_sell_info

"""
# Create an embed instance
embed = discord.Embed(title="Shimmer Market Data", color=0x00FF00)
embed.add_field(name="Price (Coingecko)", value=f"{await format_currency(coingecko_data['usd_price'])}", inline=False)
Expand All @@ -104,15 +105,15 @@ async def build_embed():
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)
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name="ShimmerEVM Order Books", value="\u200b", inline=False)
embed.add_field(name="Order Book depth ±2%", value=f"{negative_order_book_depth_str_2_percent} {positive_order_book_depth_str_2_percent}", inline=True)
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name="Order Book depth ±5%", value=f"{negative_order_book_depth_str_5_percent} {positive_order_book_depth_str_5_percent}", inline=True)
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name="Order Book depth ±10%", value=f"{negative_order_book_depth_str_10_percent} {positive_order_book_depth_str_10_percent}", inline=True)
embed.add_field(name="\u200b", value="\u200b", inline=False)
embed.add_field(name="Order Book depth ±20%", value=f"{negative_order_book_depth_str_20_percent} {positive_order_book_depth_str_20_percent}", inline=True)
embed.add_field(name="\u200b", value="\u200b", inline=False)
# embed.add_field(name="ShimmerEVM Order Books", value="\u200b", inline=False)
# embed.add_field(name="Order Book depth ±2%", value=f"{negative_order_book_depth_str_2_percent} {positive_order_book_depth_str_2_percent}", inline=True)
# embed.add_field(name="\u200b", value="\u200b", inline=False)
# embed.add_field(name="Order Book depth ±5%", value=f"{negative_order_book_depth_str_5_percent} {positive_order_book_depth_str_5_percent}", inline=True)
# embed.add_field(name="\u200b", value="\u200b", inline=False)
# embed.add_field(name="Order Book depth ±10%", value=f"{negative_order_book_depth_str_10_percent} {positive_order_book_depth_str_10_percent}", inline=True)
# embed.add_field(name="\u200b", value="\u200b", inline=False)
# embed.add_field(name="Order Book depth ±20%", value=f"{negative_order_book_depth_str_20_percent} {positive_order_book_depth_str_20_percent}", inline=True)
# embed.add_field(name="\u200b", value="\u200b", inline=False)

# Add additional information
embed.add_field(name="Sources", value="Bitfinex, Coingecko, DefiLlama, GeckoTerminal, Shimmer API", inline=False)
Expand Down