Package: dxfeed
dxfeed packageThis package provides access todxFeedstreaming data.
The library is build as a thin wrapper overdxFeed C-API library.
We useCythonin this project as it combines flexibility, reliability and
usability in writing C extensions.The design of the dxfeed package allows users to write any logic related to events in python as well as
extending lower level Cython functionality. Moreover, one may start working with the API using the default
values like function arguments or a default event handler.Documentation:dxfeed.readthedocs.ioPackage distribution:pypi.org/project/dxfeedInstallationRequirements:python >= 3.6Install package via PyPI:pip3installdxfeedInstallation from sourcesTo install dxfeed from source you need Poetry. It provides a custom installer.
This is the recommended way of installing poetry according todocumentationFor macOS / Linux / Windows (with bash):curl-sSLhttps://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py|pythonIn the project root directory (same one where you found this file after
cloning the git repo), execute:poetryinstallBy default package is installed indevelopment mode. To rebuild
C extensions, after editing .pyx files:poetryruntaskbuild_inplace# build c extensionsBasic usageFollowing steps should be performed:ImportCreate EndpointCreate SubscriptionAttach event handlerAdd tickersFinally close subscription and connectionImport packageimportdxfeedasdxfromdatetimeimportdatetime# for timed subscriptionConfigure and create connection with Endpoint classCreate instance of Endpoint class which will connect provided address.endpoint=dx.Endpoint('demo.dxfeed.com:7300')Endpoint instance contains information about the connection, e.g. connection address or statusprint(f'Connected address:{endpoint.address}')print(f'Connection status:{endpoint.connection_status}')Connected address: demo.dxfeed.com:7300
Connection status: Connected and authorizedConfigure and create subscriptionYou should specify event type. For timed subscription (conflated stream) you should also provide time to start subscription from.trade_sub=endpoint.create_subscription('Trade')Attach default or custom event handler- class that process incoming events. For details about custom
event handler look intoCustomHandlerExample.ipynbjupyter notebook inexapmlesfolder of this repository.trade_handler=dx.DefaultHandler()trade_sub=trade_sub.set_event_handler(trade_handler)Add tikersyou want to receive events fortrade_sub=trade_sub.add_symbols(['C','AAPL'])For timed subscription you may provide either datetime object or string. String might be incomplete, in
this case you will get warning with how your provided date parsed automatically.tns_sub=endpoint.create_subscription('TimeAndSale',date_time=datetime.now())\.add_symbols(['AMZN'])candle_sub=endpoint.create_subscription('Candle',date_time='2020-04-16 13:05')candle_sub=candle_sub.add_symbols(['AAPL','MSFT'])We didn't provide subscriptions with event handlers. In such a case DefaultHandler is initiated automatically.
One may get it withget_event_handlermethod.tns_handler=tns_sub.get_event_handler()candle_handler=candle_sub.get_event_handler()Subscription instance propertiesprint(f'Subscription event type:{tns_sub.event_type}')print(f'Subscription symbols:{candle_sub.symbols}')Subscription event type: TimeAndSale
Subscription symbols: ['AAPL', 'MSFT']Access dataIn DefaultHandler the data is stored as deque. Its length may be configured, by default 100000 events.candle_handler.get_list()Close connectionendpoint.close_connection()print(f'Connection status:{endpoint.connection_status}')Connection status: Not connectedTransform data to pandas DataFrameDefaultHandler hasget_dataframemethod, which allows you to get pandas.DataFrame object with events as rows.trade_df=trade_handler.get_dataframe()tns_df=tns_handler.get_dataframe()candle_df=candle_handler.get_dataframe()