Example #1
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
Example #2
0
 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 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 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
Example #5
0
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)
Example #6
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()
Example #7
0
    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()
Example #8
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)
Example #9
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)
 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
Example #11
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 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, 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)
Example #14
0
def main(client_config="configs/mdclient1.cfg", debug=None):
    """FIX market data client

    Client to receive market data 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.")

    config = configparser.ConfigParser()

    config.read(client_config)

    sender_compid = config["SESSION"]["SenderCompID"]
    target_compid = config["SESSION"]["TargetCompID"]

    settings = fix.SessionSettings(client_config)
    store = fix.FileStoreFactory(settings)
    app = MarketDataClient()

    app.set_logging(logger)

    initiator = fix.SocketInitiator(app, store, settings)

    initiator.start()

    sleep(1)

    symbol = int(input("Enter choice: - "
                       "\n1. request instruments"
                       "\n2. Enter symbol to subscribe: hello"
                       "\n> "))
    # symbol = input("Enter symbol to subscribe: ")
    if (symbol == 1):
        app.security_definition_request(sender_compid, target_compid)
    else:
        symbol = "all"
        app.market_data_request(sender_compid, target_compid, [symbol])

    try:
        while True:
            sleep(1)
    except KeyboardInterrupt:
        logger.info("Caught interrupt, exiting...")
        initiator.stop()
        sys.exit()
Example #15
0
    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()
Example #16
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
Example #17
0
    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)
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 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 True:
            time.sleep(0)
        initiator.stop()

    except (fix.ConfigError, fix.RuntimeError) as e:
        print(e)
        sys.exit()
Example #20
0
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()
Example #21
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)
Example #22
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
Example #23
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()
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)
Example #25
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.')
Example #26
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
Example #27
0
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:
            myInput = input()
            if myInput == "1":
                print("New Order")
                application.new_order()
            elif myInput == "2":
                print("Cancel Order")
                application.cancel_order()
            elif myInput == "3":
                print("Get order status")
                application.request_order()
            elif myInput == "4":
                print("Test unsupported msg type")
                application.list_cancel_request()
            elif myInput == "5":
                sys.exit(0)
            elif myInput == "d":
                import pdb
                pdb.set_trace()
            else:
                print(
                    "Valid input is 1 for new order, 2 for cancel order, 3 for order status, 4 for unsupported msg, 5 to exit"
                )
                continue
    except (fix.ConfigError, fix.RuntimeError) as e:
        print(e)
Example #28
0
    def toAdmin(self, message, sessionID):
        return

    def toApp(self, message, sessionID):
        return

    def fromAdmin(self, message, sessionID):
        return

    def fromApp(self, message, sessionID):
        return


if len(sys.argv) < 2:
    exit(1)
else:
    fileName = sys.argv[1]

try:
    settings = quickfix.SessionSettings(fileName)
    application = Application()
    storeFactory = quickfix.FileStoreFactory(settings)
    logFactory = quickfix.FileLogFactory(settings)
    acceptor = quickfix.SocketInitiator(application, storeFactory, settings,
                                        logFactory)
    acceptor.start()
    # while condition == true: do something
    acceptor.stop()
except quickfix.ConfigError, e:
    print e
Example #29
0
import sys
import time
import quickfix as fix
from qfix_app_BME import Application

try:
    thisFile = sys.argv[1]
    settings = fix.SessionSettings(thisFile)
    application = Application()
    storeFactory = fix.FileStoreFactory(settings)
    logFactory = fix.FileLogFactory(settings)
    initiator = fix.SocketInitiator(application, storeFactory, settings,
                                    logFactory)
    message_flag = True
    initiator.start()
    while 1:
        time.sleep(1)
        if message_flag is True:

            message = fix.Message()
            header = message.getHeader()
            trailer = message.getTrailer()

            header.setField(fix.BeginString(fix.BeginString_FIX42))
            header.setField(fix.BodyLength())
            header.setField(fix.MsgType(fix.MsgType_NewOrderSingle))
            header.setField(fix.SendingTime())
            header.setField(fix.SenderSubID("SG1"))
            header.setField(fix.TargetSubID("BARCA"))
            header.setField(fix.MsgSeqNum())
            header.setField(fix.DefaultApplVerID(fix.ApplVerID_FIX42))
    parser.add_argument("-f",
                        "--fix",
                        default=False,
                        help="increase fix output verbosity",
                        action="store_true")
    args = parser.parse_args()

    with open(args.market_config, 'r') as f:
        config = json.load(f)

    try:
        settings = fix.SessionSettings(args.fix_config)
        fix_client = FixClient(args.fix)
        storeFactory = fix.FileStoreFactory(settings)
        logFactory = fix.FileLogFactory(settings)
        initiator = fix.SocketInitiator(fix_client, storeFactory, settings,
                                        logFactory)
        initiator.start()

        buyers = populate_market(config["traders"]['buyers'], 'B', args.trader,
                                 fix_client)
        sellers = populate_market(config["traders"]['sellers'], 'S',
                                  args.trader, fix_client)

        traders = {}
        traders.update(buyers)
        traders.update(sellers)
        fix_client.traders = traders

        market_session = MarketSession(
            0,
            args.sync,