Exemple #1
0
def main(args):

    target = ('localhost', 2000)
    use_tls = False

    if args:
        r = urlparse.urlparse(args.pop(0))
        if r.netloc:
            addr, port = r.netloc.split(':')
            target = (addr, int(port))
            use_tls = r.scheme == 'tls'
        else:
            print "target address: [tls:]//<host>:<port>"
            sys.exit(1)

    logging.basicConfig(level=logging.DEBUG)

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

    process = ProcessApplication(reaktor, FixSink('sink.dat'), name='fixsink')
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    if use_tls:
        session.ssl_context(SSLServerContext())

    session.start(target)
    process.start()
    save_path = args[0] + '.state'
    reaktor.run([(session.state, save_path)])
Exemple #2
0
def main(args):

    target = ('localhost', 2000)
    use_tls = False

    if args:
        r = urlparse.urlparse(args.pop(0))
        if r.netloc:
            addr, port = r.netloc.split(':')
            target = (addr, int(port))
            use_tls = r.scheme == 'tls'
        else:
            print "target address: [tls:]//<host>:<port>"
            sys.exit(1)

    logging.basicConfig(level=logging.DEBUG)

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

    process = ProcessApplication(reaktor, FixSink('sink.dat'), name='fixsink')
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    if use_tls:
        session.ssl_context(SSLServerContext())

    session.start(target)
    process.start()
    save_path = args[0] + '.state'
    reaktor.run([(session.state, save_path)])
Exemple #3
0
def main(args):

    logging.basicConfig(level=logging.DEBUG)

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

    process = ProcessApplication(reaktor, FixSource("source.dat"), name="fixsource")
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    save_path = args[0] + ".state"
    session.state.restore(save_path)

    session.start(("localhost", 2000))
    process.start()
    reaktor.run([(session.state, save_path)])
Exemple #4
0
def main(args):

    logging.basicConfig(level=logging.DEBUG)

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

    process = ProcessApplication(reaktor, FixSource('source.dat'), name='fixsource')
    session = get_session(args, reaktor, protocol)

    process.linkdown(session)
    session.linkup(process)

    save_path = args[0] + '.state'
    session.state.restore(save_path)

    session.start(('localhost', 2000))
    process.start()
    reaktor.run([(session.state, save_path)])
Exemple #5
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)
Exemple #6
0
    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()
    ses.state.restore(save_path)
    reaktor.run(savelist=[(ses, save_path)], exc_handler=exchandler)


if __name__ == "__main__":
    main(sys.argv[1:])
Exemple #7
0
    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()
    ses.state.restore(save_path)
    reaktor.run(savelist=[(ses, save_path)], exc_handler=exchandler)


if __name__ == "__main__":
Exemple #8
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)