def setUp(self): #print("Entering", self._testMethodName) self.store = fix.FileStoreFactory() self.settings = fix.SessionSettings([]) self.settings.read_dict({self._testMethodName: {'ConnectionType': 'acceptor', 'BeginString': 'FIX.4.2', 'SenderCompID': 'HOST', 'TargetCompID': self._testMethodName, # 'CLIENT', 'SocketAcceptPort': '5001', 'StorageConnectionString': 'sqlite:///:memory:?check_same_thread=False', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.utcnow() - timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S')}}) self.settings_client = fix.SessionSettings([]) self.settings_client.read_dict({self._testMethodName: {'ConnectionType': 'initiator', 'BeginString': 'FIX.4.2', 'SenderCompID': self._testMethodName, # 'CLIENT', 'TargetCompID': 'HOST', 'SocketConnectPort': '5001', 'SocketConnectHost': 'localhost', 'StorageConnectionString': 'sqlite:///:memory:?check_same_thread=False', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.utcnow() - timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S')}}) self.client_app = FIXTestAppClient() self.client = fix.SocketConnection( self.client_app, self.store, self.settings_client) self.server_app = FIXTestAppServer() self.server = fix.SocketConnection( self.server_app, self.store, self.settings)
def setUp(self): #print("Entering", self._testMethodName) self.store = fix.FileStoreFactory() self.settings = fix.SessionSettings([]) self.settings.read_dict({self._testMethodName: {'ConnectionType': 'acceptor', 'BeginString': 'FIX.4.2', 'SenderCompID': 'HOST', 'TargetCompID': self._testMethodName, # 'CLIENT', 'SocketAcceptPort': '5001', 'StorageConnectionString': 'sqlite:///:memory:?check_same_thread=False', 'HeartBeatInt': '1', 'HeatBeatGracePeriod': '2', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.utcnow() - timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S')}}) self.settings_client = fix.SessionSettings([]) self.settings_client.read_dict({self._testMethodName: {'ConnectionType': 'initiator', 'BeginString': 'FIX.4.2', 'SenderCompID': self._testMethodName, # 'CLIENT', 'TargetCompID': 'HOST', 'SocketConnectPort': '5001', 'SocketConnectHost': 'localhost', 'StorageConnectionString': 'sqlite:///:memory:?check_same_thread=False', 'HeartBeatInt': '1', 'HeatBeatGracePeriod': '2', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.utcnow() - timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S')}}) self.client_app = FIXTestAppClient() self.client = fix.SocketConnection( self.client_app, self.store, self.settings_client) self.server_app = FIXTestAppServer() self.server = fix.SocketConnection( self.server_app, self.store, self.settings) self.server.start() self.client.start() resp_logon = SERVER_QUEUE.get(timeout=3) sent_logon = CLIENT_QUEUE.get(timeout=3) self.assertIsInstance(resp_logon, fix_messages_4_2_0_base.Logon) self.assertIsInstance(sent_logon, fix_messages_4_2_0_base.Logon)
def test_logout_timer(self): self.settings_client = fix.SessionSettings([]) self.settings_client.read_dict({ self._testMethodName: { 'ConnectionType': 'initiator', 'BeginString': 'FIX.4.2', 'SenderCompID': self._testMethodName, # 'CLIENT', 'TargetCompID': 'HOST', 'SocketConnectPort': '5001', 'SocketConnectHost': 'localhost', 'StorageConnectionString': f'sqlite:///store/{self._testMethodName}.client.db?check_same_thread=False', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.utcnow() + timedelta(seconds=0)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=3)).time().strftime('%H:%M:%S') } }) self.client_app = FIXTestAppClient() self.client = fix.SocketConnection(self.client_app, self.store, self.settings_client) self.server.start() self.client.start() resp_logon = SERVER_QUEUE.get(timeout=3) sent_logon = CLIENT_QUEUE.get(timeout=3) self.assertIsInstance(resp_logon, fix_messages_4_2_0_base.Logon) self.assertIsInstance(sent_logon, fix_messages_4_2_0_base.Logon) self.assertIsInstance(SERVER_QUEUE.get(timeout=5), fix_messages_4_2_0_base.TestRequest) self.assertIsInstance(SERVER_QUEUE.get(timeout=3), fix_messages_4_2_0_base.Logout) self.assertIsInstance(CLIENT_QUEUE.get(timeout=3), fix_messages_4_2_0_base.Heartbeat) self.assertIsInstance(CLIENT_QUEUE.get(timeout=3), fix_messages_4_2_0_base.Logout)
def main(): settings = fix.SessionSettings('config.ini') client_app = FIXApp() store = fix.FileStoreFactory() client = fix.SocketConnection(client_app, store, settings) task = client.start() while not task.done(): time.sleep(1) print(task.result())
def test_dupe_logon(self): self.client.start() settings_client2 = fix.SessionSettings([]) settings_client2.read_dict({ self._testMethodName: { 'ConnectionType': 'initiator', 'BeginString': 'FIX.4.2', 'SenderCompID': self._testMethodName, # 'CLIENT', 'TargetCompID': 'HOST', 'SocketConnectPort': '5001', 'SocketConnectHost': 'localhost', 'StorageConnectionString': 'sqlite:///:memory:?check_same_thread=False', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.utcnow() - timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S') } }) client_app2 = FIXTestAppClient() client2 = fix.SocketConnection(client_app2, self.store, settings_client2) resp_logon = SERVER_QUEUE.get(timeout=3) sent_logon = CLIENT_QUEUE.get(timeout=3) self.assertIsInstance(resp_logon, fix_messages_4_2_0_base.Logon) self.assertIsInstance(sent_logon, fix_messages_4_2_0_base.Logon) client2.start() error = SERVER_QUEUE.get(timeout=3) self.assertIsInstance(error, fix_errors.FIXSessionExistsError) self.do_logout(self.client_app) client_app2.close_connection(self._testMethodName)
def test_timezone_logon(self): self.settings = fix.SessionSettings([]) self.settings.read_dict({ self._testMethodName: { 'ConnectionType': 'acceptor', 'BeginString': 'FIX.4.2', 'SenderCompID': 'HOST', 'TargetCompID': self._testMethodName, # 'CLIENT', 'SocketAcceptPort': '5001', 'StorageConnectionString': f'sqlite:///store/{self._testMethodName}.server.db?check_same_thread=False', 'SessionTimeZone': 'America/New_York', 'ConnectionStartTime': datetime.now( gettz('America/New_York')).time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.now(gettz('America/New_York')) + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.now(gettz('America/New_York')) + timedelta(seconds=0)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.now(gettz('America/New_York')) + timedelta(seconds=3)).time().strftime('%H:%M:%S') } }) self.server_app = FIXTestAppServer() self.server = fix.SocketConnection(self.server_app, self.store, self.settings) self.server.start() self.client.start() resp_logon = SERVER_QUEUE.get(timeout=3) sent_logon = CLIENT_QUEUE.get(timeout=3) self.assertIsInstance(resp_logon, fix_messages_4_2_0_base.Logon) self.assertIsInstance(sent_logon, fix_messages_4_2_0_base.Logon) self.do_logout(self.client_app)
def test_reject_out_of_window(self): self.settings = fix.SessionSettings([]) self.settings.read_dict({ self._testMethodName: { 'ConnectionType': 'acceptor', 'BeginString': 'FIX.4.2', 'SenderCompID': 'HOST', 'TargetCompID': self._testMethodName, # 'CLIENT', 'SocketAcceptPort': '5001', 'StorageConnectionString': f'sqlite:///store/{self._testMethodName}.server.db?check_same_thread=False', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': (datetime.utcnow() + timedelta(seconds=8)).time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S') } }) self.server_app = FIXTestAppServer() self.server = fix.SocketConnection(self.server_app, self.store, self.settings) self.server.start() self.client.start() self.assertIsInstance(SERVER_QUEUE.get(timeout=3), fix_errors.FIXRejectError) self.assertIsInstance(CLIENT_QUEUE.get(timeout=3), fix_errors.FIXInvalidFirstMessage) self.assertIsInstance(SERVER_QUEUE.get(timeout=3), fix_errors.FIXDropMessageError)
def test_invalid_comp_ID(self): settings_bad_client = fix.SessionSettings([]) settings_bad_client.read_dict({ 'SESSION1': { 'ConnectionType': 'initiator', 'BeginString': 'FIX.4.2', 'SenderCompID': 'CLIENT1', 'TargetCompID': 'HOST', 'SocketConnectPort': '5001', 'SocketConnectHost': 'localhost', 'StorageConnectionString': 'sqlite:///:memory:?check_same_thread=False', 'ConnectionStartTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'ConnectionEndTime': (datetime.utcnow() + +timedelta(seconds=10)).time().strftime('%H:%M:%S'), 'LogonTime': datetime.utcnow().time().strftime('%H:%M:%S'), 'LogoutTime': (datetime.utcnow() + timedelta(seconds=10)).time().strftime('%H:%M:%S') } }) client_bad_app = FIXTestAppClient() client_bad = fix.SocketConnection(client_bad_app, self.store, settings_bad_client) # self.server.start() client_bad.start() error = SERVER_QUEUE.get(timeout=3) self.assertIsInstance(error, fix_errors.FIXSessionNotFound) self.assertTrue(CLIENT_QUEUE.empty()) client_bad_app.close_connection(self._testMethodName) client_bad.stop_all()