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)
| 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'] |
no outgoing calls
no test coverage detected