-1

Is fetch_ticker faster than fetch_tickers? I want to download information of under 10 kinds of coins. To use fetch_ticker function 10 times is faster than just using fetch_tickers?

I'm going to use fetch_ticker() like this:

binance.fetch_ticker('TRX/USDT')
binance.fetch_ticker('ETH/USDT')
binance.fetch_ticker('ETC/USDT')
binance.fetch_ticker('BTC/USDT')

or fetch_tickers

binance.fetch_tickers()

I don't need whole information of coins in exchanges

JustAG33K
  • 1,403
  • 3
  • 13
  • 28

1 Answers1

1

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
midnight
  • 25
  • 5