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

How to get new announcement from Binance asap? #913

Open
plzbugmenot opened this issue Dec 3, 2024 · 0 comments
Open

How to get new announcement from Binance asap? #913

plzbugmenot opened this issue Dec 3, 2024 · 0 comments

Comments

@plzbugmenot
Copy link

Hello, coders.

I am currently working on a project.
I need to get new announcements from https://www.binance.com/en/support/announcement/new-cryptocurrency-listing?c=48 as soon as possible.
I want to get new announcements within 1-2 seconds.
The current codebase is implemented with Python Scrapping.

URL = https://www.binance.com/en/support/announcement/new-cryptocurrency-listing?c=48

    async def fetch_with_retry(url: str, method: str = 'GET', max_retries: int = 1, **kwargs) -> Optional[str]:
        start_time = time.time()
        async with aiohttp.ClientSession() as session:
            for attempt in range(max_retries):
                try:
                    async with session.request(method, url, **kwargs) as response:
                        response.raise_for_status()
                        text = await response.text()
                        return text
                except aiohttp.ClientError as e:
                    if attempt == max_retries - 1:
                        return None
                    await asyncio.sleep(2 ** attempt)  # Exponential backoff
        return None

    async def fetch_announcements(self) -> Optional[str]:
        response = await self.fetch_with_retry(
            f"http://api.scrape.do/?token={API_KEY}&url={URL}",
            GET_MODE,
            headers=HEADERS
        )
        if response:
            return response
        return None

But it takes 10 seconds.

I have two questions:

  1. Is it possible to get new announcements using API instead of scraping?

  2. How can I reduce the time by using scraping?

I hope hear from you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant