@@ -16,6 +16,7 @@ def createRequest(service, options):
1616 # NOTE: this function uses `Request.__setitem__` to format a `Request`. See
1717 # the other `createRequest` functions in this `requestresponse` directory
1818 # for examples of alternative interfaces for formatting a `Request`.
19+ # An alternative using `request.fromJson` is shown in the comments below.
1920 request = service .createRequest ("HistoricalDataRequest" )
2021
2122 request [SECURITIES ] = options .securities
@@ -28,6 +29,22 @@ def createRequest(service, options):
2829 request [MAX_DATA_POINTS ] = 100
2930 request [RETURN_EIDS ] = True
3031
32+ # Alternative: Using `Request.fromJson` to format the request
33+ # import json
34+ # REQUEST_JSON = f"""
35+ # {{
36+ # "securities": {json.dumps(options.securities)},
37+ # "fields": {json.dumps(options.fields)},
38+ # "periodicityAdjustment": "ACTUAL",
39+ # "periodicitySelection": "MONTHLY",
40+ # "startDate": "20200101",
41+ # "endDate": "20201231",
42+ # "maxDataPoints": 100,
43+ # "returnEids": true
44+ # }}
45+ # """
46+ # request.fromJson(REQUEST_JSON)
47+
3148 return request
3249
3350
@@ -36,6 +53,10 @@ def processResponseEvent(event):
3653 print (f"Received response to request { msg .getRequestId ()} " )
3754 print (msg )
3855
56+ # Alternative: Using `Message.toJson` to convert the message to JSON
57+ # jsonStr = msg.toJson()
58+ # print(jsonStr)
59+
3960
4061__copyright__ = """
4162Copyright 2021, Bloomberg Finance L.P.
0 commit comments