Skip to content

Commit d970096

Browse files
committed
added article detail
1 parent 50089ad commit d970096

1 file changed

Lines changed: 52 additions & 2 deletions

File tree

Article.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,9 +254,22 @@ async with httpx.AsyncClient(
254254
print(f"Unexpected error: {e}")
255255
```
256256

257-
### Where is asyncio.run(main())?
257+
#### Where is asyncio.run(main())?
258258

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+
async def man()
267+
await something()
268+
269+
if __name__ == "__main__":
270+
271+
asyncio.run(main())
272+
```
260273

261274
### Comparing to Synchronous Code
262275

@@ -292,6 +305,43 @@ with httpx.Client(
292305
...
293306
```
294307

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.
337+
338+
```python
339+
HISTORICAL_RICS = ["NVDA.O","AAPL.O","MSFT.O","AMZN.O","GOOG.O","AVGO.O","META.O","ORCL.N","IBM.N","PLTR.O","NFLX.O","TSLA.O","CRM.N","AMD.O","INTC.O","ARM.O","ASML.AS","CSCO.O","WMT.O","LLY.N","JPM.N","XOM.N","V.N","JNJ.N","MU.O","MA.N","COST.O","CVX.N","BAC.N","CAT.N"]
340+
```
341+
342+
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.
343+
344+
[TBD]
295345

296346

297347

0 commit comments

Comments
 (0)