Beispiel #1
0
def get_session(args, reaktor, protocol):
    if args[0] == "client":
        app = FixClient(reaktor, protocol, name=args[0])
        app.set_conf("sender_comp_id", "ASIDE")
        app.set_conf("target_comp_id", "BSIDE")
    else:
        app = FixServer(reaktor, protocol, name=args[0])
        app.set_conf("sender_comp_id", "BSIDE")
        app.set_conf("target_comp_id", "ASIDE")

    app.set_conf("heartbeat_interval", 60)
    app.set_conf("login_wait_time", 30)
    app.set_conf("resend_mode", "GAPFILL")
    return app
Beispiel #2
0
def run_session(handler_expr, options):
    """Run FIX session.

    Loads message handler application from ``handler_expr``. Fix client session
    connects to ``net_url``, which is of form *//host:port* or *tls://host:port*.
    """
    net_url = ''
    ses_cf = {}
    app_cf = {}
    if options.config:
        cf = read_config(options.config)
        ses_cf.update(cf.items(options.name))
        app_cf.update(cf.items(options.appname))

    fix_version = ses_cf.get('fixversion', options.fixversion)
    net_url = ses_cf.get('destination', options.dest)
    store_url = ses_cf.get('message_store', options.messages)
    statepath = ses_cf.get('state_path', options.statepath)

    if not net_url:
        logging.error("No target address defined")
        sys.exit(1)

    r = urlparse.urlparse(net_url)
    if r.netloc:
        addr, port = r.netloc.split(':')
        netaddr = (addr, int(port))
        use_tls = r.scheme == 'tls'
    else:
        logging.error("Illegal target address. Must be [tls:]//<host>:<port>")
        sys.exit(1)

    reaktor = Reaktor()
    protocol = FixProtocol(version=fix_version)

    target = make_app(handler_expr)
    app = ProcessApplication(reaktor, target, name=options.name)

    ses = FixClient(reaktor, protocol, name=options.name, store_url=store_url)

    for key, val in ses_cf.items():
        if key in ['heartbeat_interval', 'login_wait_time']:
            ses.set_conf(key, int(val))
        elif key in ['reset_seqno']:
            ses.set_conf(key, bool(val))
        else:
            ses.set_conf(key, val)

    for key, val in app_cf.items():
        app.set_conf(key, val)

    if options.sender:
        ses.set_conf('sender_comp_id', options.sender)
    if options.target:
        ses.set_conf('target_comp_id', options.target)
    if options.resend:
        ses.set_conf('resend_mode', options.resend)
    if options.reset:
        ses.set_conf('reset_seqno', options.reset)
    if not ses.get_conf('heartbeat_interval'):
        ses.set_conf('heartbeat_interval', options.heartbeat)
    if not ses.get_conf('login_wait_time'):
        ses.set_conf('login_wait_time', 30)

    app.linkdown(ses)
    ses.linkup(app)
    # overload session login validator
    validator = LoginValidator(app, ses)
    ses.login_hook = validator.login_hook

    ses.start(netaddr)
    app.start()

    savelist = []
    if statepath:
        ses.state.restore(statepath)
        savelist = [(ses, statepath)]

    reaktor.run(savelist=savelist, exc_handler=validator.exchandler)
Beispiel #3
0
def get_session(args, reaktor, protocol):
    if args[0] == "client":
        app = FixClient(reaktor, protocol, name=args[0])
        app.set_conf('sender_comp_id', 'ASIDE')
        app.set_conf('target_comp_id', 'BSIDE')
    else:
        app = FixServer(reaktor, protocol, name=args[0])
        app.set_conf('sender_comp_id', 'BSIDE')
        app.set_conf('target_comp_id', 'ASIDE')

    app.set_conf('heartbeat_interval', 20)
    app.set_conf('login_wait_time', 30)
    app.set_conf('resend_mode', 'GAPFILL')
    return app
Beispiel #4
0
    if args:
        file_name = args.pop(0)

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version="4.4")

    if app_type == "sink":
        target = FixSink(file_name)
    else:
        target = FixSource(app_type)

    process = ProcessApplication(reaktor, target, name=app_type)
    ses = FixClient(reaktor, protocol, name="client", store_url=store_url)

    ses.set_conf("sender_comp_id", sender_id)
    ses.set_conf("target_comp_id", target_id)
    ses.set_conf("heartbeat_interval", hb_interval)
    ses.set_conf("login_wait_time", 30)
    ses.set_conf("resend_mode", resend)

    process.linkdown(ses)
    ses.linkup(process)

    if use_tls:
        ses.ssl_context(SSLClientContext(cert_reqs=ssl.CERT_OPTIONAL, ca_certs=cafile, ssl_version=ssl.PROTOCOL_TLSv1))

    ses.start(netaddr)
    process.start()
