MCPcopy
hub / github.com/danpaquin/coinbasepro-python / _send_paginated_message

Method _send_paginated_message

cbpro/public_client.py:272–311  ·  view source on GitHub ↗

Send API message that results in a paginated response. The paginated responses are abstracted away by making API requests on demand as the response is iterated over. Paginated API messages support 3 additional parameters: `before`, `after`, and `limit`. `before` an

(self, endpoint, params=None)

Source from the content-addressed store, hash-verified

270 return r.json()
271
272 def _send_paginated_message(self, endpoint, params=None):
273 """ Send API message that results in a paginated response.
274
275 The paginated responses are abstracted away by making API requests on
276 demand as the response is iterated over.
277
278 Paginated API messages support 3 additional parameters: `before`,
279 `after`, and `limit`. `before` and `after` are mutually exclusive. To
280 use them, supply an index value for that endpoint (the field used for
281 indexing varies by endpoint - get_fills() uses 'trade_id', for example).
282 `before`: Only get data that occurs more recently than index
283 `after`: Only get data that occurs further in the past than index
284 `limit`: Set amount of data per HTTP response. Default (and
285 maximum) of 100.
286
287 Args:
288 endpoint (str): Endpoint (to be added to base URL)
289 params (Optional[dict]): HTTP request parameters
290
291 Yields:
292 dict: API response objects
293
294 """
295 if params is None:
296 params = dict()
297 url = self.url + endpoint
298 while True:
299 r = self.session.get(url, params=params, auth=self.auth, timeout=30)
300 results = r.json()
301 for result in results:
302 yield result
303 # If there are no more pages, we're done. Otherwise update `after`
304 # param to get next page.
305 # If this request included `before` don't get any more pages - the
306 # cbpro API doesn't support multiple pages in that case.
307 if not r.headers.get('cb-after') or \
308 params.get('before') is not None:
309 break
310 else:
311 params['after'] = r.headers['cb-after']

Callers 6

get_product_tradesMethod · 0.95
get_account_historyMethod · 0.80
get_account_holdsMethod · 0.80
get_ordersMethod · 0.80
get_fillsMethod · 0.80
get_fundingsMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected