Skip to content

Commit d1d6341

Browse files
committed
[EN-1328] core example added
1 parent 8fec2a1 commit d1d6341

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

docs/core_usage.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
.. _core_usage:
2+
3+
Core functionality
4+
==================
5+
6+
All the functions in C API have similar ones in Python with the same name. Not all arguments are
7+
supported by now, this work is in progress.
8+
9+
First of all you have to import the package:
10+
11+
.. code-block:: python
12+
13+
import dxfeed.core.DXFeedPy as dxc
14+
15+
Next, the connection to dxfeed server should be established:
16+
17+
.. code-block:: python
18+
19+
con = dxc.dxf_create_connection(address='demo.dxfeed.com:7300')
20+
21+
To get events of certain types the subscription with this type should be
22+
create. One connection may have several subscriptions.
23+
24+
.. code-block:: python
25+
26+
sub1 = dxc.dxf_create_subscription(con, 'Trade')
27+
sub2 = dxc.dxf_create_subscription(con, 'Quote')
28+
29+
.. note::
30+
31+
'Trade', 'Quote', 'Summary', 'Profile', 'Order', 'TimeAndSale', 'Candle', 'TradeETH', 'SpreadOrder',
32+
'Greeks', 'TheoPrice', 'Underlying', 'Series', 'Configuration' event types are supported.
33+
34+
Special function called listener should be attached to the subscription to start receiving
35+
events. There are default listeners already implemented in dxpyfeed, but you
36+
can write your own with cython: :ref:`custom_listener`. To attach
37+
default listener just call `dxf_attach_listener`
38+
39+
.. code-block:: python
40+
41+
dxc.dxf_attach_listener(sub1)
42+
dxc.dxf_attach_listener(sub2)
43+
44+
Each subscription should be provided with tickers to get events for:
45+
46+
.. code-block:: python
47+
48+
dxc.dxf_add_symbols(sub1, ['AAPL', 'MSFT'])
49+
dxc.dxf_add_symbols(sub2, ['AAPL', 'C'])
50+
51+
The data can be extracted with `get_data()` method. It is stored as dict with list of columns and list
52+
of events. Note that `get_data` extracts the data and then clean the field. To look at data call this property:
53+
54+
.. code-block:: python
55+
56+
sub1.get_data()
57+
sub2.get_data()
58+
59+
The more convenient way to look at data is to convert it into pandas DataFrame.
60+
`to_dataframe` method of subscription class is responsible for that:
61+
62+
.. code-block:: python
63+
64+
sub1.to_dataframe()
65+
sub2.to_dataframe()
66+
67+
To stop receiving events just detach the listener:
68+
69+
.. code-block:: python
70+
71+
dxc.dxf_detach_listener(sub1)
72+
dxc.dxf_detach_listener(sub2)
73+
74+
When you are done with subscription you'd better close it:
75+
76+
.. code-block:: python
77+
78+
dxc.dxf_close_subscription(sub1)
79+
dxc.dxf_close_subscription(sub2)
80+
81+
Same with connection:
82+
83+
.. code-block:: python
84+
85+
dxc.dxf_close_connection(con)

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Table of contents:
3030
self
3131
installation.rst
3232
basic_usage.rst
33+
core_usage.rst
3334
custom_listener.rst
3435
api.rst
3536
devs.rst

0 commit comments

Comments
 (0)