ZeroMQ

Posted By: Grat

ZeroMQ - 06/18/19 05:41

Hi,

I create interface for ZeroMQ. Status is early alpha

install:
a) download libzmq.dll and put in zorro folder
b) install zorroZmq.h into include
c) zmq_client.c into Strategy

[Linked Image]

test server in python:
Code
import time
import zmq

context = zmq.Context()
socket = context.socket(zmq.REP)
socket.bind("tcp://*:5555")

while True:
    #  Wait for next request from client
    message = socket.recv()
    print("Received request: %s" % message)

    #  Do some 'work'
    time.sleep(1)

    #  Send reply back to client
    socket.send(b"World")


Attached File
libzmq.zip  (136 downloads)
Attached File
zorroZmq.h  (208 downloads)
Attached File
zmq_client.c  (226 downloads)
Attached picture Screenshot_96.png
Posted By: ricky_k

Re: ZeroMQ - 09/08/19 08:36

Grat,

Nice work with the ZMQ interface.

Wondering what kinds of applications you'd use this for (or already have) besides a custom trading API?

ricky
Posted By: felixfx

Re: ZeroMQ - 10/23/19 20:04

wow, that's great. If you don't mind my asking, what is your reasoning for using ZMQ via Zorro?
I'm just getting into Zorro and Lite-C so I'm wondering if you've hit some upper limits of its capabilities.

Don't get me wrong, I think its great you can connect Jupyter Notebook with Zorro now.

If you didn't know, there is also a ZMQ EA created for MT4 that will bind MT4 and Python:
Don't get me wrong, I think its great there is an option via Zorro now.
Posted By: danatrader

Re: ZeroMQ - 11/09/20 11:16

I tried, I receive "Can't open libzmq.dll" and "Error 019: Empty function called!"
Posted By: soulman3

Re: ZeroMQ - 09/24/23 16:17

Do you mind sharing the source for the libzmq.dll? I also got the error that danatrader did... If we get this working it would be a great way to interface to python instead of the using files.
Posted By: TipmyPip

Re: ZeroMQ - 12/13/23 12:27

Wow, that's great, Users can always find more complex ideas for Python exchange data with Zorro Trader, and develop very efficient code to trade dynamic strategies:

Code
#include <litec.h>
#include <trade.h>
#include <zmq.h>

// Declare ZeroMQ functions
void* zmq_ctx_new();
void* zmq_socket(void* context, int type);
int zmq_connect(void* socket, const char* endpoint);
int zmq_send(void* socket, const char* buf, int len, int flags);
int zmq_recv(void* socket, char* buf, int len, int flags);

void run() {
    // Initialize ZeroMQ context and socket
    void* context = zmq_ctx_new();
    void* requestor = zmq_socket(context, ZMQ_REQ);
    zmq_connect(requestor, "tcp://localhost:5555");

    while(algo(loop("EUR/USD", "USD/JPY"))) {
        // Prepare data to send (example: last 10 close prices)
        var data[10];
        int i;
        for(i = 0; i < 10; i++)
            data[i] = priceClose(i);

        // Send data to Python server
        zmq_send(requestor, (const char*)data, sizeof(data), 0);

        // Receive prediction from Python server
        char buffer[256];
        zmq_recv(requestor, buffer, sizeof(buffer), 0);

        // Process the received prediction for trading decisions
        // ...
    }

    // Close ZeroMQ socket and context
    // ...
}
© 2024 lite-C Forums