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()
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()
dd.latencies.append(latency) if timeNow - dd.startTime >= 10.: dd._endTime = timeNow if not self.delays: self.stopped = True reactor.stop() return self.delay = self.delays.pop(0) print "Setting delay to %s" % self.delay except: print "Duff test request id %s" % request traceback.print_exc() config = yaml.load(open('../config/sender.yaml', 'r')) senderConfig = makeConfig(config) for x in senderConfig: x.app = Sender(fix) app = x.app if __name__ == '__main__': sessionManager = SessionManager(fix, senderConfig) sessionManager.getConnected() reactor.run() from pylab import plot, show data = [] for d, x in app.latencies.items(): if not x._endTime: x._endTime = time.time() timeTaken = x.endTime() - x.startTime messages = x.count
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()
import yaml from pyfix.FIXProtocol import SessionManager from pyfix.FIXSpec import parse_specification from pyfix.FIXConfig import makeConfig fix = parse_specification(version="FIX.4.2") config = yaml.load(open('../config/receiver.yaml', 'r')) if __name__ == '__main__': receiverConfig = makeConfig(config) sm = SessionManager(fix, receiverConfig) from twisted.internet import reactor print "About to listen" sm.getConnected() reactor.run()
def on_recovery_done(self): "%s recovered %s executions, %s orders" % (self.session.target, self.execs, self.orders) def onRecoveredExecution(self, msg): self.execs += 1 def onRecoveredOrder(self, msg): self.orders += 1 def onExecution(self, protocol, msg, seq, possdup): self.mux.on_execution(self, msg) if __name__ == '__main__': config = yaml.load(open('./mux.yaml', 'r')) muxConfig = makeConfig(config) sessionManager = SessionManager(fix, muxConfig) if 0: # Vanilla multiplexer multiplexer = Multiplexer(sessionManager) else: # 'Perspective' version can be monitored by examples/pyglex/muxGui fixPerspective = FIXPerspective(sessionManager, description="Multiplexer Example - MUX") multiplexer = NoiseMux(sessionManager, fixPerspective) for s in sessionManager.sessions: s.app.recover() sessionManager.getConnected() reactor.run()