예제 #1
0
파일: sinks.py 프로젝트: smandy/pyfix
class Receiver(FIXApplication):
    def __init__(self):
        FIXApplication.__init__(self, fix)
        self.dispatch_dict = {fix.OrderSingle: self.on_order}

    def on_order(self, protocol, order, seq, dup):
        assert order.__class__ == fix.OrderSingle
        #msg.dump()
        f = fix
        if self.state.__class__ == NormalMessageProcessing:
            reply = flipOrder(self.fix, order)
            assert self.protocol is not None
            assert self.session is not None
            strMsg = self.session.compile_message(reply)
            print ">>>MYEXEC %s %s" % (reply, strMsg)
            protocol.transport.write(strMsg)


config = yaml.load(open('./sinks.yaml', 'r'))

if __name__ == '__main__':
    receiverConfig = makeConfig(config)
    for x in receiverConfig:
        x.app = Receiver()

    sm = SessionManager(fix, receiverConfig)
    fixPerspective = FIXPerspective(sm, description="Multiplexer:Sinks")
    print "About to listen"
    sm.getConnected()
    reactor.run()
예제 #2
0
        strMsg = self.session.compile_message(myOrder)
        msgSeqNum = myOrder.get_header_field_value(self.fix.MsgSeqNum)
        print "APP>> %s %s %s" % (msgSeqNum, myOrder, strMsg)
        self.transport.write(strMsg)

    def sendOrder(self):
        f = self.fix
        assert self.normalMessageProcessing, "Can't send an order in abnormal conditions!!!"
        myOrder = f.OrderSingle(fields=[
            f.ClOrdID("MyOrder"),
            f.HandlInst('3'),
            f.Symbol('CSCO'), f.Side.BUY,
            f.OrderQty(100),
            f.TransactTime(datetime.now()), f.OrdType.MARKET
        ])
        strMsg = self.session.compile_message(myOrder)
        msgSeqNum = myOrder.get_header_field_value(self.fix.MsgSeqNum)
        print "APP>> %s %s %s" % (msgSeqNum, myOrder, strMsg)
        self.transport.write(strMsg)


config = yaml.load(open('../config/sender.yaml', 'r'))
senderConfig = NativeConfig(config)

if __name__ == '__main__':
    sessionManager = SessionManager(fix,
                                    senderConfig,
                                    initiatorProtocol=SendingProtocol)
    sessionManager.getConnected()
    reactor.run()
예제 #3
0
파일: sender.py 프로젝트: smandy/pyfix
        newFields = [ fieldDict.get( x.__class__, x ) for x in fields ]
        myOrder = f.OrderSingle( fields = newFields )
        strMsg = self.session.compile_message( myOrder )
        msgSeqNum = myOrder.get_header_field_value( self.fix.MsgSeqNum)
        print "APP>> %s %s %s" % (msgSeqNum, myOrder, strMsg)
        self.transport.write( strMsg )

    def sendOrder(self):
        f = self.fix
        assert self.normal_message_processing, "Can't send an order in abnormal conditions!!!"
        myOrder = f.OrderSingle(fields = [ f.ClOrdID( "MyOrder" ),
                                           f.HandlInst('3'),
                                           f.Symbol('CSCO'),
                                           f.Side.BUY,
                                           f.OrderQty(100),
                                           f.TransactTime( datetime.now() ),
                                           f.OrdType.MARKET]
                                )
        strMsg = self.session.compile_message( myOrder )
        msgSeqNum = myOrder.get_header_field_value( self.fix.MsgSeqNum)
        print "APP>> %s %s %s" % (msgSeqNum, myOrder, strMsg)
        self.transport.write( strMsg )

config = yaml.load( open( '../config/sender.yaml','r') )
senderConfig   = makeConfig( config )

if __name__=='__main__':
    sessionManager = SessionManager( fix, senderConfig, initiatorProtocol = SendingProtocol )
    sessionManager.getConnected()
    reactor.run()
예제 #4
0
파일: ftpBridge.py 프로젝트: smandy/pyfix
    def __init__(self, app):
        self.app = app
        self.avatar = None

    def requestAvatar(self, avatar_id, mind, *interfaces):
        for iface in interfaces:
            if iface is IFTPShell:
                if avatar_id is ANONYMOUS:
                    avatar = FTPAnonymousShell(self.anonymousRoot)
                else:
                    avatar = MyFTPShell(self.app)
                    self.avatar = avatar
                    print "Avatar is MyFTPShell %s" % avatar
                return IFTPShell, avatar, getattr(avatar, 'logout', lambda: None)
        raise NotImplementedError("Only IFTPShell interface is supported by this realm")


if __name__ == '__main__':
    cfg = config['manhole']
    senderConfig = makeConfig(yaml.load(open('../config/sender.yaml', 'r').read()))
    sm = SessionManager(fix, senderConfig, initiatorProtocol=SendingProtocol)
    s = sm.sessions[0]
    p = Portal(MyFTPRealm(s),
               [AllowAnonymousAccess(), InMemoryUsernamePasswordDatabaseDontUse(**config['ftpServer']['passwords'])])
    f = FTPFactory(p)
    reactor.listenTCP(cfg['listenPort'], getManholeFactory(globals(), passwords=cfg['passwords']))
    reactor.listenTCP(2011, f)
    sm.getConnected()

    reactor.run()