示例#1
0
    def __init__(self,
                 connection,
                 event_type: str,
                 date_time: Union[str, datetime],
                 exact_format: bool = True):
        """

        Parameters
        ----------
        connection: dxfeed.core.DXFeedPy.ConnectionClass
            Core class written in cython, that handle connection related details on the low level
        event_type: str
            One of possible event types: 'Trade', 'Quote', 'Summary', 'Profile', 'Order', 'TimeAndSale', 'Candle',
            'TradeETH', 'SpreadOrder', 'Greeks', 'TheoPrice', 'Underlying', 'Series', 'Configuration' or ''
        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 (non-conflated). Default - None.
        exact_format: bool
            If False no warning will be thrown in case of incomplete date_time parameter. Default - True
        """
        self.__event_type = event_type
        if date_time is None:
            self.__sub = dxp.dxf_create_subscription(cc=connection,
                                                     event_type=event_type)
        else:
            date_time = cu.handle_datetime(date_time,
                                           fmt='%Y-%m-%d %H:%M:%S.%f',
                                           exact_format=exact_format)
            timestamp = int(date_time.timestamp() * 1000)
            self.__sub = dxp.dxf_create_subscription_timed(
                cc=connection, event_type=event_type, time=timestamp)
示例#2
0
def test_symbol_addition(connection):
    symbols = ['AAPL', 'GOOG']
    sub = dxc.dxf_create_subscription(cc=connection, event_type='Trade')
    dxc.dxf_add_symbols(sc=sub, symbols=symbols)
    actual_symbols = dxc.dxf_get_symbols(sc=sub)
    dxc.dxf_close_subscription(sub)
    assert set(symbols) == set(actual_symbols)
示例#3
0
def test_wrong_symbol_types_ignored(connection):
    symbols = ['AAPL', 'GOOG']
    sub = dxc.dxf_create_subscription(cc=connection, event_type='Trade')
    dxc.dxf_add_symbols(sc=sub, symbols=symbols + [1, 5.0, [], True, {}, ()])
    actual_symbols = dxc.dxf_get_symbols(sc=sub)
    dxc.dxf_close_subscription(sub)
    assert set(symbols) == set(actual_symbols)
示例#4
0
def test_symbol_deletion(connection):
    symbols = ['AAPL', 'GOOG']
    sub = dxc.dxf_create_subscription(cc=connection, event_type='Trade')
    dxc.dxf_add_symbols(sc=sub, symbols=symbols)
    dxc.dxf_remove_symbols(sc=sub, symbols=['AAPL'])
    actual_symbols = dxc.dxf_get_symbols(sc=sub)
    dxc.dxf_close_subscription(sub)
    assert ['GOOG'] == actual_symbols
示例#5
0
def test_double_event_handler_attachment(connection):
    handler1 = DefaultHandler()
    handler2 = DefaultHandler()
    sub = dxc.dxf_create_subscription(cc=connection, event_type='Trade')
    sub.set_event_handler(handler1)
    dxc.dxf_attach_listener(sub)
    symbols = ['AAPL', 'MSFT']
    dxc.dxf_add_symbols(sub, symbols)
    sub.set_event_handler(handler2)
    assert sub.get_event_handler() is handler2
    assert set(dxc.dxf_get_symbols(sub)) == set(symbols)
示例#6
0
def test_subscription_fail_on_incorrect_type(connection):
    dxc.dxf_create_subscription(cc=connection, event_type='TradeQuote')
示例#7
0
def test_subscription_on_correct_types(connection, sub_type):
    sub = dxc.dxf_create_subscription(cc=connection, event_type=sub_type)
    act_sub_type = dxc.dxf_get_subscription_event_types(sc=sub)
    dxc.dxf_close_subscription(sub)
    assert act_sub_type == sub_type
示例#8
0
def test_fail_to_use_subscription_without_connection(connection):
    sub = dxc.dxf_create_subscription(cc=connection, event_type='Trade')
    dxc.dxf_close_connection(connection)
    dxc.dxf_add_symbols(sc=sub, symbols=['AAPL'])
示例#9
0
def test_fail_create_subscription_with_no_connection():
    dxc.dxf_create_subscription()
示例#10
0
def test_default_event_handler(connection, sub_type):
    sub = dxc.dxf_create_subscription(cc=connection, event_type=sub_type)
    sub.set_event_handler(DefaultHandler())
    assert isinstance(sub.get_event_handler(), DefaultHandler)