Beispiel #5
0
    if args:
        file_name = args.pop(0)

    logging.basicConfig(level=logging.DEBUG)

    reaktor = Reaktor()
    protocol = FixProtocol(version='4.4')

    if app_type == 'sink':
        target = FixSink(file_name)
    else:
        target = FixSource(app_type)

    process = ProcessApplication(reaktor, target, name=app_type)
    ses = FixClient(reaktor, protocol, name='client', store_url=store_url)

    ses.set_conf('sender_comp_id', sender_id)
    ses.set_conf('target_comp_id', target_id)
    ses.set_conf('heartbeat_interval', hb_interval)
    ses.set_conf('login_wait_time', 30)
    ses.set_conf('resend_mode', resend)

    process.linkdown(ses)
    ses.linkup(process)

    if use_tls:
        ses.ssl_context(
            SSLClientContext(cert_reqs=ssl.CERT_OPTIONAL,
                             ca_certs=cafile,
                             ssl_version=ssl.PROTOCOL_TLSv1))
Beispiel #6
0
def get_session(args, reaktor, protocol):
    if args[0] == "client":
        app = FixClient(reaktor, protocol, name=args[0])
        app.set_conf('sender_comp_id', 'ASIDE')
        app.set_conf('target_comp_id', 'BSIDE')
    else:
        app = FixServer(reaktor, protocol, name=args[0])
        app.set_conf('sender_comp_id', 'BSIDE')
        app.set_conf('target_comp_id', 'ASIDE')

    app.set_conf('heartbeat_interval', 20)
    app.set_conf('login_wait_time', 30)
    app.set_conf('resend_mode', 'GAPFILL')
    return app
Beispiel #7
0
def run_session(handler_expr, options):
    """Run FIX session.

    Loads message handler application from ``handler_expr``. Fix client session
    connects to ``net_url``, which is of form *//host:port* or *tls://host:port*.
    """
    net_url = ''
    ses_cf = {}
    app_cf = {}
    if options.config:
        cf = read_config(options.config)
        ses_cf.update(cf.items(options.name))
        app_cf.update(cf.items(options.appname))

    fix_version = ses_cf.get('fixversion', options.fixversion)
    net_url = ses_cf.get('destination', options.dest)
    store_url = ses_cf.get('message_store', options.messages)
    statepath = ses_cf.get('state_path', options.statepath)

    if not net_url:
        logging.error("No target address defined")
        sys.exit(1)
        
    r = urlparse.urlparse(net_url)
    if r.netloc:
        addr, port = r.netloc.split(':')
        netaddr = (addr, int(port))
        use_tls = r.scheme == 'tls'
    else:
        logging.error("Illegal target address. Must be [tls:]//<host>:<port>")
        sys.exit(1)

    
    reaktor = Reaktor()
    protocol = FixProtocol(version=fix_version)

    target = make_app(handler_expr)
    app = ProcessApplication(reaktor, target, name=options.name)

    ses = FixClient(reaktor, protocol, name=options.name, store_url=store_url)

    for key, val in ses_cf.items():
        if key in ['heartbeat_interval', 'login_wait_time']:
            ses.set_conf(key, int(val))
        elif key in ['reset_seqno']:
            ses.set_conf(key, bool(val))
        else:
            ses.set_conf(key, val)

    for key, val in app_cf.items():
        app.set_conf(key, val)
    
    if options.sender:
        ses.set_conf('sender_comp_id', options.sender)
    if options.target:
        ses.set_conf('target_comp_id', options.target)
    if options.resend:
        ses.set_conf('resend_mode', options.resend)
    if options.reset:
        ses.set_conf('reset_seqno', options.reset)
    if not ses.get_conf('heartbeat_interval'):
        ses.set_conf('heartbeat_interval', options.heartbeat)
    if not ses.get_conf('login_wait_time'):
        ses.set_conf('login_wait_time', 30)

    app.linkdown(ses)
    ses.linkup(app)
    # overload session login validator
    validator = LoginValidator(app, ses)
    ses.login_hook = validator.login_hook

    ses.start(netaddr)
    app.start()

    savelist = []
    if statepath:
        ses.state.restore(statepath)
        savelist = [(ses, statepath)]

    reaktor.run(savelist=savelist, exc_handler=validator.exchandler)