33Basic Usage
44===========
55
6-
76There are three levels in the dxfeed package. The lowest is the C API
87library, the highest is Python wrapper classes. Cython level in the
98middle aims to connect these two. Here we are going to look into Python
@@ -15,20 +14,21 @@ Python level, in its turn, mainly consists of three class types:
15142. Subscription
16153. EventHandler
1716
18- The **Endpoint ** is responsible for connection management and creating dependent classes, for
19- example Subscription. One Endpoint may have several different
20- Subscriptions, but each Subscription is related to one Endpoint.
17+ The **Endpoint ** is responsible for connection management and creating
18+ dependent classes, for example Subscription. One Endpoint may have
19+ several different Subscriptions, but each Subscription is related to one
20+ Endpoint.
2121
22- **Subscription ** class sets the type of subscription (stream or timed), the type of
23- events (e.g. Trade, Candle), etc.
22+ **Subscription ** class sets the type of subscription (stream or timed),
23+ the type of events (e.g. Trade, Candle), etc.
2424
2525After you specified the data you want to receive, you have to specify
26- how to process upcoming events. This is where the **EventHandler ** class and
27- its children come into play. Every time an event arrives Cython event
28- listener will call ``self.update(event) `` method. You have to inherit
29- from the EventHandler class and redefine the update method. Or you may
30- use DefaultHandler which stores upcoming data in deque of the length
31- 100k.
26+ how to process upcoming events. This is where the **EventHandler ** class
27+ and its children come into play. Every time an event arrives Cython
28+ event listener will call ``self.update(event) `` method. You have to
29+ inherit from the EventHandler class and redefine the update method. Or
30+ you may use DefaultHandler which stores upcoming data in deque of the
31+ length 100k.
3232
3333Import package
3434~~~~~~~~~~~~~~
@@ -56,7 +56,7 @@ e.g. connection address or status
5656 print(f'Connection status: {endpoint.connection_status}')
5757
5858
59- .. code-block :: text
59+ .. code :: text
6060
6161 Connected address: demo.dxfeed.com:7300
6262 Connection status: Connected and authorized
@@ -88,7 +88,10 @@ default one
8888
8989 For timed subscription you should provide either datetime object or
9090string. String might be incomlete, in this case you will get warning
91- with how your provided date parsed automatically
91+ with how your provided date parsed automatically. For Candle event type
92+ along with base symbol, you should specify an aggregation period. You
93+ can also set price type. More details:
94+ https://kb.dxfeed.com/display/DS/REST+API#RESTAPI-Candlesymbols.
9295
9396.. code :: python3
9497
@@ -98,10 +101,10 @@ with how your provided date parsed automatically
98101 .. code :: python3
99102
100103 candle_sub = endpoint.create_subscription('Candle', date_time='2020-04-16 13:05')
101- candle_sub = candle_sub.add_symbols(['AAPL', 'MSFT'])
104+ candle_sub = candle_sub.add_symbols(['AAPL{=d} ', 'MSFT{=d} '])
102105
103106
104- .. code-block :: text
107+ .. code :: text
105108
106109 c:\job\python-api\dxfeed\wrappers\class_utils.py:38: UserWarning: Datetime argument does not exactly match %Y-%m-%d %H:%M:%S.%f format, date was parsed automatically as 2020-04-16 13:05:00.000000
107110 warn(warn_message, UserWarning)
@@ -125,11 +128,11 @@ Subscription instance properties
125128 print(f'Candle subscription symbols: {candle_sub.symbols}')
126129
127130
128- .. code-block :: text
131+ .. code :: text
129132
130133 TimeAndSale subscription event type: TimeAndSale
131134 Candle subscription event type: Candle
132- Candle subscription symbols: ['AAPL', 'MSFT']
135+ Candle subscription symbols: ['AAPL{=d} ', 'MSFT{=d} ']
133136
134137
135138 Access data from DefaultHandler instance
@@ -144,12 +147,29 @@ handler that stores no data.
144147 print(f'Candle columns: {candle_handler.columns}')
145148
146149
147- .. code-block :: text
150+ .. code :: text
148151
149152 Trade columns: ['Symbol', 'Price', 'ExchangeCode', 'Size', 'Tick', 'Change', 'DayVolume', 'Time', 'IsETH']
150153 Candle columns: ['Symbol', 'Index', 'Time', 'Sequence', 'Count', 'Open', 'High', 'Low', 'Close', 'Volume', 'VWap', 'BidVolume', 'AskVolume', 'OpenInterest', 'ImpVolatility']
151154
152155
156+ .. code :: python3
157+
158+ candle_handler.get_list()[-5:]
159+
160+
161+
162+
163+ .. code :: text
164+
165+ [['MSFT{=d}', 6816463568083353600, 1587081600000, 0, 189986.0, 179.5, 180.0, 175.87, 178.6, 52765625.0, 177.90622, 24188832.0, 22094602.0, 0, 0.4384],
166+ ['MSFT{=d}', 6816294775868620800, 1587042300000, 0, 189986.0, 179.5, 180.0, 175.87, 178.6, 52765625.0, 177.90622, 24188832.0, 22094602.0, 0, 0.4384],
167+ ['AAPL{=d}', 6839841934068940800, 1592524800000, 0, 827.0, 354.05, 355.55, 353.35, 354.72, 188804.0, 354.45941, 78039.0, 110765.0, 0, 0.3691],
168+ ['AAPL{=d}', 6839841934068940800, 1592524800000, 0, 831.0, 354.05, 355.55, 353.35, 354.9, 189555.0, 354.4611, 78039.0, 111516.0, 0, 0.3691],
169+ ['AAPL{=d}', 6839841934068940800, 1592524800000, 0, 832.0, 354.05, 355.55, 353.35, 354.72, 190055.0, 354.46178, 78539.0, 111516.0, 0, 0.3691]]
170+
171+
172+
153173 .. code :: python3
154174
155175 candle_handler.get_dataframe().head(3)
@@ -197,79 +217,64 @@ handler that stores no data.
197217 <tbody >
198218 <tr >
199219 <th >0</th >
200- <td >MSFT </td >
201- <td >6838531241273198328 </td >
202- <td >2020-06-15 11:13:50.566 </td >
203- <td >1784 </td >
204- <td >1 .0</td >
205- <td >184.17 </td >
206- <td >184.17 </td >
207- <td >184.17 </td >
208- <td >184.17 </td >
209- <td >635 .0</td >
210- <td >184.17 </td >
211- <td >635 .0</td >
212- <td >NaN </td >
220+ <td >AAPL{=d} </td >
221+ <td >6839841934068940800 </td >
222+ <td >2020-06-19 </td >
223+ <td >0 </td >
224+ <td >827 .0</td >
225+ <td >354.05 </td >
226+ <td >355.55 </td >
227+ <td >353.35 </td >
228+ <td >354.72 </td >
229+ <td >188804 .0</td >
230+ <td >354.45941 </td >
231+ <td >78039 .0</td >
232+ <td >110765.0 </td >
213233 <td >0</td >
214- <td >NaN </td >
234+ <td >0.3691 </td >
215235 </tr >
216236 <tr >
217237 <th >1</th >
218- <td >MSFT</td >
219- <td >6838531241273198326</td >
220- <td >2020-06-15 11:13:50.566</td >
221- <td >1782</td >
222- <td >1.0</td >
223- <td >184.17</td >
224- <td >184.17</td >
225- <td >184.17</td >
226- <td >184.17</td >
227- <td >100.0</td >
228- <td >184.17</td >
229- <td >100.0</td >
230- <td >NaN</td >
238+ <td >AAPL{=d}</td >
239+ <td >6839470848894566400</td >
240+ <td >2020-06-18</td >
231241 <td >0</td >
232- <td >NaN</td >
242+ <td >96172.0</td >
243+ <td >351.41</td >
244+ <td >353.45</td >
245+ <td >349.22</td >
246+ <td >351.73</td >
247+ <td >24205096.0</td >
248+ <td >351.56873</td >
249+ <td >8565421.0</td >
250+ <td >10394906.0</td >
251+ <td >0</td >
252+ <td >0.3673</td >
233253 </tr >
234254 <tr >
235255 <th >2</th >
236- <td >MSFT </td >
237- <td >6838531058896471782 </td >
238- <td >2020-06-15 11:13:08.092 </td >
239- <td >1766 </td >
240- <td >1 .0</td >
241- <td >184.17 </td >
242- <td >184.17 </td >
243- <td >184.17 </td >
244- <td >184.17 </td >
245- <td >100 .0</td >
246- <td >184.17 </td >
247- <td >100 .0</td >
248- <td >NaN </td >
256+ <td >AAPL{=d} </td >
257+ <td >6839099763720192000 </td >
258+ <td >2020-06-17 </td >
259+ <td >0 </td >
260+ <td >110438 .0</td >
261+ <td >355.15 </td >
262+ <td >355.40 </td >
263+ <td >351.09 </td >
264+ <td >351.59 </td >
265+ <td >28601626 .0</td >
266+ <td >353.70998 </td >
267+ <td >10686232 .0</td >
268+ <td >12141490.0 </td >
249269 <td >0</td >
250- <td >NaN </td >
270+ <td >0.3713 </td >
251271 </tr >
252272 </tbody >
253273 </table >
254274 </div >
255275
256276
257277
258- .. code :: python3
259-
260- candle_handler.get_list()[:3]
261-
262-
263-
264-
265- .. code-block :: text
266-
267- [['MSFT', 6838531241273198328, 1592219630566, 1784, 1.0, 184.17, 184.17, 184.17, 184.17, 635.0, 184.17, 635.0, nan, 0, nan],
268- ['MSFT', 6838531241273198326, 1592219630566, 1782, 1.0, 184.17, 184.17, 184.17, 184.17, 100.0, 184.17, 100.0, nan, 0, nan],
269- ['MSFT', 6838531058896471782, 1592219588092, 1766, 1.0, 184.17, 184.17, 184.17, 184.17, 100.0, 184.17, 100.0, nan, 0, nan]]
270-
271-
272-
273278Close subscription
274279~~~~~~~~~~~~~~~~~~
275280
@@ -288,7 +293,7 @@ Close connection
288293 print(f'Connection status: {endpoint.connection_status}')
289294
290295
291- .. code-block :: text
296+ .. code :: text
292297
293298 Connection status: Not connected
294299
0 commit comments