API Reference¶
API¶
-
class
dxfeed.wrappers.endpoint.Endpoint(connection_address: str = 'demo.dxfeed.com:7300', connect: bool = True)¶ Class for connection management. After successful creation Instance will be connected to server with provided credentials
-
connection_address¶ One of possible connection addresses:
- the single address: host:port or just host
- address with credentials: host:port[username=xxx,password=yyy]
- multiple addresses: (host1:port1)(host2)(host3:port3[username=xxx,password=yyy])
Default: demo.dxfeed.com:7300
Type: str
-
connect¶ When True connect method is called during instance creation. Default - True
Type: bool
-
close_connection()¶ Method to close connections and all related subscriptions.
-
connect(reconnect: bool = True) Creates connection. If connection status differs from “Not connected” and reconnect is False, does nothing
Parameters: reconnect (bool) – When True closes previous connection. Default - True Returns: self Return type: Endpoint
-
create_subscription(event_type: str, data_len: int = 100000, date_time: Union[str, datetime.datetime] = None)¶ Method creates certain event type subscription and returns Subscription class
Parameters: - event_type (str) – One of possible event types: ‘Trade’, ‘Quote’, ‘Summary’, ‘Profile’, ‘Order’, ‘TimeAndSale’, ‘Candle’, ‘TradeETH’, ‘SpreadOrder’, ‘Greeks’, ‘TheoPrice’, ‘Underlying’, ‘Series’, ‘Configuration’ or ‘’
- data_len (int) – The amount of events kept in Subscription class. To have no limits set this value to -1
- date_time (str or datetime.datetime) – If present timed subscription will be created (conflated stream). For sting date format is following: %Y-%m-%d %H:%M:%S.%f. If None - stream subscription will be created. Default - None.
Note
Some event types (e.g. Candle) support only timed subscription.
Returns: subscription – Subscription class related to current connection Return type: Subscription
-
-
class
dxfeed.wrappers.subscription.Subscription(connection, event_type: str, date_time: Union[str, datetime.datetime], data_len: int = 100000)¶ Class for subscription management. Recommended to be created only via create_subscription method in Endpoint class. Also stores incoming events
-
connection¶ Core class written in cython, that handle connection related details on the low level
Type: dxfeed.core.DXFeedPy.ConnectionClass
-
event_type¶ One of possible event types: ‘Trade’, ‘Quote’, ‘Summary’, ‘Profile’, ‘Order’, ‘TimeAndSale’, ‘Candle’, ‘TradeETH’, ‘SpreadOrder’, ‘Greeks’, ‘TheoPrice’, ‘Underlying’, ‘Series’, ‘Configuration’ or ‘’
Type: str
-
data_len¶ The amount of events kept in Subscription class. By default event is received as list and each event is stored in deque of fixed size. To have no limits for the deque set this value to -1. Default 100000.
Type: int
-
date_time¶ If present timed subscription will be created (conflated stream). For sting date format is following: %Y-%m-%d %H:%M:%S.%f. If None - stream subscription will be created (non-conflated). Default - None.
Type: str or datetime.datetime
Note
Some event types (e.g. Candle) support only timed subscription.
-
add_symbols(symbols: Union[str, Iterable[str]])¶ Method to add symbol. Supports addition of one symbol as a string as well as list of symbols :param symbols: Symbols to add. Previously added and remained symbols are ignored on C-API level :type symbols: str, Iterable
Returns: self Return type: Subscription
-
attach_listener()¶ Method to attach default listener.
Returns: self Return type: Subscription
-
close_subscription()¶ Method to close subscription. All received data will remain in the object.
-
detach_listener()¶ Removes listener so new events won’t be received
Returns: self Return type: Subscription
-
get_dataframe(keep: bool = True)¶ Method converts data to the Pandas DataFrame
Parameters: keep (bool) – When True copies data to dataframe, otherwise pops. Default True Returns: df – Dataframe each row - one event. Return type: pandas.DataFrame
-
get_list()¶ Method to get data. When called internal field is cleared
Returns: data – List of events. Each event contains list with data related to subscription type. Return type: list
-
remove_symbols(symbols: Union[str, Iterable[str], None] = None)¶ Method removes symbols from subscription. If no symbols provided removes all symbols
Parameters: symbols (str, Iterable) – One ticker or list of tickers to remove from subscription Returns: self Return type: Subscription
-
Low-level API¶
-
class
dxfeed.core.DXFeedPy.ConnectionClass¶ Data structure that contains connection
-
get_sub_refs()¶ Method to get list of references to all subscriptions related to current connection
Returns: List of weakref objects. Empty list if no refs Return type: list
-
-
class
dxfeed.core.DXFeedPy.SubscriptionClass¶ Data structure that contains subscription and related fields
-
get_data()¶ Method returns list with data, specified in event listener and returned data will be removed from object buffer
Returns: List with data Return type: list
-
to_dataframe()¶ Method converts data to the Pandas DataFrame
Parameters: keep (bool) – When True copies data to dataframe, otherwise pops. Default True Returns: df Return type: pandas DataFrame
-
-
dxfeed.core.DXFeedPy.dxf_add_symbols()¶ Adds symbols to subscription
Parameters: - sc (SubscriptionClass) – SubscriptionClass with information about subscription
- symbols (list) – List of symbols to add
-
dxfeed.core.DXFeedPy.dxf_attach_custom_listener()¶ Attaches custom listener
Parameters: - sc (SubscriptionClass) – SubscriptionClass with information about subscription
- fw (FuncWrapper) – c function wrapped in FuncWrapper class with Cython
- columns (list) – Columns for internal data of SubscriptionClass
- data (dict) – Dict with new internal data structure of SubscriptionClass
-
dxfeed.core.DXFeedPy.dxf_attach_listener()¶ Function attaches default listener according to subscription type
Parameters: sc (SubscriptionClass) – SubscriptionClass with information about subscription
-
dxfeed.core.DXFeedPy.dxf_clear_symbols()¶ Removes all symbols from the subscription
Parameters: sc (SubscriptionClass) – SubscriptionClass with information about subscription
-
dxfeed.core.DXFeedPy.dxf_close_connection()¶ Closes connection
Parameters: cc (ConnectionClass) – Variable with connection information
-
dxfeed.core.DXFeedPy.dxf_close_subscription()¶ Closes subscription
Parameters: sc (SubscriptionClass) – SubscriptionClass with information about subscription
-
dxfeed.core.DXFeedPy.dxf_create_connection()¶ Function creates connection to dxfeed given url address
Parameters: address (str) – One of possible connection addresses:
- the single address: host:port or just host
- address with credentials: host:port[username=xxx,password=yyy]
- multiple addresses: (host1:port1)(host2)(host3:port3[username=xxx,password=yyy])
- the data from file: /path/to/file on nix and drive:pathtofile on Windows
Default: demo.dxfeed.com:7300
Returns: cc – Cython ConnectionClass with information about connection Return type: ConnectionClass
-
dxfeed.core.DXFeedPy.dxf_create_connection_auth_bearer()¶ Function creates connection to dxfeed given url address and token
Parameters: - address (str) – dxfeed url address
- token (str) – dxfeed token
Returns: cc – Cython ConnectionClass with information about connection
Return type:
-
dxfeed.core.DXFeedPy.dxf_create_subscription()¶ Function creates subscription and writes all relevant information to SubscriptionClass
Parameters: - cc (ConnectionClass) – Variable with connection information
- event_type (str) – Event types: ‘Trade’, ‘Quote’, ‘Summary’, ‘Profile’, ‘Order’, ‘TimeAndSale’, ‘Candle’, ‘TradeETH’, ‘SpreadOrder’, ‘Greeks’, ‘TheoPrice’, ‘Underlying’, ‘Series’, ‘Configuration’ or ‘’
- data_len (int) – Sets maximum amount of events, that are kept in Subscription class. Default 100000.
Returns: sc – Cython SubscriptionClass with information about subscription
Return type:
-
dxfeed.core.DXFeedPy.dxf_create_subscription_timed()¶ Creates a timed subscription with the specified parameters.
Notes
Default limit for ‘Candle’ event type is 8000 records. The other event types have default limit of 1000 records.
Parameters: - cc (ConnectionClass) – Variable with connection information
- event_type (str) – Event types: ‘Trade’, ‘Quote’, ‘Summary’, ‘Profile’, ‘Order’, ‘TimeAndSale’, ‘Candle’, ‘TradeETH’, ‘SpreadOrder’, ‘Greeks’, ‘TheoPrice’, ‘Underlying’, ‘Series’, ‘Configuration’ or ‘’
- time (int) – UTC time in the past (unix time in milliseconds)
- data_len (int) – Sets maximum amount of events, that are kept in Subscription class. Default 100000.
Returns: sc – Cython SubscriptionClass with information about subscription
Return type:
-
dxfeed.core.DXFeedPy.dxf_detach_listener()¶ Detaches any listener
Parameters: sc (SubscriptionClass) – SubscriptionClass with information about subscription
-
dxfeed.core.DXFeedPy.dxf_get_current_connected_address()¶ Returns current connected address
Parameters: cc (ConnectionClass) – Variable with connection information Returns: address – Current connected address Return type: str
-
dxfeed.core.DXFeedPy.dxf_get_current_connection_status()¶ Returns one of four possible statuses
Parameters: - cc (ConnectionClass) – Variable with connection information
- return_str (bool) – When True returns connection status in string format, otherwise internal c representation as integer
-
dxfeed.core.DXFeedPy.dxf_get_subscription_event_types()¶ Gets subscription event type
Parameters: - sc (SubscriptionClass) – SubscriptionClass with information about subscription
- return_str (bool) – When True returns event type in string format, otherwise internal c representation as integer
Returns: Subscription type
Return type: str or int
-
dxfeed.core.DXFeedPy.dxf_get_symbols()¶ Retrieves the list of symbols currently added to the subscription.
Parameters: sc (SubscriptionClass) – SubscriptionClass with information about subscription Returns: List of unicode strings of subscription symbols Return type: list
-
dxfeed.core.DXFeedPy.dxf_initialize_logger()¶ Initializes the internal logger. Various actions and events, including the errors, are being logged throughout the library. They may be stored into the file.
Parameters: - file_name (str) – A full path to the file where the log is to be stored
- rewrite_file (bool) – A flag defining the file open mode if it’s True then the log file will be rewritten
- show_timezone_info (bool) – A flag defining the time display option in the log file if it’s True then the time will be displayed with the timezone suffix
- verbose (bool) – A flag defining the logging mode if it’s True then the verbose logging will be enabled
-
dxfeed.core.DXFeedPy.dxf_remove_symbols()¶ Removes several symbols from the subscription
Parameters: - sc (SubscriptionClass) – SubscriptionClass with information about subscription
- symbols (list) – List of symbols to remove
-
dxfeed.core.DXFeedPy.process_last_error()¶ Function retrieves last error
Parameters: verbose (bool) – If True error description is printed Returns: error_code – Error code is returned Return type: int
Utils functions¶
-
dxfeed.core.utils.helpers.event_type_convert()¶ The function converts event type given as string to int, used in C dxfeed dxfeed
Parameters: event_type (str) – - Event type: ‘Trade’, ‘Quote’, ‘Summary’, ‘Profile’, ‘Order’, ‘TimeAndSale’, ‘Candle’, ‘TradeETH’, ‘SpreadOrder’,
- ’Greeks’, ‘TheoPrice’, ‘Underlying’, ‘Series’, ‘Configuration’ or ‘’
Returns: Integer that corresponds to event type in C dxfeed dxfeed Return type: int
-
dxfeed.core.utils.helpers.get_include()¶ Function returns paths to header files of dxfeed-c-api library. Used for writing custom listeners
Returns: out_dir – List of paths to header files Return type: list
-
class
dxfeed.core.utils.data_class.DequeWithLock(iterable=(), maxlen=None)¶ Class that provides lock mechanism to deque from collections for append, copy and get operations
-
safe_append(data: Any)¶ Method appends data while locked
Parameters: data (any) – Data to append
-
safe_get()¶ Method that pops all the data with subsequent clearing
Returns: list_to_return – List filled with data Return type: list
-