Skip to content

Commit 7ebe79d

Browse files
authored
Merge pull request #16 from dxFeed/EN-1570-no-cython
En 1570 no cython event handlers
2 parents 56a1a72 + de56db5 commit 7ebe79d

26 files changed

+1887
-615
lines changed

README.md

+32-27
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ The library is build as a thin wrapper over [dxFeed C-API library](https://githu
1414
We use [Cython](https://cython.org/) in this project as it combines flexibility, reliability and
1515
usability in writing C extensions.
1616

17-
This package already contains basic C-API functions related to creating connections, subscriptions etc.
18-
Moreover default listeners (functions responsible for event processing) are ready to use. The user is also able to
19-
write his own custom listener in Cython
17+
The design of the dxfeed package allows users to write any logic related to events in python as well as
18+
extending lower level Cython functionality. Moreover, one may start working with the API using the default
19+
values like function arguments or a default event handler.
20+
21+
Documentation: [dxfeed.readthedocs.io](https://dxfeed.readthedocs.io/en/latest/)
22+
23+
Package distribution: [pypi.org/project/dxfeed](https://pypi.org/project/dxfeed/)
2024

2125
## Installation
2226

23-
**Requirements:** python >3.6, pandas
27+
**Requirements:** python >= 3.6, pandas
2428

2529
```python
2630
pip3 install pandas
@@ -39,7 +43,7 @@ Following steps should be performed:
3943
* Import
4044
* Create Endpoint
4145
* Create Subscription
42-
* Attach listener
46+
* Attach event handler
4347
* Add tickers
4448
* Finally close subscription and connection
4549

@@ -76,39 +80,48 @@ You should specify event type. For timed subscription (conflated stream) you sho
7680

7781

7882
```python
79-
trade_sub = endpoint.create_subscription('Trade', data_len=-1)
83+
trade_sub = endpoint.create_subscription('Trade')
8084
```
8185

82-
**Attach default listener** - function that process incoming events
86+
**Attach default or custom event handler** - class that process incoming events. For details about custom
87+
event handler look into `CustomHandlerExample.ipynb` jupyter notebook in `exapmles` folder of this repository.
8388

8489

8590
```python
86-
trade_sub = trade_sub.attach_listener()
91+
trade_handler = dx.DefaultHandler()
92+
trade_sub = trade_sub.set_event_handler(trade_handler)
8793
```
8894

89-
**Add tikers** you want to recieve events for
95+
**Add tikers** you want to receive events for
9096

9197

9298
```python
93-
trade_sub = trade_sub.add_symbols(['C', 'TSLA'])
99+
trade_sub = trade_sub.add_symbols(['C', 'AAPL'])
94100
```
95101

96-
For timed subscription you may provide either datetime object or string. String might be incomlete, in this case you will get warning with how your provided date parsed automatically
102+
For timed subscription you may provide either datetime object or string. String might be incomplete, in
103+
this case you will get warning with how your provided date parsed automatically.
97104

98105

99106
```python
100107
tns_sub = endpoint.create_subscription('TimeAndSale', date_time=datetime.now()) \
101-
.attach_listener() \
102108
.add_symbols(['AMZN'])
103109
```
104110

105111

106112
```python
107113
candle_sub = endpoint.create_subscription('Candle', date_time='2020-04-16 13:05')
108-
candle_sub = candle_sub.attach_listener()
109114
candle_sub = candle_sub.add_symbols(['AAPL', 'MSFT'])
110115
```
111116

117+
We didn't provide subscriptions with event handlers. In such a case DefaultHandler is initiated automatically.
118+
One may get it with `get_event_handler` method.
119+
120+
```python
121+
tns_handler = tns_sub.get_event_handler()
122+
candle_handler = candle_sub.get_event_handler()
123+
```
124+
112125
#### Subscription instance properties
113126

114127

@@ -123,11 +136,10 @@ Subscription symbols: ['AAPL', 'MSFT']
123136
```
124137

125138
### Access data
126-
Data is stored as deque. Its length is configured with data_len parameter and by default is 100000. When you call method below you extracts all data recieved to the moment and clears the buffer in class.
127-
139+
In DefaultHandler the data is stored as deque. Its length may be configured, by default 100000 events.
128140

129141
```python
130-
candle_sub.get_data()
142+
candle_handler.get_list()
131143
```
132144

133145
### Close connection
@@ -144,17 +156,10 @@ Connection status: Not connected
144156

145157
### Transform data to pandas DataFrame
146158

159+
DefaultHandler has `get_dataframe` method, which allows you to get pandas.DataFrame object with events as rows.
147160

148161
```python
149-
trade_df = trade_sub.get_dataframe()
150-
```
151-
152-
153-
```python
154-
tns_df = tns_sub.get_dataframe()
155-
```
156-
157-
158-
```python
159-
candle_df = candle_sub.get_dataframe()
162+
trade_df = trade_handler.get_dataframe()
163+
tns_df = tns_handler.get_dataframe()
164+
candle_df = candle_handler.get_dataframe()
160165
```

build.py

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
extensions = [Extension('dxfeed.core.utils.helpers', ['dxfeed/core/utils/helpers.' + ext],
3939
include_dirs=include_dirs),
40+
Extension('dxfeed.core.utils.handler', ['dxfeed/core/utils/handler.' + ext],
41+
include_dirs=include_dirs),
4042
Extension('dxfeed.core.listeners.listener', ['dxfeed/core/listeners/listener.' + ext],
4143
include_dirs=include_dirs),
4244
Extension('dxfeed.core.DXFeedPy', ['dxfeed/core/DXFeedPy.' + ext_pp], libraries=libs,

docs/_static/custom.css

+12
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@
1313
.attribute {
1414
margin-left: 30px;
1515
}
16+
17+
table {
18+
display: block;
19+
overflow-x: scroll;
20+
}
21+
22+
.highlight-text > .highlight > pre {
23+
background-color: wheat;
24+
display: block;
25+
max-height: 300px;
26+
overflow-y: auto;
27+
}

docs/api.rst

+10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
.. _api:
22

3+
.. meta::
4+
:description lang=en: dxfeed package docstrings.
5+
36
API Reference
47
=============
58

9+
This page contains only automatically generated documentation to functions, classes, methods, etc.
10+
611
API
712
------------------------
813

@@ -14,6 +19,10 @@ API
1419
:members:
1520
:inherited-members:
1621

22+
.. automodule:: dxfeed.core.utils.handler
23+
:members:
24+
:inherited-members:
25+
1726
Low-level API
1827
-----------------------
1928

@@ -30,3 +39,4 @@ Utils functions
3039

3140
.. automodule:: dxfeed.core.utils.data_class
3241
:members:
42+
:inherited-members:

0 commit comments

Comments
 (0)