|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -from typing import TYPE_CHECKING |
| 3 | +from typing import TYPE_CHECKING, Any, Dict, List |
4 | 4 |
|
5 | 5 | from datetime import UTC, time, datetime, timedelta
|
6 | 6 |
|
|
12 | 12 | from discord.ext.menus.views import ViewMenuPages
|
13 | 13 |
|
14 | 14 | from utils.cd import cooldown
|
15 |
| -from utils.paginators import TradeOgrePaginatorSource, HistoricalPricePaginatorSource |
| 15 | +from utils.paginators import ( |
| 16 | + XeggeXPaginatorSource, |
| 17 | + TradeOgrePaginatorSource, |
| 18 | + HistoricalPricePaginatorSource, |
| 19 | +) |
16 | 20 |
|
17 | 21 | if TYPE_CHECKING:
|
18 | 22 | from bot import RoboNerva
|
@@ -181,44 +185,57 @@ async def _tradeogre(self, ctx: discord.Interaction):
|
181 | 185 | # noinspection PyUnresolvedReferences
|
182 | 186 | await ctx.response.defer(thinking=True)
|
183 | 187 |
|
184 |
| - entries = list() |
185 |
| - |
186 |
| - async with aiohttp.ClientSession() as session: |
187 |
| - async with session.get( |
188 |
| - "https://tradeogre.com/api/v1/ticker/xnv-btc" |
189 |
| - ) as res: |
190 |
| - data = await res.json(content_type=None) |
191 |
| - |
192 |
| - entry = { |
193 |
| - "pair": "XNV-BTC", |
194 |
| - "last_price": f"{round(float(data['price']) * 100_000_000)} sat", |
195 |
| - "bid": f"{round(float(data['bid']) * 100_000_000)} sat", |
196 |
| - "ask": f"{round(float(data['ask']) * 100_000_000)} sat", |
197 |
| - "volume": f"{float(data['volume'])} BTC", |
198 |
| - "high": f"{round(float(data['high']) * 100_000_000)} sat", |
199 |
| - "low": f"{round(float(data['low']) * 100_000_000)} sat", |
200 |
| - } |
201 |
| - |
202 |
| - entries.append(entry) |
203 |
| - |
204 |
| - async with session.get( |
205 |
| - "https://tradeogre.com/api/v1/ticker/xnv-usdt" |
206 |
| - ) as res: |
207 |
| - data = await res.json(content_type=None) |
208 |
| - |
209 |
| - entry = { |
210 |
| - "pair": "XNV-USDT", |
211 |
| - "last_price": f"${round(float(data['price']), 4)}", |
212 |
| - "bid": f"${round(float(data['bid']), 4)}", |
213 |
| - "ask": f"${round(float(data['ask']), 4)}", |
214 |
| - "volume": f"${round(float(data['volume']), 2)}", |
215 |
| - "high": f"${round(float(data['high']), 4)}", |
216 |
| - "low": f"${round(float(data['low']), 4)}", |
217 |
| - } |
218 |
| - |
219 |
| - entries.append(entry) |
220 |
| - |
221 |
| - pages = TradeOgrePaginatorSource(entries=entries, ctx=ctx) |
| 188 | + market_data: List[Dict] = list() |
| 189 | + |
| 190 | + for pair in self.bot.config.TRADEOGRE_MARKET_PAIRS: |
| 191 | + async with aiohttp.ClientSession() as session: |
| 192 | + async with session.get( |
| 193 | + f"https://tradeogre.com/api/v1/ticker/{pair.lower()}" |
| 194 | + ) as res: |
| 195 | + data: Dict[str, Any] = await res.json(content_type=None) |
| 196 | + |
| 197 | + if "error" in data: |
| 198 | + continue |
| 199 | + |
| 200 | + else: |
| 201 | + last_price: str |
| 202 | + bid: str |
| 203 | + ask: str |
| 204 | + volume: str |
| 205 | + high: str |
| 206 | + low: str |
| 207 | + |
| 208 | + if pair.endswith("BTC"): |
| 209 | + last_price = ( |
| 210 | + f"{round(float(data['price']) * 100_000_000)} sat" |
| 211 | + ) |
| 212 | + bid = f"{round(float(data['bid']) * 100_000_000)} sat" |
| 213 | + ask = f"{round(float(data['ask']) * 100_000_000)} sat" |
| 214 | + volume = f"{float(data['volume'])} BTC" |
| 215 | + high = f"{round(float(data['high']) * 100_000_000)} sat" |
| 216 | + low = f"{round(float(data['low']) * 100_000_000)} sat" |
| 217 | + |
| 218 | + else: |
| 219 | + last_price = f"${round(float(data['price']), 4)}" |
| 220 | + bid = f"${round(float(data['bid']), 4)}" |
| 221 | + ask = f"${round(float(data['ask']), 4)}" |
| 222 | + volume = f"${round(float(data['volume']), 2)}" |
| 223 | + high = f"${round(float(data['high']), 4)}" |
| 224 | + low = f"${round(float(data['low']), 4)}" |
| 225 | + |
| 226 | + market_data.append( |
| 227 | + { |
| 228 | + "pair": pair, |
| 229 | + "last_price": last_price, |
| 230 | + "bid": bid, |
| 231 | + "ask": ask, |
| 232 | + "volume": volume, |
| 233 | + "high": high, |
| 234 | + "low": low, |
| 235 | + } |
| 236 | + ) |
| 237 | + |
| 238 | + pages = TradeOgrePaginatorSource(entries=market_data, ctx=ctx) |
222 | 239 | paginator = ViewMenuPages(
|
223 | 240 | source=pages,
|
224 | 241 | timeout=300,
|
@@ -246,45 +263,83 @@ async def _xeggex(self, ctx: discord.Interaction):
|
246 | 263 | "q=tbn:ANd9GcQge9tw8HHcbwBXNALMQvysPoL6s-bFhJjA3g&s"
|
247 | 264 | )
|
248 | 265 |
|
249 |
| - async with aiohttp.ClientSession() as session: |
250 |
| - async with session.get( |
251 |
| - "https://api.xeggex.com/api/v2/market/getbysymbol/XNV_USDT" |
252 |
| - ) as res: |
253 |
| - data = await res.json() |
254 |
| - |
255 |
| - embed.add_field( |
256 |
| - name="Last Price", value=f"${round(float(data['lastPrice']), 4)}" |
257 |
| - ) |
258 |
| - embed.add_field( |
259 |
| - name="Bid", value=f"${round(float(data['bestBid']), 4)}" |
260 |
| - ) |
261 |
| - embed.add_field( |
262 |
| - name="Ask", value=f"${round(float(data['bestAsk']), 4)}" |
263 |
| - ) |
264 |
| - embed.add_field( |
265 |
| - name="Volume", value=f"{round(float(data['volume']), 2)}" |
266 |
| - ) |
267 |
| - embed.add_field( |
268 |
| - name="High", value=f"${round(float(data['highPrice']), 4)}" |
269 |
| - ) |
270 |
| - embed.add_field( |
271 |
| - name="Low", value=f"${round(float(data['lowPrice']), 4)}" |
272 |
| - ) |
273 |
| - embed.add_field( |
274 |
| - name="Last Trade", |
275 |
| - value=f"<t:{data['lastTradeAt'] // 1000}:F> " |
276 |
| - f"(<t:{data['lastTradeAt'] // 1000}:R>)", |
277 |
| - ) |
278 |
| - |
279 |
| - view = discord.ui.View() |
280 |
| - view.add_item( |
281 |
| - discord.ui.Button( |
282 |
| - label="Xeggex (XNV-USDT)", |
283 |
| - url="https://xeggex.com/market/XNV_USDT", |
284 |
| - ) |
| 266 | + market_data: List[Dict] = list() |
| 267 | + |
| 268 | + for pair in self.bot.config.XEGGEX_MARKET_PAIRS: |
| 269 | + async with aiohttp.ClientSession() as session: |
| 270 | + async with session.get( |
| 271 | + f"https://api.xeggex.com/api/v2/market/getbysymbol/{pair.replace('-', '_')}" |
| 272 | + ) as res: |
| 273 | + data: Dict[str, Any] = await res.json() |
| 274 | + |
| 275 | + if "error" in data: |
| 276 | + continue |
| 277 | + |
| 278 | + else: |
| 279 | + last_price: str |
| 280 | + bid: str |
| 281 | + ask: str |
| 282 | + volume: str |
| 283 | + high: str |
| 284 | + low: str |
| 285 | + last_trade: str |
| 286 | + |
| 287 | + if pair.endswith("BTC"): |
| 288 | + last_price = f"{round(float(data['lastPrice']) * 100_000_000)} sat" |
| 289 | + bid = ( |
| 290 | + f"{round(float(data['bestBid']) * 100_000_000)} sat" |
| 291 | + ) |
| 292 | + ask = ( |
| 293 | + f"{round(float(data['bestAsk']) * 100_000_000)} sat" |
| 294 | + ) |
| 295 | + volume = f"{float(data['volumeSecondary'])} BTC" |
| 296 | + high = f"{round(float(data['highPrice']) * 100_000_000)} sat" |
| 297 | + low = ( |
| 298 | + f"{round(float(data['lowPrice']) * 100_000_000)} sat" |
| 299 | + ) |
| 300 | + last_trade = data["lastTradeAt"] // 1000 |
| 301 | + |
| 302 | + elif pair.endswith("USDT") or pair.endswith("USDC"): |
| 303 | + last_price = f"${round(float(data['lastPrice']), 4)}" |
| 304 | + bid = f"${round(float(data['bestBid']), 4)}" |
| 305 | + ask = f"${round(float(data['bestAsk']), 4)}" |
| 306 | + volume = f"${round(float(data['volumeSecondary']), 2)}" |
| 307 | + high = f"${round(float(data['highPrice']), 4)}" |
| 308 | + low = f"${round(float(data['lowPrice']), 4)}" |
| 309 | + last_trade = data["lastTradeAt"] // 1000 |
| 310 | + |
| 311 | + else: |
| 312 | + last_price = f"{round(float(data['lastPrice']), 4)} XPE" |
| 313 | + bid = f"{round(float(data['bestBid']), 4)} XPE" |
| 314 | + ask = f"{round(float(data['bestAsk']), 4)} XPE" |
| 315 | + volume = f"{float(data['volumeSecondary'])} XPE" |
| 316 | + high = f"{round(float(data['highPrice']), 4)} XPE" |
| 317 | + low = f"{round(float(data['lowPrice']), 4)} XPE" |
| 318 | + last_trade = data["lastTradeAt"] // 1000 |
| 319 | + |
| 320 | + market_data.append( |
| 321 | + { |
| 322 | + "pair": pair, |
| 323 | + "last_price": last_price, |
| 324 | + "bid": bid, |
| 325 | + "ask": ask, |
| 326 | + "volume": volume, |
| 327 | + "high": high, |
| 328 | + "low": low, |
| 329 | + "last_trade": last_trade, |
| 330 | + } |
| 331 | + ) |
| 332 | + |
| 333 | + pages = XeggeXPaginatorSource(entries=market_data, ctx=ctx) |
| 334 | + paginator = ViewMenuPages( |
| 335 | + source=pages, |
| 336 | + timeout=300, |
| 337 | + delete_message_after=False, |
| 338 | + clear_reactions_after=True, |
285 | 339 | )
|
286 | 340 |
|
287 |
| - await ctx.edit_original_response(embed=embed, view=view) |
| 341 | + await ctx.edit_original_response(content="\U0001f44c") |
| 342 | + await paginator.start(ctx) |
288 | 343 |
|
289 | 344 | @app_commands.command(name="history")
|
290 | 345 | @app_commands.guilds(COMMUNITY_GUILD_ID)
|
|
0 commit comments