11import json
22import os
33import time
4- from typing import Any , Sequence
54
65import httpx
76from dotenv import load_dotenv
@@ -45,7 +44,6 @@ def post_authentication(machine_id, password, app_key, url, client):
4544
4645 # Send authentication request to the OAuth token endpoint.
4746 # `data=payload` sends a form body required by this endpoint.
48- # `verify=False` skips SSL verification (for local/dev only). This is not recommended for production use. I use it to avoid LSEG beloved ZScaler.
4947 response = client .post (url , data = payload )
5048 response .raise_for_status () # Raise for 4xx/5xx API failures.
5149 return response .json ()
@@ -59,7 +57,6 @@ def get_chain(ric, token, url, client):
5957 "universe" : ric
6058 }
6159 # Request chain data from the pricing chains endpoint.
62- # `verify=False` skips SSL verification (for local/dev only). This is not recommended for production use. I use it to avoid LSEG beloved ZScaler.
6360 response = client .get (url , params = parameters , headers = headers )
6461 response .raise_for_status ()
6562 return response .json ()
@@ -75,7 +72,7 @@ def post_historical_event(rics, token, url, client):
7572 }
7673
7774 # `json=payload` serializes and sends JSON in the request body.
78- # `verify=False` skips SSL verification (for local/dev only). This is not recommended for production use. I use it to avoid LSEG beloved ZScaler.
75+
7976 response = client .post (url , json = payload , headers = headers )
8077 response .raise_for_status ()
8178 return response .json ()
@@ -91,7 +88,7 @@ def post_auth_refresh(app_key, refresh_token, url, client):
9188 headers = {
9289 "Content-Type" : "application/x-www-form-urlencoded"
9390 }
94- # `verify=False` skips SSL verification (for local/dev only). This is not recommended for production use. I use it to avoid LSEG beloved ZScaler.
91+
9592 response = client .post (url , data = payload , headers = headers )
9693 response .raise_for_status ()
9794 return response .json ()
@@ -105,7 +102,6 @@ def post_auth_revoke(token, app_key, url, client):
105102
106103 payload = f"token={ token } "
107104 auth = httpx .BasicAuth (username = app_key , password = "" )
108- # `verify=False` skips SSL verification (for local/dev only). This is not recommended for production use. I use it to avoid LSEG beloved ZScaler.
109105 response = client .post (url , data = payload , headers = headers , auth = auth )
110106 response .raise_for_status ()
111107
@@ -144,26 +140,26 @@ def main() -> None:
144140 print (f"Chain data for { ric } :" , json .dumps (chain_data , indent = 2 ))
145141
146142 # Example multi-RIC request for historical events endpoint.
147- rics = ["LSEG.L" , "VOD.L" , "BP.L" ]
148- print (f"Posting historical event data... for RICs: { rics } " )
149- historical_event_data = post_historical_event (rics , access_token , HISTORICAL_EVENT_URL , client )
150- print ("Historical event data retrieved successfully!" )
151- print (f"Historical event data for { rics } :" , json .dumps (historical_event_data ))
152-
153- refresh_token = token_data .get ("refresh_token" )
154- if refresh_token :
155- time .sleep (5 ) # Sleep for 5 seconds before refreshing token (for demo purposes)
156- print ("Refreshing access token..." )
157- refreshed_token_data = post_auth_refresh (app_key , refresh_token , AUTH_TOKEN_URL , client )
158- print ("Token refreshed successfully!" )
159- print ("New Access Token:" , json .dumps (refreshed_token_data ["access_token" ], indent = 2 ))
160- else :
161- print ("No refresh token available. Cannot refresh access token." )
162-
163- time .sleep (5 ) # Sleep for 5 seconds before revoking token (for demo purposes)
164- print ("Revoking access token..." )
165- post_auth_revoke (access_token , app_key , AUTH_REVOKE_URL , client )
166- print ("Access token revoked successfully." )
143+ # rics = ["LSEG.L", "VOD.L", "BP.L"]
144+ # print(f"Posting historical event data... for RICs: {rics}")
145+ # historical_event_data = post_historical_event(rics, access_token, HISTORICAL_EVENT_URL, client)
146+ # print("Historical event data retrieved successfully!")
147+ # print(f"Historical event data for {rics}:", json.dumps(historical_event_data))
148+
149+ # refresh_token = token_data.get("refresh_token")
150+ # if refresh_token:
151+ # time.sleep(5) # Sleep for 5 seconds before refreshing token (for demo purposes)
152+ # print("Refreshing access token...")
153+ # refreshed_token_data = post_auth_refresh(app_key, refresh_token, AUTH_TOKEN_URL, client)
154+ # print("Token refreshed successfully!")
155+ # print("New Access Token:", json.dumps(refreshed_token_data["access_token"], indent=2))
156+ # else:
157+ # print("No refresh token available. Cannot refresh access token.")
158+
159+ # time.sleep(5) # Sleep for 5 seconds before revoking token (for demo purposes)
160+ # print("Revoking access token...")
161+ # post_auth_revoke(access_token, app_key, AUTH_REVOKE_URL, client)
162+ # print("Access token revoked successfully.")
167163
168164 else :
169165 print ("Failed to receive access token. Exiting..." )
@@ -181,4 +177,7 @@ def main() -> None:
181177
182178
183179if __name__ == "__main__" :
184- main ()
180+ start = time .perf_counter ()
181+ main ()
182+ elapsed = time .perf_counter () - start
183+ print (f"{ __file__ } executed in { elapsed :0.2f} seconds." )
0 commit comments