2

I'm using the CoinGecko api to get real-time price data on several cryptocurrencies in an ASP.NET Core MVC web application. CoinGecko's price data is updated every 1-10 minutes, so I want to request price data probably every 5 minutes. I want the data to refresh on the client-side so the user doesn't have to refresh the page to see up-to-date data. I want that data to be displayed in a line graph chart.

I want to make sure I'm thinking about this correctly so here's my current thought process:

I can use SignalR to create an open connection between the client and the server, so the client does not have to refresh to get coingecko api data. I chose SignalR because it will choose the best transport technique for the situation, and I know very little about websockets, long-polling, etc.

As far as displaying that data, I've decided to use the Highcharts library, since it's easy to learn.

So essentially my question is, how do I get real time web api data at set intervals and display it in a chart without having to refresh the client? Is my thought process correct?

Any helpful insights or links to articles would be appreciated. I'm not really sure how to proceed so I want to make sure I'm not wasting my time.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ethan Partridge
  • 147
  • 3
  • 12

1 Answers1

3

You could try to create scheduled Background tasks with hosted services. Then, you can also use the Cronos package and the Cron Expressions to configure the scheduled task, and set the Cron Expressions to run the task at special date range or run the Schedule Job per 5 minutes.

More detail about creating a scheduled tasks, see How can I execute a method every year using BackgroundService in ASP.NET core Application?.

Then, in the task, you can call the CoinGecko api to get the latest data, then, inject an instance of IHubContext and call the client method to send the data to the client and display them.

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30