tarkah / tickrs

Realtime ticker data in your terminal 📈
MIT License
1.17k stars 58 forks source link

Provide command line option to change refresh interval #13

Closed daniel-j-h closed 3 years ago

daniel-j-h commented 3 years ago

Hey hey :wave:

it would be great to have an option like -n, --interval or something like that (similar to watch?) so we can change the data update interval. When we only want to show e.g. the 5Y data, it makes no sense to request new data every few seconds and re-draw it.

tarkah commented 3 years ago

So on the 5Y graph, there are 2 API connections that occur. One is for the graph data, which only refreshes every 24 hours since the data points are daily. The second connection queries the current market price every second. I'd think you still want to see live price fluctuation even when looking at a 5yr view?

The one change I can think of is having the current market price API disabled when outside market hours so it doesn't make any requests.

Does this make sense?

tarkah commented 3 years ago

I'll add an interval option that can specify seconds. Interval, if passed, will be used to specify the current market price update speed.

Also, I'll use the max between the supplied interval and the default update for each timeframe.

For example, the 1 week time frame has an update interval of 5 minutes. If the user supplies an interval of 3 minutes, it'll still refresh every 5 since that's how often the API has new data. However if the user passes 10 minutes, it'll use 10 as the refresh interval for the graph data as well.

tarkah commented 3 years ago

@daniel-j-h I've create PR #14 to resolve this. I've tested with -i 5 and -i 10 for 5 and 10 seconds, respectively, and both appear to work great!

The cool part is this also cuts down on CPU usage. I added 20 stocks to test and with the default 1 second update, it used ~4.5% CPU. By passing -i 10, it cut down CPU usage to ~1.5%.

tarkah commented 3 years ago

Here is the new option:

-i, --update-interval <update-interval>    Interval to update data from API (seconds) [default: 1]
tarkah commented 3 years ago

Note that the app still re-draws every 1 second to keep everything displaying properly. Certain actions, like opening the options pane or switching to a new stock tab, will cause API requests to fire off and get some initial data (which then updates based on the interval). If I put the re-draw on the same interval and we chose 5 seconds, none of that initial data will get drawn for 5 seconds. A draw does occur after the user input, but the API request takes longer than that so then its stuck waiting for the update interval.

daniel-j-h commented 3 years ago

Amazing :rocket: