Best practice to watch huge number of tickers
See original GitHub issueIs it good practice, in Node.js case, to create one infinite while
cycle for each symbol like this:
// !!! Can contain 700+ symbols.
const symbols = [
'1INCH-PERP',
'ADA-PERP'
];
// Solution 1
const exchange = new ccxt.ftx();
function start() {
for (let symbol of symbols) {
watchTicker(symbol);
}
}
// One infinite while for each symbol will be created, so 700+ 'while' cycles.
// All processed in async way.
async function watchTicker(symbol) {
while (true) {
try {
let ticker = await exchange.watchTicker(symbol);
// do magic with ticker ...
}
catch (e) {
console.log(e);
}
}
}
start();
Currently, we process all tickets in one while cycle, but considering switching to above solution. Current solution:
// Solution 2
const exchange = new ccxt.ftx();
function subscribeAll() {
for (let symbol of symbols) {
subscribe(symbol);
}
}
async function subscribe(symbol) {
try {
await exchange.watchTicker(symbol);
}
catch (e) {
console.log(e);
}
}
// Contains only one infinite while for all subscribed symbols,
// but each ticker is processed synchronously one by one.
async function process() {
while(true) {
for (let symbol in exchange.tickers) {
let ticker = exchange.tickers[symbol];
// do magic with ticker ...
}
await delay(1000);
}
}
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
subscribeAll();
process();
- OS: Debian (Docker)
- Programming Language version: JavaScript (Node.js)
- CCXT version: pro 0.9.35
Issue Analytics
- State:
- Created 2 years ago
- Comments:18 (14 by maintainers)
Top Results From Across the Web
Building An Effective Watchlist - Investopedia
It's a good idea to devote at least one screen entirely to tickers, with each entry displaying just two or three fields, including...
Read more >How to Always Find the Top Stocks to Watch - YouTube
It's a great way to prep for the upcoming week every Sunday.) We're not looking to be first, and you shouldn't either.
Read more >Opinion: Here's the best way to spot stock-market winners ...
Mark Mahaney says look for high-quality companies whose stock price has fallen 20% or more.
Read more >Learn How to Create a Stock Watch List with MarketSmith
A good way to gauge those things is to look at the stocks rated highest by Relative Strength or Earnings Per Share (EPS)...
Read more >7 Top Stocks to Watch in November 2022 - StocksToTrade
Building your watchlist every day is the best way to get the highest-potential trades in your sights. I also send out a NO-COST...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yeah, we can think of how to better merge the two methods with user-controllable options.
Some of the bots I’ve worked with were much closer to real-time, dealing with milliseconds and sub-ms time precision. However, if +/- 500ms is not critical for this specific use-case, then fetchTicker/fetchTickers should be ok. Mind, however, that some exchanges (especially, Binance, the biggest one) will impose higher rate limits on fetchTickers, so you won’t be able to call it with Binance once or twice a second – they will ban you temporarily to cool off.