def main(config_file):
    try:
        settings = fix.SessionSettings(config_file)
        application = Application()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(application, storeFactory, settings,
                                        logFactory)
        initiator.start()

        while 1:
            input = raw_input()
            if input == '1':
                print "Colocando orden"
                application.put_order()
            if input == '2':
                sys.exit(0)
            if input == 'd':
                import pdb
                pdb.set_trace()
            else:
                print "Ingresar 1 para mandar una orden, 2 para salir"
                continue
    except (fix.ConfigError, fix.RuntimeError), e:
        print e
    def __init__(self, config_file, usrId, pswd, targetCompID, tickers, entries):
        # def __init__(self, config_file, usrId, pswd, targetCompID):
        self.config_file = config_file
        self.usrId = usrId
        self.pswd = pswd
        self.targetCompID = targetCompID
        self.tickers = tickers
        self.entries = entries

        try:
            self.settings = fix.SessionSettings(self.config_file)
            self.myFixApplication = rofexEngine(self.usrId, self.pswd, self.targetCompID, self.tickers, self.entries)
            self.storefactory = fix.FileStoreFactory(self.settings)
            self.logfactory = fix.FileLogFactory(self.settings)
            self.initiator = fix.SocketInitiator(self.myFixApplication, self.storefactory, self.settings,
                                                 self.logfactory)

            """
            * Se puede iniciar desde aca
            
            self.initiator.start()
            self.myFixApplication.run()
            self.initiator.stop()
            """
        except (fix.ConfigError, fix.RuntimeError) as e:

            print(e)
            self.initiator.stop()
            sys.exit()
def main():
    try:
        settings = fix.SessionSettings('config/client.cfg')
        application = Client()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        client = fix.SocketInitiator(application, storeFactory, settings,
                                     logFactory)
        client.start()
        while True:
            order = raw_input().strip().split()
            cmd, order_id, side, qty, price = order
            message_details = order_id, side, float(qty), float(price)
            if cmd == 'x':
                client.stop()
                break
            if cmd == 'n':
                # new order
                application.new_order(message_details)
            if cmd == 'c':
                # cancel order
                application.cancel_order(message_details)
            if cmd == 'r':
                # replace order
                application.replace_order(message_details)
            if cmd == 'm':
                # market data request
                application.market_data_request()
            time.sleep(1)
    except (fix.ConfigError, fix.RuntimeError), e:
        print(e)
Exemple #4
0
def main(config_file):
    #def main():
    """Main"""
    try:

        # *******Lectura de file de configuracion
        cpParser = configparser.RawConfigParser()
        cfgFile = r'../conf/usrCredentials.cfg'
        cpParser.read(cfgFile)
        usrId = cpParser.get('usr-credentials', 'usr')
        pswd = cpParser.get('usr-credentials', 'pswd')
        #************************

        settings = quickfix.SessionSettings(config_file)
        myFixApplication = fixEngine()
        myFixApplication.setUsrId(usrId)
        myFixApplication.setUsrPswd(pswd)

        storefactory = quickfix.FileStoreFactory(settings)
        logfactory = quickfix.FileLogFactory(settings)
        initiator = quickfix.SocketInitiator(myFixApplication, storefactory,
                                             settings, logfactory)

        initiator.start()
        myFixApplication.run()

        #while 1:
        #   myFixApplication.goRobot()

        initiator.stop()

    except (quickfix.ConfigError, quickfix.RuntimeError) as e:
        print(e)
        initiator.stop()
        sys.exit()
Exemple #5
0
def main():
    try:
        settings = fix.SessionSettings("initiatorsettings.cfg")
        application = Application()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(application, storeFactory, settings,
                                        logFactory)
        initiator.start()

        while 1:
            input = raw_input()
            if input == '1':
                print "Putin Order"
                application.put_order()
            if input == '2':
                sys.exit(0)
            if input == 'd':
                import pdb
                pdb.set_trace()
            else:
                print "Valid input is 1 for order, 2 for exit"
                continue
    except (fix.ConfigError, fix.RuntimeError), e:
        print e
