danpaquin / coinbasepro-python

The unofficial Python client for the Coinbase Pro API
MIT License
1.82k stars 740 forks source link

Coinbase rate limits impact calls for arbitrarily large number of pages #388

Closed angelaponte closed 4 years ago

angelaponte commented 4 years ago

I ran into what looks like a Coinbase API rate limit issue when calling AuthenticatedClient.get_account_history, read the source, and didn't see how API rate limits were being handled in PublicClient._send_paginated_message .

Here's the Coinbase Pro API rate limits page: https://docs.pro.coinbase.com/#rate-limits

It says: "PUBLIC ENDPOINTS We throttle public endpoints by IP: 3 requests per second, up to 6 requests per second in bursts.

PRIVATE ENDPOINTS We throttle private endpoints by profile ID: 5 requests per second, up to 10 requests per second in bursts."

This patch adds a time.sleep of .2 seconds to paginated calls in the AuthenticatedClient (to meet the 5 request per second limit) and sets a default time.sleep of .34 seconds for all other paginated calls (e.g. the PublicClient).

The changes are simple and easy to read, but I have not tested them yet. The changes necessarily make the paginated calls slower.