I've gotten ZMQ to work in .py files but I want to use it in a cython class but have not figure out how to import the right library in to .pyx files. Example:
import zmq
from zmq.backend.cython.socket cimport Socket
from zmq.backend.cython.context import Context
cdef class MyClass:
cdef public str tick_port
cdef public Socket socket
cdef public Context context
def __cinit__(self,tick_port):
self.tick_port = tick_port
self.context = zmq.Context()
self.socket = self.context.socket(zmq.SUB)
self.socket.setsockopt(zmq.SUBSCRIBE, b"") # Note.
def StartData(self):
''' market data comes in here '''
self.socket.connect("tcp://127.0.0.1:" + str(self.tick_port))
while True:
tick_message = self.socket.recv_json()
print("Data: " + str(tick_message))
#self.OnTick(eval(tick_message))
how do you correctly declare and define various zmq variables within cython? so I still create context
and socket
objects like in python? Lots of newbie question but I couldn't find anything from googling "how to use zmq in cython".
for example when compiling the above I get error:
C attribute of type '<error>' cannot be accessed from pythong.
Thanks,