Exemple #6
0
 def CreateInitiator(cls, logger, config):
     logger.setLevel(logging.INFO)
     logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s')
     settings = fix.SessionSettings(config)
     application = FixClient(settings, logger)
     storeFactory = fix.FileStoreFactory(settings)
     logFactory = fix.FileLogFactory(settings)
     return fix.SocketInitiator(application, storeFactory, settings, logFactory)
Exemple #7
0
 def init_fix_settings(self, default_client_config_file_name=None):
     client_config_file_name_ = self.client_config_file_name if default_client_config_file_name is None \
         else default_client_config_file_name
     settings = fix.SessionSettings(client_config_file_name_)
     self.fix_application = ClientFIXApplication(self)
     self.storeFactory = fix.FileStoreFactory(settings)
     self.logFactory = fix.FileLogFactory(settings)
     self.socket_initiator = fix.SocketInitiator(self.fix_application, self.storeFactory, settings, self.logFactory)
Exemple #8
0
def init_test_client():
    try:
        settings = fix.SessionSettings('client.cfg')
        application = Application()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        client = fix.SocketInitiator(application, storeFactory, settings, logFactory)
        client.start()
        return client, application
    except (fix.ConfigError, fix.RuntimeError), e:
        print(e)
 def __init__(self, Brain):
     self.fix_connector = FixConnector(Brain)
     self.settings = quickfix.SessionSettings("./config/config.cfg")
     storefactory = quickfix.FileStoreFactory(self.settings)
     logfactory = quickfix.FileLogFactory(self.settings)
     self.initiator = quickfix.SocketInitiator(self.fix_connector,
                                               storefactory, self.settings,
                                               logfactory)
     self.initiator.start()
     while not self.initiator.isLoggedOn():
         continue
Exemple #10
0
def main(port=9000, debug=None):
    """FIX gateway

    Accepts orders over a FIX session.

    """
    if debug:
        logger.setLevel(logging.DEBUG)
        logger.info(f"Logging set to debug.")
    else:
        logger.setLevel(logging.INFO)
        logger.info(f"Logging set to info.")

    settings = fix.SessionSettings("configs/exchange.cfg")
    log = fix.FileLogFactory(settings)
    store = fix.FileStoreFactory(settings)
    app = MessageBroker()
    address = ("localhost", port)

    app.set_logging(logger)

    acceptor = fix.SocketAcceptor(app, store, settings, log)

    try:
        acceptor.start()
        logger.info("FIX.4.2 server started.")

        conn = Client(address, authkey=b"Dj$0.Jkx1@")

        logger.info(f"Started market data publisher at port {port}.")

        while True:
            sleep(1)
            if MARKETS:
                for market in MARKETS:
                    # remove the comment below to print debug orderbook
                    # logger.debug(f"\n{MARKETS[market]._show_orderbook()}")
                    if market in FLUSH_BOOK:
                        bids, asks = MARKETS[market].book()
                        trades = []
                        if FLUSH_BOOK[market]:
                            # trades
                            trades = list(set(FLUSH_BOOK[market]))
                        book = Book(market, bids, asks, trades)
                        conn.send(book)
                        FLUSH_BOOK.pop(market)

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()
    def __init__(self, config_file, usrId, pswd):
        Thread.__init__(self)

        self.config_file = config_file

        self.settings = fix.SessionSettings(config_file)
        self.myFixApplication = rofexEngine(usrId, pswd)

        self.storefactory = fix.FileStoreFactory(self.settings)
        self.logfactory = fix.FileLogFactory(self.settings)
        self.initiator = fix.SocketInitiator(self.myFixApplication,
                                             self.storefactory, self.settings,
                                             self.logfactory)
