Hi Guys, I am trying to understand the basic algorithm used for implementing automated trading systems. I have heard that it is best implemented as producer/consumer pattern but I am not able to get it right in code. As I understand, continuous stream of data acts as producer. My doubts are: 1. How to implement consumer? 2. Is it going to create a new consumer thread everytime there is a tick update received? 3. Producer thread never blocks as it is real time data. What algo to follow so that code is synchronized? If someone can give me basic steps of algorithm/sudocode then it will be great. Cheers, Mich
something like this. but you dont need it to start; you can just do it all single threaded and use callbacks Code: class Producer() Producer(queue) this.queue=queue void produce(msg) this.queue.put(msg) class Consumer() Consumer(queue) this.queue=queue void consume() while true msg=this.queue.get() q=Queue() p=Producer(queue=q) c=Consumer(queue=q) t=thread(c).start() t.consume() p.produce("message")
1. Look at zeromq or asio. 2. Nope, because that would be crazy slow. 3. ??? To echo what rosy2 said, I would just stick to single threaded callbacks until you have some idea of what you're doing. Speed sensitive stuff can be broken into separate threads later.