Basically, you are asking if it is faster to make 10 API calls and save the information or make 1 single API call and search for your information in the global result.
For many reasons, the fewer API calls, the better:
- API calls are generally slower than calculation / search in code from computer or server.
- The more calls you make, the more likely you will hit rate limits of the API.
Just to verify this :
public static function testSpeed(): void {
$binance = new ccxt\binance();
$binance->load_markets();
$symbols = $binance->symbols;
$symbolsToFetch = [];
for( $i = 0; $i < 10; $i++ ){
$symbolsToFetch[] = $symbols[ $i ];
}
$tickers = [];
$start = microtime( true );
foreach( $symbolsToFetch as $symbolToFetch ){
$tickers[] = $binance->fetch_ticker( $symbolToFetch );
}
echo '10x fetch_ticker, fetched ' . count( $tickers ) . ' tickers in : ' . round( microtime( true ) - $start, 3 ) . ' seconds';
echo "\n";
$start = microtime( true );
$tickers = $binance->fetch_tickers( $symbolsToFetch );
echo '1x fetch_tickers, fetched ' . count( $tickers ) . ' tickers in : ' . round( microtime( true ) - $start, 3 ) . ' seconds';
}
And the result (with no surprise):
10x fetch_ticker, fetched 10 tickers in : 6.353 seconds
1x fetch_tickers, fetched 10 tickers in : 3.167 seconds