def main():
    try:
        settings = fix.SessionSettings('config/executor.cfg')
        application = Executor()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        executor = fix.SocketAcceptor(application, storeFactory, settings,
                                      logFactory)
        executor.start()
        while True:
            time.sleep(1)
    except (fix.ConfigError, fix.RuntimeError), e:
        print(e)
Exemple #13
0
def main(config_file):
    try:
        settings = fix.SessionSettings("acceptor.conf")
        application = Application()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        initiator = fix.SocketAcceptor(application, storeFactory, settings,
                                       logFactory)
        initiator.start()

        while 1:
            pass
    except (fix.ConfigError, fix.RuntimeError), e:
        print e
Exemple #14
0
def main(config_file):
    try:
        settings = fix.SessionSettings(config_file)
        application = Application()
        storefactory = fix.FileStoreFactory(settings)
        logfactory = fix.FileLogFactory(settings)
        acceptor = fix.SocketAcceptor(application, storefactory, settings,
                                      logfactory)
        acceptor.start()
        while (1):
            time.sleep(10)

    except (fix.ConfigError, fix.RuntimeError) as e:
        print(e)
        sys.exit()
Exemple #15
0
 def Create(cls, logger, config, storeMessages):
     logger.setLevel(logging.INFO)
     logging.basicConfig(
         format='%(asctime)s - %(levelname)s - %(threadName)s - %(message)s'
     )
     settings = fix.SessionSettings(config)
     application = GainApplication(settings, logger)
     storeFactory = fix.FileStoreFactory(
         settings) if storeMessages else fix.MemoryStoreFactory()
     logFactory = fix.FileLogFactory(settings) if storeMessages else None
     init = fix.SocketInitiator(application, storeFactory, settings,
                                logFactory)
     client = FixClient(init, logger)
     application.FixClientRef = client
     return client
Exemple #16
0
def main(file_name):

    try:
        settings = fix.SessionSettings(file_name)
        application = Application()
        storeFactory = fix.FileStoreFactory( settings )
        logFactory = fix.FileLogFactory( settings )
        print 'creating acceptor'
        acceptor = fix.SocketAcceptor( application, storeFactory, settings, logFactory )
        print 'starting acceptor'
        acceptor.start()

        while 1:
            time.sleep(1)
    except (fix.ConfigError, fix.RuntimeError), e:
        print e
def main(config_file):
    try:
        settings = quickfix.SessionSettings(config_file)
        application = Application()
        storefactory = quickfix.FileStoreFactory(settings)
        logfactory = quickfix.FileLogFactory(settings)
        initiator = quickfix.SocketInitiator(application, storefactory,
                                             settings, logfactory)

        initiator.start()
        application.run()
        initiator.stop()

    except (quickfix.ConfigError, quickfix.RuntimeError) as e:
        print(e)
        sys.exit()
    def __init__(self, config_file, market, user, passwd, account):
        Thread.__init__(self)
        self.config_file = config_file
        self.market = market
        self.user = user
        self.passwd = passwd
        self.account = account

        self.settings = fix.SessionSettings(self.config_file)
        self.application = Application(self.market, self.user, self.passwd,
                                       self.account)
        self.storefactory = fix.FileStoreFactory(self.settings)
        self.logfactory = fix.FileLogFactory(self.settings)
        self.initiator = fix.SocketInitiator(self.application,
                                             self.storefactory, self.settings,
                                             self.logfactory)
Exemple #19
0
def main(fileName):
    if len(sys.argv) < 2:
        return
    fileName = sys.argv[1]

    try:
        settings = quickfix.SessionSettings(fileName)
        application = quickfix.MyApplication()
        storeFactory = quickfix.FileStoreFactory(settings)
        logFactory = quickfix.FileLogFactory(settings)
        acceptor = quickfix.SocketAcceptor(application, storeFactory, settings,
                                           logFactory)
        acceptor.start()
        # while condition == true: do something
        acceptor.stop()
    except quickfix.ConfigError, e:
        print e
