def _create_fix_socket(self, config_file): settings = fix.SessionSettings(config_file) gateway = FixMarketAdapter(self) store_factory = fix.FileStoreFactory(settings) log_factory = fix.ScreenLogFactory(settings) return fix.SocketInitiator(gateway, store_factory, settings, log_factory)
def create_initiator(initiator_config, simulation_config): def create_subscriptions(instruments): result = Subscriptions() for instrument in instruments: subscription = Subscription(instrument['symbol']) result.add(subscription) return result settings = quickfix.SessionSettings(initiator_config) config = load_yaml(simulation_config) fix_version = create_fix_version(config) subscriptions = create_subscriptions(config['instruments']) logger = create_logger(config) subscribe_interval = config.get('subscribe_interval', 1) skip_snapshot_chance = config.get('skip_snapshot_chance', 0) application = Client(fix_version, logger, skip_snapshot_chance, subscribe_interval, subscriptions) storeFactory = quickfix.FileStoreFactory(settings) logFactory = quickfix.ScreenLogFactory(settings) initiator = quickfix.SocketInitiator(application, storeFactory, settings, logFactory) return initiator
def main(): sessionID = fix.SessionID('FIX.4.4', SENDERCOMPID, 'PAYMIUM') params = fix.Dictionary() params.setString('ConnectionType', 'initiator') params.setString('StartTime', '00:00:00') params.setString('EndTime', '00:00:00') params.setString('HeartBtInt', '30') params.setString('CheckLatency', 'Y') params.setString('SocketConnectHost', '195.154.171.115') params.setString('SocketConnectPort', '8359') params.setString('DataDictionary', FIX44FILE) params.setString('EncryptMethod', '0') settings = fix.SessionSettings() settings.set(sessionID, params) application = MyApplication() factory = fix.FileStoreFactory("store") acceptor = fix.SocketInitiator(application, factory, settings, fix.ScreenLogFactory(DEBUG, DEBUG, DEBUG)) acceptor.start() time.sleep(2) mdr = fixMsg.MarketDataRequest() mdr.setField(fix.MDReqID("MDRQ-%d" % (time.time() * 1000000))) # We want the full book here, not just the top mdr.setField(fix.MarketDepth(1)) # We want to get a snapshot and also subscribe to the market depth updates mdr.setField( fix.SubscriptionRequestType( fix.SubscriptionRequestType_SNAPSHOT_PLUS_UPDATES)) # We'll want only incremental refreshes when new data is available mdr.setField(fix.MDUpdateType(fix.MDUpdateType_INCREMENTAL_REFRESH)) # Specify the currency instruments = fixMsg.MarketDataRequest().NoRelatedSym() instruments.setField(fix.Symbol("EUR/XBT")) mdr.addGroup(instruments) # Specify that we'll want the bids and asks mdr.setField(fix.NoMDEntryTypes(2)) group = fixMsg.MarketDataRequest().NoMDEntryTypes() group.setField(fix.MDEntryType(fix.MDEntryType_BID)) group.setField(fix.MDEntryType(fix.MDEntryType_OFFER)) mdr.addGroup(group) fix.Session.sendToTarget(mdr, sessionID) while True: time.sleep(10) acceptor.stop()
def __init__(self, config_file='../config/pricing.conf', username = '', password = ''): self.config_file = config_file self.fix_pricing_instance = FixPricing(fix.Session, username, password) self.fix_settings = fix.SessionSettings(self.config_file) self.fix_store_factory = fix.FileStoreFactory(self.fix_settings) self.log_factory = fix.ScreenLogFactory(self.fix_settings) self.initiator = fix.SocketInitiator(self.fix_pricing_instance, self.fix_store_factory, self.fix_settings, self.log_factory) self.initiator.start()
def create_acceptor(acceptor_config, simulation_config): def create_subscriptions(sources): subscriptions = Subscriptions() for source in sources: variation = source.get('variation', None) if variation: step, limit = variation.get('step', 0), variation.get('limit', 0) else: step, limit = 0, 0 subscription = Subscription(source['symbol'], SnapshotGenerator(step, limit)) for quote in source['bid']: subscription.generator.addQuote( Quote(Quote.BID, quote['price'], quote['size'])) for quote in source['ask']: subscription.generator.addQuote( Quote(Quote.ASK, quote['price'], quote['size'])) subscriptions.add(subscription) return subscriptions settings = quickfix.SessionSettings(acceptor_config) config = load_yaml(simulation_config) fix_version = create_fix_version(config) publish_interval = config.get("publish_interval", 1) subscriptions = create_subscriptions(config['instruments']) logger = create_logger(config) rejectRate = config.get("reject_rate", 0) application = Server(fix_version, logger, publish_interval, rejectRate, subscriptions) storeFactory = quickfix.FileStoreFactory(settings) logFactory = quickfix.ScreenLogFactory(settings) acceptor = quickfix.SocketAcceptor(application, storeFactory, settings, logFactory) return acceptor
executionReport.setField( fix.ExecType(fix.ExecType_FILL) ) executionReport.setField( fix.LeavesQty(0) ) time.sleep(5) try: fix.Session.sendToTarget( executionReport, sessionID ) except SessionNotFound as e: return def genOrderID(self): self.orderID = self.orderID+1 return self.orderID def genExecID(self): self.execID = self.execID+1 return self.execID try: file = sys.argv[1] settings = fix.SessionSettings( file ) application = Application() storeFactory = fix.FileStoreFactory( settings ) logFactory = fix.ScreenLogFactory( settings ) acceptor = fix.SocketAcceptor( application, storeFactory, settings, logFactory ) acceptor.start() while 1: time.sleep(1) except (fix.ConfigError, fix.RuntimeError) as e: print(e)
def start(self): """""" self.register_event() # For child app child_settings = fix.SessionSettings() child_dict = fix.Dictionary() child_dict.setString("ConnectionType", "acceptor") child_dict.setString("ResetOnLogon", "Y") child_dict.setString("FileLogPath", "./genus_log/child") child_dict.setString("LogonTimeout", "30") child_dict.setString("StartTime", "00:00:00") child_dict.setString("EndTime", "00:00:00") child_dict.setString("HeartBtInt", "30") child_dict.setString("CheckLatency", "N") child_dict.setString("UseDataDictionary", "N") child_dict.setString("FileStorePath", "./genus_store/child") child_dict.setString("ScreenLogShowIncoming", "N") child_dict.setString("ScreenLogShowOutgoing", "N") child_dict.setString("ScreenLogShowEvents", "N") child_dict.setString("SocketAcceptHost", SETTINGS["genus.child_host"]) child_dict.setString("SocketAcceptPort", SETTINGS["genus.child_port"]) child_session = fix.SessionID("FIX.4.2", SETTINGS["genus.child_sender"], SETTINGS["genus.child_target"]) child_settings.set(child_session, child_dict) child_store_factory = fix.FileStoreFactory(child_settings) child_log_factory = fix.ScreenLogFactory(child_settings) self.child_app: GenusChildApp = GenusChildApp(self) self.child_socket = fix.SocketAcceptor(self.child_app, child_store_factory, child_settings, child_log_factory) self.child_socket.start() # For parent app parent_settings = fix.SessionSettings() parent_dict = fix.Dictionary() parent_dict.setString("ConnectionType", "initiator") parent_dict.setString("ResetOnLogon", "Y") parent_dict.setString("FileLogPath", "./genus_log/parent") parent_dict.setString("LogonTimeout", "30") parent_dict.setString("StartTime", "00:00:00") parent_dict.setString("EndTime", "00:00:00") parent_dict.setString("HeartBtInt", "30") parent_dict.setString("CheckLatency", "N") parent_dict.setString("UseDataDictionary", "N") parent_dict.setString("FileStorePath", "./genus_store/parent") parent_dict.setString("ScreenLogShowIncoming", "N") parent_dict.setString("ScreenLogShowOutgoing", "N") parent_dict.setString("ScreenLogShowEvents", "N") parent_dict.setString("SocketConnectHost", SETTINGS["genus.parent_host"]) parent_dict.setString("SocketConnectPort", SETTINGS["genus.parent_port"]) parent_session = fix.SessionID("FIX.4.2", SETTINGS["genus.parent_sender"], SETTINGS["genus.parent_target"]) parent_settings.set(parent_session, parent_dict) parent_store_factory = fix.FileStoreFactory(parent_settings) parent_log_factory = fix.ScreenLogFactory(parent_settings) self.parent_app: GenusParentApp = GenusParentApp(self) self.parent_socket = fix.SocketInitiator(self.parent_app, parent_store_factory, parent_settings, parent_log_factory) self.parent_socket.start()
def getOrderDetails(self, orderID): table = texttable.Texttable() table.set_cols_width([16, 32]) for key in self.orders[orderID]: table.add_row([key, self.orders[orderID][key]]) print table.draw() if len(sys.argv) > 1: configFile = sys.argv[1] else: configFile = 'mfs-quickfix.cfg' settings = quickfix.SessionSettings(configFile) application = FIXServer() logFactory = quickfix.ScreenLogFactory(settings) storeFactory = quickfix.FileStoreFactory(settings) acceptor = quickfix.SocketAcceptor(application, storeFactory, settings) fixServer = threading.Thread(target=acceptor.start()) fixServer.start() def help(): print "Commands are: " print "\tbook ## Shows current order book" print "\tack [orderID] ## Sends acknowledgement on orderID" print "\tcancel [orderID] ## Sends cancel ack on orderID" print "\tfill [orderID] [quantity] ## Sends a fill on orderID with quantity" print "\torder [orderID] ## Provides details about the order" print "\tremove [orderID] ## Removes the order from the book" print "\treplace [orderID] ## Sends a ReplaceAck on orderID" print "\treplacepend [orderID] ## Sends a ReplacePending message for orderID"