Skip to content

Commit 3215d30

Browse files
committed
Merge pull request #12 in EN/dxfeed-python-api from feature/EN-1215-pythonapi-add-documentation to master
* commit '8f2ac0894792bc41fdeb7b356d2082dbdc07b8c0': (43 commits) [EN-1215] package dropped from name [EN-1215] data_class docs added [EN-1215] current section in bold [EN-1215] anchors in custom listener added [EN-1215] sidebar modification [EN-1215] cython link edited [EN-1215] function highlighting [EN-1215] bottom padding added [EN-1215] external links support via custom js [EN-1215] blank line in the end [EN-1215] better way to hide sphinx in footer theme [EN-1215] alabaster clean theme [EN-1215] alabaster theme [EN-1215] footer invisible theme [EN-1215] base classic theme [EN-1215] corlab theme [EN-1215] minor edit [EN-1215] home page more text [EN-1215] redundant configs removed [EN-1215] cython highlighting ...
2 parents 8e2ee19 + 8f2ac08 commit 3215d30

17 files changed

+656
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
build/*
66
*.pyd
77

8+
_build*
89

910
*__pycache__
1011

build.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from setuptools import setup, Extension, find_packages
2+
from setuptools.dist import Distribution
23
from pathlib import Path
34
import platform
45

@@ -44,4 +45,18 @@ def build(setup_kwargs):
4445
'dxfeed/dxfeed-c-api/src'],
4546
})
4647

47-
48+
def build_extensions():
49+
"""
50+
Function for building extensions inplace for docs and tests
51+
:return:
52+
"""
53+
build_params = {}
54+
build(build_params)
55+
dist = Distribution(attrs=build_params)
56+
build_clib_cmd = dist.get_command_obj('build_clib')
57+
build_clib_cmd.ensure_finalized()
58+
build_clib_cmd.run()
59+
build_ext_cmd = dist.get_command_obj('build_ext')
60+
build_ext_cmd.ensure_finalized()
61+
build_ext_cmd.inplace = 1
62+
build_ext_cmd.run()

docs/Makefile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build
7+
SOURCEDIR = .
8+
BUILDDIR = _build
9+
10+
# Put it first so that "make" without argument is like "make help".
11+
help:
12+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13+
14+
.PHONY: help Makefile
15+
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@cd ..; python -c 'from build import *; build_extensions()'
21+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
22+
python zipper.py
23+
@cd ..; find dxfeed/core/* -type f \( -name '*.c*' -or -name '*.pyd' \) -delete
24+
25+
.PHONY: clean
26+
clean:
27+
rm -rf $(BUILDDIR)/*

docs/_static/custom.css

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.footer {
2+
display: none;
3+
}
4+
.body {
5+
margin-bottom: 50px;
6+
}
7+
.section > dl > dt {
8+
background-color: #DDE7F7;
9+
}
10+
.current.reference.internal {
11+
font-weight: bold;
12+
}

docs/_static/custom.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
$(document).ready(function () {
2+
$('a[href^="http://"], a[href^="https://"]').not('a[class*=internal]').attr('target', '_blank');
3+
});

docs/api.rst

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. _api:
2+
3+
API Reference
4+
=============
5+
6+
Core functions
7+
--------------
8+
9+
.. automodule:: dxfeed.core.DXFeedPy
10+
:members:
11+
:inherited-members:
12+
13+
Utils functions
14+
---------------
15+
16+
.. automodule:: dxfeed.core.utils.helpers
17+
:members:
18+
:inherited-members:
19+
20+
.. automodule:: dxfeed.core.utils.data_class
21+
:members:

docs/basic_usage.rst

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
.. _basic_usage:
2+
3+
Basic Usage
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 as dx
14+
15+
Next, the connection to dxfeed server should be established:
16+
17+
.. code-block:: python
18+
19+
con = dx.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 = dx.dxf_create_subscription(con, 'Trade')
27+
sub2 = dx.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+
Each subscription should be provided with tickers to get events for:
35+
36+
.. code-block:: python
37+
38+
dx.dxf_add_symbols(sub1, ['AAPL', 'MSFT'])
39+
dx.dxf_add_symbols(sub2, ['AAPL', 'C'])
40+
41+
Special function called listener should be attached to the subscription to start receiving
42+
events. There are default listeners already implemented in dxpyfeed, but you
43+
can write your own with cython: :ref:`custom_listener`. To attach
44+
default listener just call `dxf_attach_listener`
45+
46+
.. code-block:: python
47+
48+
dx.dxf_attach_listener(sub1)
49+
dx.dxf_attach_listener(sub2)
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+
dx.dxf_detach_listener(sub1)
72+
dx.dxf_detach_listener(sub2)
73+
74+
When you are done with subscription you'd better close it:
75+
76+
.. code-block:: python
77+
78+
dx.dxf_close_subscription(sub1)
79+
dx.dxf_close_subscription(sub2)
80+
81+
Same with connection:
82+
83+
.. code-block:: python
84+
85+
dx.dxf_close_connection(con)

docs/conf.py

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import sys
4+
import toml
5+
from pathlib import Path
6+
from pygments.lexers.python import CythonLexer
7+
from sphinx.highlighting import lexers
8+
9+
pyproject = toml.load(Path(__file__).parents[1].joinpath('pyproject.toml'))
10+
# -- Path setup --------------------------------------------------------------
11+
12+
sys.path.append(Path(__file__).parents[1])
13+
# -- Project information -----------------------------------------------------
14+
15+
project = pyproject['tool']['poetry']['name']
16+
copyright = '2019, dxfeed'
17+
author = 'dxfeed'
18+
19+
# The short X.Y version
20+
version = pyproject['tool']['poetry']['version']
21+
# The full version, including alpha/beta/rc tags
22+
release = pyproject['tool']['poetry']['version']
23+
24+
25+
# -- General configuration ---------------------------------------------------
26+
# Add any Sphinx extension module names here, as strings.
27+
extensions = [
28+
'sphinx.ext.autodoc',
29+
'sphinx.ext.coverage',
30+
'sphinx.ext.napoleon', # numpy style docstrings
31+
'sphinx.ext.intersphinx'
32+
]
33+
34+
# Add any paths that contain templates here, relative to this directory.
35+
templates_path = ['_templates']
36+
37+
# The suffix(es) of source filenames.
38+
source_suffix = '.rst'
39+
40+
# The master toctree document.
41+
master_doc = 'index'
42+
43+
# The language for content autogenerated by Sphinx.
44+
language = 'en'
45+
46+
# List of patterns, relative to source directory, that match files and
47+
# directories to ignore when looking for source files.
48+
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
49+
50+
# -- Options for HTML output -------------------------------------------------
51+
html_static_path = ['_static']
52+
html_css_files = ['custom.css']
53+
html_js_files = ['custom.js']
54+
55+
# The theme to use for HTML and HTML Help pages.
56+
html_theme = 'alabaster'
57+
html_theme_options = {
58+
'body_max_width': '80%',
59+
'show_powered_by': False,
60+
'sidebar_collapse': True
61+
}
62+
63+
# -- Options for HTMLHelp output ---------------------------------------------
64+
65+
# Output file base name for HTML help builder.
66+
htmlhelp_basename = 'dxfeeddoc'
67+
68+
# remove view source link
69+
html_show_sourcelink = False
70+
71+
# highlight cython
72+
lexers['cython'] = CythonLexer()

0 commit comments

Comments
 (0)