Exemple #20
0
def main(path):

    try:
        settings = fix.SessionSettings(path.name)
        application = Application(
            username=os.environ['FIX_USERNAME'],
            password=os.environ['FIX_PASSWORD'],
            sender_sub_id=os.environ['FIX_SENDER_SUB_ID'])
        store_factory = fix.FileStoreFactory(settings)
        log_factory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(application, store_factory, settings,
                                        log_factory)
        initiator.start()
        application.run()
        # time.sleep(5)
        initiator.stop()
    except fix.ConfigError as e:
        print(e)
Exemple #21
0
def main(file_name):
    """run an acceptor application service"""
    log.info("-->> executor main file_name:{}".format(file_name))
    try:
        settings = fix.SessionSettings(file_name)
        application = Application()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)

        acceptor = fix.SocketAcceptor(application, storeFactory, settings,
                                      logFactory)
        log.info('-->> starting acceptor')
        acceptor.start()

        while 1:
            time.sleep(1)
    except (fix.ConfigError, fix.RuntimeError) as e:
        print(e)
def main(file_name):
    """Main"""
    log.info("-->> initiator main file_name:{}".format(file_name))
    try:
        settings = fix.SessionSettings(file_name)
        application = Application()
        storefactory = fix.FileStoreFactory(settings)
        logfactory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(application, storefactory, settings, logfactory)
        application.initiator = initiator

        initiator.start()
        application.run()
        initiator.stop()
    except (fix.ConfigError, fix.RuntimeError) as e:
        print(e)
        initiator.stop()
        sys.exit()
Exemple #23
0
def main(port=9000, debug=None):
    """FIX price gateway

    Sends market data snapshot over FIX.

    """
    if debug:
        logger.setLevel(logging.DEBUG)
        logger.info("Logging set to debug.")
    else:
        logger.setLevel(logging.INFO)
        logger.info("Logging set to info.")

    settings = fix.SessionSettings("configs/price.cfg")
    log = fix.FileLogFactory(settings)
    store = fix.FileStoreFactory(settings)
    app = MarketDataAdapter()
    address = ("localhost", port)

    book = Book("Market", [(1, 1)], [(1, 1)], [])

    app.set_logging(logger)

    acceptor = fix.SocketAcceptor(app, store, settings, log)

    try:
        acceptor.start()

        logger.info("FIX.4.2 maarket data server started.")
        logger.debug(f"Starting listener on port {port}.")

        conn = Listener(address, authkey=b"Dj$0.Jkx1@").accept()

        logger.debug(f"Accepted orderbook connection on port {port}.")

        while True:
            book = conn.recv()
            app.dispatch(book)

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()
Exemple #24
0
    def create(cls, config_filename: str):
        config = parse_config(config_filename)

        rv = cls()

        rv.incoming_messages = Queue()
        rv.outgoing_messages = Queue()

        rv.data_dict = fix.DataDictionary(config['DataDictionary'])
        rv.enums = parse_enums(config['DataDictionary'])
        rv.username = config.get('Username')
        rv.password = config.get('Password')

        settings = fix.SessionSettings(config_filename)
        rv.socket_initiator = fix.SocketInitiator(
            rv, fix.FileStoreFactory(settings), settings,
            fix.FileLogFactory(settings))

        return rv
Exemple #25
0
def mainLogon(config_file, usrId, pswd, targetCompID, tickers):

    try:
        # suscribe=
        settings = fix.SessionSettings(config_file)
        myFixApplication = rofexEngine(usrId, pswd, targetCompID, tickers)
        storefactory = fix.FileStoreFactory(settings)
        logfactory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(myFixApplication, storefactory,
                                        settings, logfactory)

        initiator.start()
        myFixApplication.run()
        initiator.stop()

    except (fix.ConfigError, fix.RuntimeError) as e:
        print(e)
        initiator.stop()
        sys.exit()
