Esempio n. 1
0
 def eBindToReqRep(self, iDir):
     """
     We bind on our Metatrader end, and connect from the scripts.
     """
     assert iDir in [zmq.REP, zmq.REQ]
     if self.oReqRepSocket is None:
         oReqRepSocket = self.oContext.socket(iDir)
         assert oReqRepSocket, "eBindToReqRep: oReqRepSocket is null"
         assert self.iReqRepPort, "eBindToReqRep: iReqRepPort is null"
         sUrl = 'tcp://%s:%d' % (self.sHostAddress, self.iReqRepPort,)
         vInfo("eBindToReqRep: Binding to %d: %s" % (iDir, sUrl,))
         sys.stdout.flush()
         oReqRepSocket.bind(sUrl)
         self.oReqRepSocket = oReqRepSocket
Esempio n. 2
0
 def eConnectToReqRep(self, iDir):
     """
     We bind on the Metatrader end, and connect from the scripts.
     """
     if self.oReqRepSocket is None:
         assert iDir in [zmq.REP, zmq.REQ], \
                "iDir not in [zmq.REP, zmq.REQ]: " +str(iDir)
         oReqRepSocket = self.oContext.socket(iDir)
         assert oReqRepSocket, "eConnectToReqRep: oReqRepSocket is null"
         assert self.iReqRepPort, "eConnectToReqRep: iReqRepPort is null"
         sUrl = 'tcp://%s:%d' % (self.sHostAddress, self.iReqRepPort,)
         vInfo("eConnectToReqRep: Connecting to %d: %s" % (iDir, sUrl,))
         sys.stdout.flush()
         oReqRepSocket.connect(sUrl)
         self.oReqRepSocket = oReqRepSocket
     return ""
Esempio n. 3
0
 def eBindToSubPub(self, iDir=zmq.PUB):
     """
     We bind on this Metatrader end, and connect from the scripts.
     This is called by Metatrader.
     """
     if self.oSubPubSocket is None:
         assert iDir in [zmq.PUB, zmq.SUB]
         oSubPubSocket = self.oContext.socket(iDir)
         assert oSubPubSocket, "eBindToSub: oSubPubSocket is null"
         assert self.iSubPubPort, "eBindToSub: iSubPubPort is null"
         sUrl = 'tcp://%s:%d' % (self.sHostAddress, self.iSubPubPort,)
         vInfo("eBindToSub: Binding to SUB " +sUrl)
         sys.stdout.flush()
         oSubPubSocket.bind(sUrl)
         time.sleep(0.1)
         self.oSubPubSocket = oSubPubSocket
Esempio n. 4
0
 def eBindToSubPub(self, iDir=zmq.PUB):
     """
     We bind on this Metatrader end, and connect from the scripts.
     This is called by Metatrader.
     """
     if self.oSubPubSocket is None:
         assert iDir in [zmq.PUB, zmq.SUB]
         oSubPubSocket = self.oContext.socket(iDir)
         assert oSubPubSocket, "eBindToSub: oSubPubSocket is null"
         assert self.iSubPubPort, "eBindToSub: iSubPubPort is null"
         sUrl = 'tcp://%s:%d' % (
             self.sHostAddress,
             self.iSubPubPort,
         )
         vInfo("eBindToSub: Binding to SUB " + sUrl)
         sys.stdout.flush()
         oSubPubSocket.bind(sUrl)
         time.sleep(0.1)
         self.oSubPubSocket = oSubPubSocket
Esempio n. 5
0
 def bCloseContextSockets(self):
     """
     same
     """
     if self.oReqRepSocket:
         self.oReqRepSocket.setsockopt(zmq.LINGER, 0)
         time.sleep(0.1)
         self.oReqRepSocket.close()
     if self.oSubPubSocket:
         self.oSubPubSocket.setsockopt(zmq.LINGER, 0)
         time.sleep(0.1)
         self.oSubPubSocket.close()
     if self.iDebugLevel >= 1:
         vInfo("destroying the context")
     sys.stdout.flush()
     time.sleep(0.1)
     self.oContext.destroy()
     self.oContext = None
     return True
