You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Article.md
+52-2Lines changed: 52 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -254,9 +254,22 @@ async with httpx.AsyncClient(
254
254
print(f"Unexpected error: {e}")
255
255
```
256
256
257
-
### Where is asyncio.run(main())?
257
+
####Where is asyncio.run(main())?
258
258
259
-
You might wonder why the main code does not call `asyncio.run(main())`. The reason is that Jupyter natively supports top-level `await`, so no `asyncio.run()` wrapper is needed.
259
+
You might wonder why the main code does not call `asyncio.run(main())` statement. The reason is that Jupyter natively supports top-level `await`, so no `asyncio.run()` wrapper is needed.
260
+
261
+
If your target platform is non-Jupyter environment, you need call asynchronous code and method in `asyncio.run(main())` statement as follows:
262
+
263
+
```python
264
+
import asyncio
265
+
266
+
asyncdefman()
267
+
await something()
268
+
269
+
if__name__=="__main__":
270
+
271
+
asyncio.run(main())
272
+
```
260
273
261
274
### Comparing to Synchronous Code
262
275
@@ -292,6 +305,43 @@ with httpx.Client(
292
305
...
293
306
```
294
307
308
+
The `post_authentication_async` method sends a single HTTP POST request to the RDP authentication endpoint asynchronously and retrieves the access token for use in subsequent data requests. Nothing too exciting here — just a straightforward async HTTP call.
309
+
310
+
Once authentication succeeds, the function parses the RDP Auth service response and stores the following token fields:
311
+
312
+
-**access_token**: The token used to invoke REST data API calls as described above. The application must keep this credential for further RDP APIs requests.
313
+
-**refresh_token**: Refresh token to be used for obtaining an updated access token before expiration. The application must keep this credential for access token renewal.
314
+
-**expires_in**: Access token validity time in seconds.
315
+
316
+
### Requesting RDP APIs Data
317
+
318
+
That brings us to requesting the RDP APIs data. All subsequent REST API calls must pass the Access Token via the `Authorization` HTTP request header as shown below.
319
+
- Header:
320
+
* Authorization = ```Bearer <RDP Access Token>```
321
+
322
+
Please notice *the space* between the ```Bearer``` and ```RDP Access Token``` values.
323
+
324
+
The application then builds a request message — either as a JSON body or URL query parameters depending on the service — and sends it to the appropriate API Endpoint. You can find each endpoint's HTTP operations and parameters on Data Platform's [API Playground page](https://apidocs.refinitiv.com/Apps/ApiDocs), an interactive documentation site available to anyone with a valid Data Platform account.
325
+
326
+
### Getting Multiple Historical Pricing Data Asynchronously
327
+
328
+
Moving on to the main benefit of the asynchronous execution model: performing multiple I/O tasks in parallel, like sending multiple HTTP requests at once. I am demonstrating this with the `/data/historical-pricing/v1/views/interday-summaries/{universe}` endpoint, which retrieves time series pricing Interday summaries data (i.e. bar data) for a single RIC code via the following HTTP structure.
329
+
330
+
```http
331
+
GET /data/historical-pricing/v1/views/interday-summaries/{RIC Code}?{params} HTTP/1.1
332
+
Authorization: Bearer {access token}
333
+
Host: api.refinitiv.com
334
+
```
335
+
336
+
I am using 30 RICs from various exchanges — S&P 500, Nasdaq Composite, and others — as sample RIC codes.
Please note that my Data Platform account *does not have permission* to retrieve [ASML](https://www.asml.com/en) (`ASML.AS`) data. I included this RIC intentionally to demonstrate how to handle an error with asynchronous execution model.
0 commit comments