Exemplo n.º 1
0
    async def job_queue(self):
        while True:
            try:
                await sleep(Utils.seconds_until_cycle())
                t = datetime.now().astimezone(utc)
                timeframes = Utils.get_accepted_timeframes(t)

                isPremium = self.tickerId in [
                    "EURUSD", "GBPUSD", "AUDJPY", "AUDUSD", "EURJPY", "GBPJPY",
                    "NZDJPY", "NZDUSD", "CADUSD", "JPYUSD", "ZARUSD"
                ]
                if len(client.guilds) == 1:
                    refreshRate = "8H"
                elif isPremium and len(client.guilds) < 15:
                    refreshRate = "1H"
                else:
                    refreshRate = "5m"

                if refreshRate in timeframes and not self.updatingNickname:
                    client.loop.create_task(self.update_nicknames())
                if "1H" in timeframes:
                    client.loop.create_task(self.update_properties())

            except CancelledError:
                return
            except Exception:
                print(format_exc())
                if environ["PRODUCTION_MODE"]: self.logging.report_exception()
Exemplo n.º 2
0
	def job_queue(self):
		while True:
			try:
				time.sleep(Utils.seconds_until_cycle())
				t = datetime.datetime.now().astimezone(pytz.utc)
				timeframes = Utils.get_accepted_timeframes(t)

				if "1h" in timeframes:
					TickerParserServer.refresh_parser_index()

			except Exception:
				print(traceback.format_exc())
				if os.environ["PRODUCTION_MODE"]: self.logging.report_exception()
Exemplo n.º 3
0
	def run(self):
		while self.isServiceAvailable:
			try:
				sleep(Utils.seconds_until_cycle())
				t = datetime.now().astimezone(utc)
				timeframes = Utils.get_accepted_timeframes(t)

				if "1m" in timeframes:
					self.update_accounts()
					self.process_price_alerts()

			except (KeyboardInterrupt, SystemExit): return
			except Exception:
				print(format_exc())
				if environ["PRODUCTION_MODE"]: self.logging.report_exception()
Exemplo n.º 4
0
    def job_queue(self):
        while True:
            try:
                time.sleep(Utils.seconds_until_cycle())
                t = datetime.datetime.now().astimezone(pytz.utc)
                timeframes = Utils.get_accepted_timeframes(t)

                if "4H" in timeframes:
                    self.update_popular_tickers()

            except (KeyboardInterrupt, SystemExit):
                return
            except Exception:
                print(traceback.format_exc())
                if os.environ["PRODUCTION_MODE"]:
                    self.logging.report_exception()
Exemplo n.º 5
0
    async def job_queue(self):
        while True:
            try:
                await sleep(Utils.seconds_until_cycle())
                t = datetime.now().astimezone(utc)
                timeframes = Utils.get_accepted_timeframes(t)

                if "1m" in timeframes:
                    await self.update_system_status(t)
                if "15m" in timeframes:
                    client.loop.create_task(self.update_alpha_guild_roles())
            except CancelledError:
                return
            except Exception:
                print(format_exc())
                if environ["PRODUCTION_MODE"]: self.logging.report_exception()
Exemplo n.º 6
0
	def job_queue(self):
		while True:
			try:
				sleep(Utils.seconds_until_cycle())
				t = datetime.now().astimezone(utc)
				timeframes = Utils.get_accepted_timeframes(t)

				if "1H" in timeframes:
					self.refresh_ccxt_index()
					self.refresh_coingecko_index()
					self.refresh_serum_index()
					self.refresh_coingecko_exchange_rates()
				if "1D" in timeframes:
					self.refresh_iexc_index()

			except Exception:
				print(format_exc())
				if environ["PRODUCTION_MODE"]: self.logging.report_exception()
Exemplo n.º 7
0
    async def job_queue(self):
        """Executes scheduled jobs as long as Alpha Bot is online

		"""

        while True:
            try:
                await asyncio.sleep(Utils.seconds_until_cycle())
                t = datetime.datetime.now().astimezone(pytz.utc)
                timeframes = Utils.get_accepted_timeframes(t)

                if "5m" in timeframes:
                    await self.update_alpha_guild_roles()
            except asyncio.CancelledError:
                return
            except Exception:
                print(traceback.format_exc())
                if os.environ["PRODUCTION_MODE"]:
                    self.logging.report_exception()
Exemplo n.º 8
0
    async def job_queue(self):
        """Updates Alpha Bot user status with latest prices

		"""

        while True:
            try:
                await asyncio.sleep(Utils.seconds_until_cycle())
                if not await self.guildProperties.check_status(): continue
                t = datetime.datetime.now().astimezone(pytz.utc)
                timeframes = Utils.get_accepted_timeframes(t)

                isPremium = self.tickerId in [
                    "EURUSD", "GBPUSD", "AUDJPY", "AUDUSD", "EURJPY", "GBPJPY",
                    "NZDJPY", "NZDUSD", "CADUSD", "JPYUSD", "ZARUSD"
                ]
                refreshRate = "5m" if len(client.guilds) > 1 and (
                    not isPremium or len(client.guilds) > 15) else "15m"

                if "1m" in timeframes:
                    self.get_assigned_id()
                if refreshRate in timeframes:
                    await asyncio.sleep(self.timeOffset)

                    try:
                        outputMessage, request = Processor.process_quote_arguments(
                            client.user.id,
                            [] if self.exchange is None else [self.exchange],
                            tickerId=self.tickerId,
                            platformQueue=[self.platform])
                    except:
                        continue
                    if outputMessage is not None:
                        print(outputMessage)
                        if os.environ["PRODUCTION_MODE"]:
                            self.logging.report(outputMessage)
                        continue

                    try:
                        payload, quoteText = await Processor.execute_data_server_request(
                            "quote", request, timeout=30)
                    except:
                        continue
                    if payload is None or payload["quotePrice"] is None:
                        print("Requested price for `{}` is not available".
                              format(request.get_ticker().name
                                     ) if quoteText is None else quoteText)
                        continue

                    self.priceText = "{} {}".format(payload["quotePrice"],
                                                    payload["quoteTicker"])
                    changeText = "" if payload[
                        "change"] is None else "{:+.2f} % | ".format(
                            payload["change"])
                    tickerText = "{} | ".format(
                        request.get_ticker().id) if request.get_exchange(
                        ) is None else "{} on {} | ".format(
                            request.get_ticker().id,
                            request.get_exchange().name)
                    statusText = "{}{}alphabotsystem.com".format(
                        changeText, tickerText)
                    status = discord.Status.online if payload[
                        "change"] is None or payload[
                            "change"] >= 0 else discord.Status.dnd

                    for guild in client.guilds:
                        properties = await self.guildProperties.get(guild.id)
                        if properties is None:
                            continue
                        elif not self.isFree and not properties["addons"][
                                "satellites"]["enabled"]:
                            try:
                                await guild.me.edit(nick="Disabled")
                            except:
                                continue
                        elif self.isFree or properties["addons"]["satellites"][
                                "connection"] is not None:
                            try:
                                await guild.me.edit(nick=self.priceText)
                            except:
                                continue
                        else:
                            try:
                                await guild.me.edit(nick="Alpha Pro required")
                            except:
                                continue

                    try:
                        await client.change_presence(
                            status=status,
                            activity=discord.Activity(
                                type=discord.ActivityType.watching,
                                name=statusText))
                    except:
                        pass

            except asyncio.CancelledError:
                return
            except Exception:
                print(traceback.format_exc())
                if os.environ["PRODUCTION_MODE"]:
                    self.logging.report_exception()