Ejemplo n.º 1
0
    def setUp(self):
        print "Setup!!!"
        from datetime import datetime

        for relpath in [ '../data', './data' ]:
            fp = os.path.abspath( relpath)
            if os.path.exists(fp):
                break
        print fp
        self.bp = BerkeleyPersister( fp, "SENDER","PHROMS", dt = datetime( 2009, 1, 11) )
        self.spec = parse_specification(version = "FIX.4.2")
        (self.inDb,self.outDb) = self.bp.getTodayPersister( )
        # data can arrive in arbitrary shapes and sizes so need
        # to ensure that a parser can cope with all the data ( even byte-at-a-time)
        print [ x.partition("=") for x in "a=b|".split("|") ]
        print [ x.partition("=") for x in "a=b|c".split("|") ]
        print [ x.partition("=") for x in "a=b|c=".split("|") ]
        print [ x.partition("=") for x in "a=b|c=d".split("|") ]

        print self.inDb.stat()

        # Build a big pyfix string
        c = self.inDb.cursor()
        self.megaString = ''
        messages = 0
        while True:
            i_s = c.next()
            if not i_s:
                break
            _, s = i_s
            self.megaString+= s
        print "Megastring is %s long" % len(self.megaString )
Ejemplo n.º 2
0
    def setUp(self):
        print "Setup!!!"
        from datetime import datetime

        for relpath in [ '../data', './data' ]:
            fp = os.path.abspath( relpath)
            if os.path.exists(fp):
                break
        print fp
        self.bp = BerkeleyPersister( fp, "SENDER","PHROMS", dt = datetime( 2009, 1, 11) )
        self.spec = parse_specification(version = "FIX.4.2")
        (self.inDb,self.outDb) = self.bp.getTodayPersister( )
        # data can arrive in arbitrary shapes and sizes so need
        # to ensure that a parser can cope with all the data ( even byte-at-a-time)
        print [ x.partition("=") for x in "a=b|".split("|") ]
Ejemplo n.º 3
0
    def setUp(self):
        self.fix = parse_specification(self.version)
        self.fp = SynchronousParser(self.fix)

        self.sendConfig = SessionConfig(
            'initiator',
            0,
            'localhost',
            'INITIATOR',
            'ACCEPTOR',
            os.path.join(tempfile.mktemp(), "sender"),  # Will be tempfile
            60,
            None)
        self.ds = Session(None, self.fix, self.sendConfig)
        major, minor = self.version.split('.')[1:]
        self.numVersion = int(major) * 10 + int(minor)
        print "NV = %s" % self.numVersion
Ejemplo n.º 4
0
 def setUp( self):
     self.fix = parse_specification( self.version )
     self.fp = SynchronousParser(self.fix)
     
     self.sendConfig = SessionConfig( 'initiator',
                                      0,
                                      'localhost',
                                      'INITIATOR',
                                      'ACCEPTOR',
                                      os.path.join( tempfile.mktemp(), "sender" ), # Will be tempfile
                                      60,
                                      None
                                      )
     self.ds = Session( None, self.fix, self.sendConfig)
     major, minor = self.version.split('.')[1:]
     self.numVersion = int(major) * 10 + int(minor)
     print "NV = %s" % self.numVersion 
Ejemplo n.º 5
0
import yaml

from pyfix.FIXProtocol import SessionManager, NormalMessageProcessing
from pyfix.FIXSpec import parse_specification
from pyfix.FIXConfig import makeConfig
from pyfix.util.randomOrders import flipOrder
from pyfix.FIXApplication import FIXApplication
from pyfix.FIXPerspective import FIXPerspective
from twisted.internet import reactor

fix = parse_specification(version="FIX.4.2")

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'))
Ejemplo n.º 6
0
from pyfix.FIXProtocol import InitiatorFIXProtocol, SessionManager
from pyfix.FIXSpec import parse_specification
from pyfix.FIXConfig import makeConfig


from datetime import datetime
from twisted.internet import reactor
import yaml

fix = parse_specification( "FIX.4.2" )
class SendingProtocol(InitiatorFIXProtocol):
    def __init__(self, *args, **kwargs):
        InitiatorFIXProtocol.__init__(self, *args, **kwargs)
        #self.dispatchMap[ self.pyfix.ExecutionReport ] = self.onExecution
        self.normal_message_processing.in_sequence_dict[ self.fix.ExecutionReport]  = self.onExecution

    def onExecution(self, msg, seq, dup):
        print "WOOHOO got an execution "
        msg.dump()

    def loggedOn(self):
        print "LOGGED ON!!!! - no gaps"
        if 1:
            for i in range(10):
                self.sendOrder()

    def onStateChange(self, old, newState ):
        print "My State change %s -> %s" % (old, newState)
        if newState == self.normal_message_processing:
            self.sendOrder()
        elif newState==self.logged_out_state:
Ejemplo n.º 7
0
from pyfix.FIXProtocol import InitiatingFIXProtocol, SessionManager
from pyfix.FIXSpec import parse_specification
from datetime import datetime

from pyfix.tx.fixConfig import NativeConfig
from twisted.internet import reactor
import yaml

fix = parse_specification("FIX.4.2")


class SendingProtocol(InitiatingFIXProtocol):
    def __init__(self, *args, **kwargs):
        InitiatingFIXProtocol.__init__(self, *args, **kwargs)
        #self.dispatchMap[ self.pyfix.ExecutionReport ] = self.onExecution
        self.normalMessageProcessing.inSequenceMap[
            self.fix.ExecutionReport] = self.onExecution

    def onExecution(self, msg, seq, dup):
        print "WOOHOO got an execution "
        msg.dump()

    def loggedOn(self):
        print "LOGGED ON!!!! - no gaps"
        if 1:
            for i in range(10):
                self.sendOrder()

    def onStateChange(self, old, newState):
        print "My State change %s -> %s" % (old, newState)
        if newState == self.normalMessageProcessing:
Ejemplo n.º 8
0
from pyfix.FIXSpec import parse_specification, BusinessReject
import unittest

from datetime import datetime 

fix = parse_specification( 'FIX.4.2')

#Noddy Change

class FieldTest( unittest.TestCase ):
    def __str__(self):
        return "%s %s" % ( unittest.TestCase.__str__(self), self.field.to_fix() )

    __repr__=__str__

    def __init__(self, *args, **kwargs):
        # TestCase docs says sholdn't mess with the signature.
        self.field = kwargs['field']
        del kwargs['field']
        unittest.TestCase.__init__(self, *args, **kwargs)
    
    def test_success(self):
        """Works"""
        self.field.validate( fix)

    def test_failure(self):
        self.assertRaises( BusinessReject, self.field.validate, fix)

shouldPass = [ fix.ClOrdID('wayhey' ),
               fix.OrderQty(100),
               fix.SendingTime( datetime.now() ),
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
from pyfix.FIXSpec import parse_specification, BusinessReject
import unittest

from datetime import datetime

fix = parse_specification('FIX.4.2')

#Noddy Change


class FieldTest(unittest.TestCase):
    def __str__(self):
        return "%s %s" % (unittest.TestCase.__str__(self), self.field.to_fix())

    __repr__ = __str__

    def __init__(self, *args, **kwargs):
        # TestCase docs says sholdn't mess with the signature.
        self.field = kwargs['field']
        del kwargs['field']
        unittest.TestCase.__init__(self, *args, **kwargs)

    def test_success(self):
        """Works"""
        self.field.validate(fix)

    def test_failure(self):
        self.assertRaises(BusinessReject, self.field.validate, fix)


shouldPass = [