-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11ab617
commit f4b6508
Showing
13 changed files
with
379 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. _api-reference-itch: | ||
ITCH API Reference | ||
================== | ||
|
||
Itch | ||
---- | ||
.. automodule:: nasdaq_protocols.itch | ||
|
||
|
||
Itch Session | ||
^^^^^^^^^^^^ | ||
.. autoclass:: nasdaq_protocols.itch.session.ItchSessionId | ||
:show-inheritance: True | ||
|
||
.. autoclass:: nasdaq_protocols.itch.session.ClientSession | ||
:show-inheritance: True | ||
:undoc-members: ['send_heartbeat'] | ||
|
||
|
||
Itch Messages | ||
^^^^^^^^^^^^^ | ||
.. automodule:: nasdaq_protocols.itch.core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.. _api-reference-ouch: | ||
OUCH API Reference | ||
================== | ||
|
||
Ouch | ||
---- | ||
.. automodule:: nasdaq_protocols.ouch | ||
|
||
|
||
Ouch Session | ||
^^^^^^^^^^^^ | ||
.. autoclass:: nasdaq_protocols.ouch.session.OuchSessionId | ||
:show-inheritance: True | ||
|
||
.. autoclass:: nasdaq_protocols.ouch.session.ClientSession | ||
:show-inheritance: True | ||
:undoc-members: ['send_heartbeat'] | ||
|
||
|
||
Ouch Messages | ||
^^^^^^^^^^^^^ | ||
.. automodule:: nasdaq_protocols.ouch.core |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
SOUP api reference | ||
.. _api-reference-soup: | ||
SOUP API Reference | ||
================== | ||
|
||
Soup | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
.. _install-guide: | ||
|
||
Installation | ||
============ | ||
|
||
To use nasdaq-protocols, install it using pip: | ||
|
||
.. code-block:: console | ||
(.venv) $ pip install nasdaq-protocols | ||
$ pip install nasdaq-protocols |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,14 @@ | ||
.. _user-guide: | ||
|
||
User Guide | ||
========== | ||
|
||
SOUP | ||
____ | ||
|
||
Connect to Soup session | ||
----------------------- | ||
Example of connecting to a Soup session and receiving messages. | ||
|
||
.. code-block:: python | ||
import asyncio | ||
from nasdaq_protocols import Soup | ||
stopped = asyncio.Event() | ||
async def on_msg(msg): | ||
print(msg) | ||
async def on_close(): | ||
stopped.set() | ||
print('closed') | ||
async def main(): | ||
session = await soup.connect_async( | ||
('host', port), 'user', 'password', | ||
sequence=1, on_msg_coro=on_msg, on_close_coro=on_close | ||
) | ||
await stopped.wait() | ||
if __name__ == '__main__': | ||
asyncio.run(main()) | ||
.. toctree:: | ||
:maxdepth: 1 | ||
:caption: User Guides: | ||
|
||
*A simple soup tail program* | ||
install | ||
user_guide_soup | ||
user_guide_ouch | ||
user_guide_itch | ||
user_guide_create_new_project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
.. _user-guide-create-new-project: | ||
|
||
Create New Project Guide | ||
======================== | ||
|
||
This guide will walk you through creating a new python package that contains the message definitions | ||
of the applications you want to use with the nasdaq-protocols. | ||
|
||
.. note:: | ||
|
||
This guide assumes you have already installed the nasdaq-protocols package. If you have not, please | ||
refer to the :ref:`installation guide <install-guide>`. | ||
|
||
|
||
Steps | ||
----- | ||
|
||
1. Install `tox` if you have not already done so. | ||
|
||
.. code-block:: bash | ||
bash$ pip install tox | ||
Refer to the `tox documentation <https://tox.wiki/en/latest/installation.html>`_ for detailed information. | ||
|
||
2. Create a new python package structure using the `nasdaq-protocols-create-new-project` command line tool. | ||
|
||
.. code-block:: bash | ||
bash$ nasdaq-protocols-create-new-project --name <project-name> \ | ||
--application app:proto [--target-dir <target-dir>] | ||
Replace `<project-name>` with the name of your project and `<target-dir>` with the directory where you want to | ||
create the project. | ||
|
||
For example, to create a project named `nasdaq-protocols-messages` in the current directory, with 2 applications `ouch_oe` | ||
and `itch_feed`, you would run the following command: | ||
|
||
.. code-block:: bash | ||
bash$ nasdaq-protocols-create-new-project --name nasdaq-protocols-messages \ | ||
--application ouch_oe:ouch \ | ||
--application itch_feed:itch | ||
3. The `nasdaq-protocols-create-new-project` command will create a new python package with the following structure: | ||
|
||
For the above example, the following directory structure will be created. | ||
|
||
.. code-block:: bash | ||
nasdaq-protocols-messages/ | ||
├── src/ | ||
| ├── nasdaq_protocols_messages/ | ||
| │ ├── __init__.py | ||
| │ ├── ouch_oe/ | ||
| │ │ └── ouch_oe.xml | ||
| │ └── itch_feed/ | ||
| │ └── itch_feed.xml | ||
├── pyproject.toml | ||
└── tox.ini | ||
.. note:: | ||
- **ouch_oe.xml** is the file where you define all the messages for the `ouch_oe` application. | ||
- **itch_feed.xml** is the file where you define all the messages for the `itch_feed` application. | ||
|
||
The XML file contains the format and guidelines on how to define the messages. | ||
|
||
4. Edit the XML files to define the messages for the applications you want to use with the nasdaq-protocols. | ||
|
||
5. Build the package | ||
|
||
.. code-block:: bash | ||
bash$ cd target-dir/nasdaq-protocols-messages | ||
bash$ tox r | ||
6. The package will be built and stored in the `dist` directory. This can be uploaded to your PyPI repository or | ||
installed locally. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
.. _user-guide-itch: | ||
|
||
ITCH User Guide | ||
=============== | ||
|
||
The `nasdaq_protocols.itch` module provides an API to interact with ITCH servers. | ||
Refer :ref:`api-reference-itch`. for more information on the API. | ||
|
||
This package **only** provides the core implementation of the ITCH protocols, like message serialization | ||
deserialization, session handling, etc. It **does not** define any actual ITCH messages. The actual ITCH | ||
messages has to be defined by the user of this package. The first step is to create a new python package | ||
which contains the messages definitions for all the protocols that the user wants to use. | ||
|
||
This package provides a command line utility `nasdaq-protocols-create-new-project` to create a new python package | ||
and all the necessary files. | ||
|
||
Follow the steps in :ref:`user-guide-create-new-project` to create a new python package for application specific | ||
messages. | ||
|
||
|
||
.. note:: | ||
|
||
This rest of the guide assumes that you have built a new python project using the steps mentioned in | ||
:ref:`user-guide-create-new-project`. | ||
|
||
|
||
The generated project will contain a file `itch_<app_name>.py` which will contain the following | ||
- ITCH message definitions | ||
- ITCH Client Session for this application | ||
|
||
Using the generated code, you can connect to a ITCH server and start receiving messages. | ||
|
||
|
||
The `nasdaq_protocols.itch` module provides an API to interact with ITCH servers. | ||
Refer :ref:`api-reference-itch`. for more information on the API. | ||
|
||
|
||
Connecting to a ITCH Server | ||
--------------------------- | ||
Use the example below to implement a program that will tail itch messages from the server. | ||
|
||
.. code-block:: python | ||
#!/usr/bin/env python | ||
import asyncio | ||
# from the generated package we import the application we want to use | ||
from nasdaq_protocols_messages import itch_feed | ||
stopped = asyncio.Event() | ||
async def itch_output(itch_message): | ||
""" | ||
This function will be called whenever a new ITCH message is received | ||
""" | ||
print('') | ||
print(f'received: {itch_message}') | ||
print('') | ||
async def itch_close(): | ||
""" | ||
This function will be called when the ITCH session is closed | ||
""" | ||
stopped.set() | ||
print('') | ||
print('itch session closed, Bye Bye') | ||
print('') | ||
async def main(): | ||
# Step1: connect | ||
port = 1234 # give the proper itch server port | ||
itch_session = await itch_feed.connect_async( | ||
('hostname', port), | ||
'itch username', # itch username, max 6 characters | ||
'pwdchange', # itch password, max 10 characters | ||
'', # session id | ||
on_msg_coro=itch_output, # function to call when a new message is received | ||
on_close_coro=itch_close, # function to call when the session is closed | ||
sequence=1 # 0 to listen from HEAD, 1 to listen from start, n to listen from n | ||
) | ||
# Wait forever until the server closes the connection | ||
await asyncio.sleep(5) | ||
print("Closing the itch session...") | ||
await stopped.wait() | ||
if __name__ == '__main__': | ||
asyncio.run(main()) | ||
*A simple itch tail program* | ||
|
||
Slightly modified version where we do not use dispatchers instead explicitely call `receive_message()` method. | ||
|
||
.. code-block:: python | ||
#!/usr/bin/env python | ||
import asyncio | ||
from nasdaq_protocols_messages import itch_feed | ||
async def main(): | ||
# Step1: connect | ||
port = 1234 # give the proper itch server port | ||
itch_session = await itch_feed.connect_async( | ||
('hostname', port), | ||
'itch username', # itch username, max 6 characters | ||
'pwdchange', # itch password, max 10 characters | ||
'', # session id | ||
sequence=1 # 0 to listen from HEAD, 1 to listen from start, n to listen from n | ||
) | ||
# receive the first message from the server. | ||
itch_message = await itch_session.receive_message() | ||
print(itch_message) | ||
print("Closing the itch session...") | ||
await itch_session.close() | ||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.. _user-guide-ouch: | ||
|
||
OUCH User Guide | ||
=============== | ||
|
||
The `nasdaq_protocols.ouch` module provides an API to interact with OUCH servers. | ||
Refer :ref:`api-reference-ouch`. for more information on the API. |
Oops, something went wrong.