Skip to content

Commit aeea64e

Browse files
author
Wasin Waeosri
committed
Change log:
1. Finalize interday notebook
1 parent 8fd4984 commit aeea64e

File tree

1 file changed

+123
-20
lines changed

1 file changed

+123
-20
lines changed

notebook/trkd_timeseries_interday.ipynb

Lines changed: 123 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
"source": [
77
"# TRKD HTTP JSON with Python Example: Time-Series Interday\n",
88
"\n",
9-
"## Overview\n",
10-
"The [Thomson Reuters Knowledge Direct (TRKD) API](https://developers.thomsonreuters.com/thomson-reuters-knowledge-direct-trkd) integrates into your website, trading platform, company intranet/extranet, advisory portal and mobile applications to provide up-to-date financial market data, news and analytics and powerful investment tools.\n",
11-
"\n",
12-
"TRKD offers a wide range of Refinitiv' information and services delivered in a request-response scenario via web services using today's industry standard protocols (SOAP/XML and REST/JSON). Connectivity can be via HTTP and HTTPS, over the Internet or Delivery Direct. All data are snapshot (non-streaming) data.\n",
13-
"\n",
14-
"This is an example project that shows how to implement TRKD HTTP JSON client with Python programming lanugage in Jupyter Notebook.\n",
159
"\n",
1610
"## Time-Series Interday Interday Introduction\n",
1711
"TRKD Time-Series Interday requests let you retrieve historical time series prices on an instrument, summarized in daily, weekly, monthly, quarterly, or annual periods. For each period, details such as the opening price, closing price, highest and lowest prices, Closing Yield value of the period, and Bid price and Ask price of the stock are retrieved. Historical interday time series prices for instruments are available back to 1981.\n",
@@ -71,9 +65,17 @@
7165
" return result"
7266
]
7367
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"### Authentication Process\n",
73+
"For you reference, please see more detail regarding TRKD Authentication service in [TRKD Tutorial: Authentication](https://developers.refinitiv.com/thomson-reuters-knowledge-direct-trkd/thomson-reuters-knowledge-direct-api-trkd-api/learning?content=68078&type=learning_material_item) page."
74+
]
75+
},
7476
{
7577
"cell_type": "code",
76-
"execution_count": 19,
78+
"execution_count": 37,
7779
"metadata": {},
7880
"outputs": [],
7981
"source": [
@@ -86,7 +88,7 @@
8688
},
8789
{
8890
"cell_type": "code",
89-
"execution_count": 5,
91+
"execution_count": 38,
9092
"metadata": {},
9193
"outputs": [],
9294
"source": [
@@ -97,7 +99,7 @@
9799
},
98100
{
99101
"cell_type": "code",
100-
"execution_count": 6,
102+
"execution_count": 39,
101103
"metadata": {},
102104
"outputs": [],
103105
"source": [
@@ -120,7 +122,7 @@
120122
},
121123
{
122124
"cell_type": "code",
123-
"execution_count": 7,
125+
"execution_count": 40,
124126
"metadata": {},
125127
"outputs": [],
126128
"source": [
@@ -131,7 +133,7 @@
131133
},
132134
{
133135
"cell_type": "code",
134-
"execution_count": 8,
136+
"execution_count": 41,
135137
"metadata": {},
136138
"outputs": [
137139
{
@@ -158,8 +160,8 @@
158160
"cell_type": "markdown",
159161
"metadata": {},
160162
"source": [
161-
"#### TRKD Time-Series: Interday Service detail\n",
162-
"##### TRKD Service Token URL and Header\n",
163+
"### TRKD Time-Series: Interday Service detail\n",
164+
"#### TRKD Service Token URL and Header\n",
163165
"\n",
164166
"TRKD Time Series provides Interday data for developers via GetInterdayTimeSeries_4 operation. The endponint of GetInterdayTimeSeries_4 operaion is the following URL:\n",
165167
"[http://api.trkd.thomsonreuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_4](http://api.trkd.thomsonreuters.com/api/TimeSeries/TimeSeries.svc/REST/TimeSeries_1/GetInterdayTimeSeries_4)\n",
@@ -170,7 +172,7 @@
170172
" - X-Trkd-Auth-Token = service Token\n",
171173
"- Method: Post\n",
172174
"\n",
173-
"##### HTTP Request Post Body\n",
175+
"#### HTTP Request Post Body\n",
174176
"The GetInterdayTimeSeries_4 operation requires the following properties in a request message's body\n",
175177
"- Symbol: A RIC of the instrument for the interday prices you want to retrieve\n",
176178
"- StartTime: Start date and time criteria of the search. The format of the Start time should be:\n",
@@ -185,14 +187,57 @@
185187
"```\n",
186188
"{\n",
187189
" \"GetInterdayTimeSeries_Request_4\":{\n",
188-
" \"Symbol\": <application id>,\n",
189-
" \"StartTime\": <username>,\n",
190-
" \"EndTime\": <password>,\n",
190+
" \"Symbol\": <RIC name>,\n",
191+
" \"StartTime\": <yyyy-mm-ddThh:mm:ss>,\n",
192+
" \"EndTime\": <yyyy-mm-ddThh:mm:ss>,\n",
191193
" \"Interval\": \"DAILY\"\n",
192194
" }\n",
193195
"}\n",
194196
"```\n",
195-
"*Note*: Please pay attention that maximum \"EndDate\" interval is >=2038. If you specify a greater \"EndDate\" interval, you receive a blank response."
197+
"*Note*: Please pay attention that maximum \"EndDate\" interval is >=2038. If you specify a greater \"EndDate\" interval, you receive a blank response.\n",
198+
"\n",
199+
"#### HTTP Response\n",
200+
"\n",
201+
"The application receives a HTTP response message from TRKD from GetInterdayTimeSeries_4 operatio operation as the following attributes.\n",
202+
"- HTTP Status: 200 OK\n",
203+
"- Header: Content-type = application/json\n",
204+
"\n",
205+
"The example of a response message for MSFT.O symbol and Daily interval is shown below\n",
206+
"```\n",
207+
"{\n",
208+
" \"GetInterdayTimeSeries_Response_4\":{\n",
209+
" \"MetaFields\":{\n",
210+
" \"CCY\":\"USD\",\n",
211+
" \"NAME\":\"MICROSOFT CP\",\n",
212+
" \"QOS\":\"RT\",\n",
213+
" \"TZ\":\"NYC\",\n",
214+
" \"TZOFFSET\":-300\n",
215+
" },\n",
216+
" \"Row\":[\n",
217+
" {\n",
218+
" \"ASK\":109.19,\n",
219+
" \"BID\":109.17,\n",
220+
" \"CLOSE\":109.19,\n",
221+
" \"HIGH\":109.24,\n",
222+
" \"LOW\":105.0,\n",
223+
" \"OPEN\":105.82,\n",
224+
" \"TIMESTAMP\":\"2018-12-06T00:00:00+00:00\",\n",
225+
" \"VOLUME\":49107431.0\n",
226+
" },\n",
227+
" {\n",
228+
" \"ASK\":104.8,\n",
229+
" \"BID\":104.78,\n",
230+
" \"CLOSE\":104.82,\n",
231+
" \"HIGH\":109.45,\n",
232+
" \"LOW\":104.3,\n",
233+
" \"OPEN\":108.38,\n",
234+
" \"TIMESTAMP\":\"2018-12-07T00:00:00+00:00\",\n",
235+
" \"VOLUME\":45044937.0\n",
236+
" }\n",
237+
" ]\n",
238+
" }\n",
239+
"}\n",
240+
"```\n"
196241
]
197242
},
198243
{
@@ -2065,6 +2110,14 @@
20652110
" print(json.dumps(interdayResult.json(), sort_keys=True, indent=2, separators=(',', ':')))"
20662111
]
20672112
},
2113+
{
2114+
"cell_type": "markdown",
2115+
"metadata": {},
2116+
"source": [
2117+
"### Creating a Pandas Data Frame\n",
2118+
"Next, we convert incoming JSON object to a [Pandas](https://pandas.pydata.org/) Data Frame object. We get a list of columns names from the JSON object and construct a data frame named *df*."
2119+
]
2120+
},
20682121
{
20692122
"cell_type": "code",
20702123
"execution_count": 13,
@@ -2098,11 +2151,54 @@
20982151
},
20992152
{
21002153
"cell_type": "code",
2101-
"execution_count": 16,
2154+
"execution_count": 20,
21022155
"metadata": {},
21032156
"outputs": [],
21042157
"source": [
2105-
"df = pd.DataFrame(interday_data, columns = columns)"
2158+
"df = pd.DataFrame(interday_data, columns = columns)\n"
2159+
]
2160+
},
2161+
{
2162+
"cell_type": "code",
2163+
"execution_count": 31,
2164+
"metadata": {},
2165+
"outputs": [
2166+
{
2167+
"name": "stdout",
2168+
"output_type": "stream",
2169+
"text": [
2170+
"Data Frame row numbers = 254\n",
2171+
"Example 10 rows are:\n",
2172+
" OPEN HIGH LOW CLOSE TIMESTAMP\n",
2173+
"0 144.82 145.020 143.77 144.43 2015-09-22T00:00:00+00:00\n",
2174+
"1 144.21 144.538 142.75 143.66 2015-09-23T00:00:00+00:00\n",
2175+
"2 142.60 145.070 141.95 144.41 2015-09-24T00:00:00+00:00\n",
2176+
"3 145.55 146.270 144.56 145.42 2015-09-25T00:00:00+00:00\n",
2177+
"4 144.33 145.360 142.47 142.52 2015-09-28T00:00:00+00:00\n",
2178+
"5 141.99 142.645 141.18 142.47 2015-09-29T00:00:00+00:00\n",
2179+
"6 143.69 145.710 143.66 144.97 2015-09-30T00:00:00+00:00\n",
2180+
"7 145.31 145.550 141.60 143.59 2015-10-01T00:00:00+00:00\n",
2181+
"8 141.20 144.590 140.56 144.58 2015-10-02T00:00:00+00:00\n",
2182+
"9 146.02 149.890 145.92 149.04 2015-10-05T00:00:00+00:00\n"
2183+
]
2184+
}
2185+
],
2186+
"source": [
2187+
"# check Data Frame object output\n",
2188+
"if not df.empty:\n",
2189+
" print('Data Frame row numbers = %d' % len(df.index))\n",
2190+
" print('Example 10 rows are:')\n",
2191+
" print(df.head(10))"
2192+
]
2193+
},
2194+
{
2195+
"cell_type": "markdown",
2196+
"metadata": {},
2197+
"source": [
2198+
"## Ploting Graph\n",
2199+
"We use Python [Matplotlib](https://matplotlib.org/) library to plot a graph from Pandas Data Frame object. The target graph compares 'Open', 'High', 'Low' and 'Close' data between time ('Timestamp' field). \n",
2200+
"\n",
2201+
"We firstly re-arrange and re-format the Timestamp value in the Data Frame object to use it in X-axis for the graph."
21062202
]
21072203
},
21082204
{
@@ -2115,6 +2211,13 @@
21152211
"df.sort_values('TIMESTAMP',ascending=True,inplace=True)"
21162212
]
21172213
},
2214+
{
2215+
"cell_type": "markdown",
2216+
"metadata": {},
2217+
"source": [
2218+
"Then we plotting a graph, the X-axis is 'Timestamp' values and the Y-axis is fields values."
2219+
]
2220+
},
21182221
{
21192222
"cell_type": "code",
21202223
"execution_count": 18,

0 commit comments

Comments
 (0)