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)
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)
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
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)
def add_symbols(self, symbols: Union[str, Iterable[str]]): """ Method to add symbol. Supports addition of one symbol as a string as well as list of symbols. If no event handler was set, DefaultHandler will be initialized. Parameters ---------- symbols: str, Iterable Symbols to add. Previously added and remained symbols are ignored on C-API level Returns ------- self: Subscription """ self._attach_default_listener() dxp.dxf_add_symbols(sc=self.__sub, symbols=cu.to_iterable(symbols)) return self
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'])