Esempio n. 6
0
 def bCloseContextSockets(self):
     """
     same
     """
     if self.oReqRepSocket:
         self.oReqRepSocket.setsockopt(zmq.LINGER, 0)
         time.sleep(0.1)
         self.oReqRepSocket.close()
     if self.oSubPubSocket:
         self.oSubPubSocket.setsockopt(zmq.LINGER, 0)
         time.sleep(0.1)
         self.oSubPubSocket.close()
     if self.iDebugLevel >= 1:
         vInfo("destroying the context")
     sys.stdout.flush()
     time.sleep(0.1)
     self.oContext.destroy()
     self.oContext = None
     return True
Esempio n. 7
0
 def eBindToReqRep(self, iDir):
     """
     We bind on our Metatrader end, and connect from the scripts.
     """
     assert iDir in [zmq.REP, zmq.REQ]
     if self.oReqRepSocket is None:
         oReqRepSocket = self.oContext.socket(iDir)
         assert oReqRepSocket, "eBindToReqRep: oReqRepSocket is null"
         assert self.iReqRepPort, "eBindToReqRep: iReqRepPort is null"
         sUrl = 'tcp://%s:%d' % (
             self.sHostAddress,
             self.iReqRepPort,
         )
         vInfo("eBindToReqRep: Binding to %d: %s" % (
             iDir,
             sUrl,
         ))
         sys.stdout.flush()
         oReqRepSocket.bind(sUrl)
         self.oReqRepSocket = oReqRepSocket
Esempio n. 8
0
 def eConnectToReqRep(self, iDir):
     """
     We bind on the Metatrader end, and connect from the scripts.
     """
     if self.oReqRepSocket is None:
         assert iDir in [zmq.REP, zmq.REQ], \
                "iDir not in [zmq.REP, zmq.REQ]: " +str(iDir)
         oReqRepSocket = self.oContext.socket(iDir)
         assert oReqRepSocket, "eConnectToReqRep: oReqRepSocket is null"
         assert self.iReqRepPort, "eConnectToReqRep: iReqRepPort is null"
         sUrl = 'tcp://%s:%d' % (
             self.sHostAddress,
             self.iReqRepPort,
         )
         vInfo("eConnectToReqRep: Connecting to %d: %s" % (
             iDir,
             sUrl,
         ))
         sys.stdout.flush()
         oReqRepSocket.connect(sUrl)
         self.oReqRepSocket = oReqRepSocket
     return ""
Esempio n. 9
0
    def eConnectToSubPub(self, lTopics, iDir=zmq.SUB):
        """
        We bind on this Metatrader end, and connect from the scripts.
        This is called by the scripts.
        """

        if self.oSubPubSocket is None:
            assert iDir in [zmq.PUB, zmq.SUB], \
                   "iDir not in [zmq.PUB, zmq.SUB]: " +str(iDir)
            oSubPubSocket = self.oContext.socket(iDir)
            sUrl = "tcp://" +self.sHostAddress +":" +str(self.iSubPubPort)
            oSubPubSocket.connect(sUrl)
            self.oSubPubSocket = oSubPubSocket
            if iDir == zmq.SUB:
                if self.iDebugLevel >= 1:
                    vInfo("Subscribing to: " + sUrl +" with topics " +repr(lTopics))
                for sElt in lTopics:
                    self.oSubPubSocket.setsockopt(zmq.SUBSCRIBE, sElt)
            else:
                if self.iDebugLevel >= 1:
                    vInfo("Publishing to: " + sUrl)

        return ""
Esempio n. 10
0
    def eConnectToSubPub(self, lTopics, iDir=zmq.SUB):
        """
        We bind on this Metatrader end, and connect from the scripts.
        This is called by the scripts.
        """

        if self.oSubPubSocket is None:
            assert iDir in [zmq.PUB, zmq.SUB], \
                   "iDir not in [zmq.PUB, zmq.SUB]: " +str(iDir)
            oSubPubSocket = self.oContext.socket(iDir)
            sUrl = "tcp://" + self.sHostAddress + ":" + str(self.iSubPubPort)
            oSubPubSocket.connect(sUrl)
            self.oSubPubSocket = oSubPubSocket
            if iDir == zmq.SUB:
                if self.iDebugLevel >= 1:
                    vInfo("Subscribing to: " + sUrl + " with topics " +
                          repr(lTopics))
                for sElt in lTopics:
                    self.oSubPubSocket.setsockopt(zmq.SUBSCRIBE, sElt)
            else:
                if self.iDebugLevel >= 1:
                    vInfo("Publishing to: " + sUrl)

        return ""