#!/bin/env python import pytest from pprint import pprint import ujson as json from txtrader_monitor import Monitor ret = None m = Monitor() def _orders(channel, data): global ret print(f'{channel}: {data}') ret = json.loads(data) return False def _status(channel, msg): print(f'{channel}: {msg}') if msg.startswith('.Authorized'): m.send('orders') return True def test_orders(): m.set_callback('STATUS', _status) m.set_callback('ORDERS', _orders) m.run() assert ret != None
#!/bin/env python import pytest from txtrader_monitor import Monitor monitor = Monitor() def _status(channel, msg): global monitor print(f'{channel}: {msg}') print(f'connection_state is {monitor.connection_state.name}') return not msg.startswith('.Authorized') def test_send_error(): global monitor monitor.send('test') def test_callback(): global monitor # override single callback, leaving others to print monitor.set_callback('STATUS', _status) monitor.run()
from txtrader_monitor import Monitor import json from pprint import pprint options = {'symbol': 'MSFT', 'query_sent': False, 'querydata_sent': False} m = Monitor(log_level='WARNING') def symbol(channel, data): result = json.loads(data) pprint(json.loads(data)) symbol = options['symbol'] if not options['query_sent']: options['query_sent'] = True m.send(f"query {symbol}") elif not options['querydata_sent']: options['querydata_sent'] = True m.send(f"querydata {symbol}") return True def symbol_data(channel, data): pprint(json.loads(data)) return False def status(channel, data): print(f"{channel}: {data}") if data.startswith('.Authorized'): options['query_sent'] = False