Exemple #26
0
def start_fix(file_name):
    try:
        settings = fix.SessionSettings(file_name)
        application = FixApplication()
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        print('Creating FIX Acceptor')
        acceptor = fix.SocketAcceptor(application, storeFactory, settings,
                                      logFactory)

        print('Starting FIX Acceptor')
        acceptor.start()

        while 1:
            time.sleep(1)

        acceptor.stop()
    except (fix.ConfigError, fix.RuntimeError) as e:
        print(e)
def connect():
    keep_open = True

    try:
        settings = quickfix.SessionSettings("app/FIX/client/client_FIXT11.cfg")
        application = Application()
        store_factory = quickfix.FileStoreFactory(settings)
        log_factory = quickfix.FileLogFactory(settings)
        initiator = quickfix.SocketInitiator(application, store_factory,
                                             settings, log_factory)

        initiator.start()

        while keep_open:
            time.sleep(1)
            global isConnected
            isConnected = initiator.isLoggedOn()

        initiator.stop()
    except (quickfix.ConfigError, quickfix.RuntimeError) as e:
        print(e)
Exemple #28
0
    def __init__(self, tick_processor,
                 config_file='config/client_sample.conf',
                 read_positions_from_file=False,  # to load positions after restart
                 store_all_ticks=True,
                 save_history_to_files=True,
                 verbose=True,
                 message_log_file = 'messages.log',
                 execution_history_file='execution_history.log'):

        # Load FIX v4.4 DEFAULT & SESSION Configuration Settings
        self.settings = fix.SessionSettings(config_file)
        self.storeFactory = fix.FileStoreFactory(self.settings)
        # FileLogFactory to write log to file. ScreenLogFactory to write to console.  
        self.logFactory = fix.FileLogFactory(self.settings)

        self.tick_processor = tick_processor

        # Create instance of main application 
        self.app = application(self.settings, self.tick_processor, 
                               read_positions_from_file, store_all_ticks, 
                               save_history_to_files, verbose, 
                               message_log_file, execution_history_file)

        self.initiator = fix.SocketInitiator(self.app, 
                                             self.storeFactory, 
                                             self.settings, 
                                             self.logFactory)
        self.initiator.start()


        for i in range(10):
            if self.isLoggedOn():
                break
            sleep(1)

        
        if not self.isLoggedOn():
            print('[ERROR] Could not initialize session.')
Exemple #29
0
def main(config_file):
    try:
        settings = fix.SessionSettings(config_file)
        print '1'
        application = Application()
        print '2'
        storeFactory = fix.FileStoreFactory(settings)
        print '3'
        logFactory = fix.FileLogFactory(settings)
        print '4'
        initiator = fix.SocketInitiator(application, storeFactory, settings,
                                        logFactory)
        print '5'
        initiator.start()
        print '6'
        #application.run()
        time.sleep(300)
        print '7'
        initiator.stop()
        print '8'

    except (fix.ConfigError, fix.RuntimeError), e:
        print e
Exemple #30
0
def main(debug=None):
    """FIX gateway

    Accepts orders over a FIX session.

    """
    if debug:
        logger.setLevel(logging.DEBUG)
        logger.info(f"Logging set to debug.")
    else:
        logger.setLevel(logging.INFO)
        logger.info(f"Logging set to info.")

    settings = fix.SessionSettings("configs/exchange.cfg")
    log = fix.FileLogFactory(settings)
    store = fix.FileStoreFactory(settings)
    app = MessageBroker()

    app.set_logging(logger)

    acceptor = fix.SocketAcceptor(app, store, settings, log)

    try:
        acceptor.start()
        logger.info("FIX4.2 server started.")

        while True:
            sleep(1)
            if MARKETS:
                for market in MARKETS:
                    logger.debug(f"\n{MARKETS[market]._show_orderbook()}")

    except (fix.ConfigError, fix.RuntimeError) as error:
        raise fix.RuntimeError(error)
    except KeyboardInterrupt:
        logger.info(f"Got signal interrupt, exiting...")
        acceptor.stop()