Using ZeroMQ from within Ninjatrader (assistance bitte)

Discussion in 'App Development' started by Jack_Larkin, May 10, 2016.

  1. Having a dilly of a pickle trying to use ZeroMQ from within a Ninjatrader script/indicator. I'm a python programmer and have only just started dabbling with C# and NT in general.

    Where I've gotten so far:

    - Taken the C# release/bindings for ZeroMQ, and placed the approperate DLL files in the NT's bin/Custom folder. This includes the main ZeroMQ.DLL file and two sub directories as part of the release folder within the download from this link:
    https://github.com/zeromq/clrzmq4/releases

    - Added the ZeroMQ.DLL file as a reference within Ninjatrader.

    - Included a "using ZeroMQ;" line. This is accepted without error.

    - Wrote in some C# ZeroMQ code into an indicator, which saves and compiles without issue. That is to say, NT seems to get the class references and namespace from the DLL file just fine.

    - Added said indicator onto a chart, which starts but fails to plot anything. In NT's output window I get this error:

    """Failed to call method 'Initialize' for indicator 'MyCustomIndicator': Could not load file or assembly 'ZeroMQ, Version=4.1.0.21, Culture=neutral, PublicKeyToken=4a9630883fd6c563' or one of its dependencies. The system cannot find the file specified."""

    So it appears to be failing on a dependency somewhere outside the initial DLL import.

    Has anyone done this before? Where am I going wrong?
     
  2. a) Are the two sub directories your: amd64 and i386 - both containing libzmq.dll and libsodium.dll?

    b) Are you using NT7 or NT8? clrzmq4 uses .Net 4 and NT7 is .Net 3 framework. So you want to be using NT8.

    I have done this before but for whatever reason went with the Microsoft Message Queue for pushing data to my executable from NT7 - the executable uses Zmq load balancing pattern for distributing level 1 and level 2 datafeeds into analysis and trade management threads. I didn't find using MSMQ compromised the efficiency of zmq.
     
  3. Thanks for the reply.

    a) Yes, both do.

    b) NT7, I haven't tried NT8 yet for this. What you're saying makes sense.. ideally I'd like to use NT7 though, but if it works cleanly to NT8 I suppose the NT related code conversion would be trivial.

    I wanted to use ZeroMQ over MMQ given all my existing infrastructure uses ZeroMQ so integration would have been simple. Using anything else would require some extra glue code or translation service in between.

    I'll try out NT8, and if that proves the problem, then maybe try finding or building ZeroMQ's C# bindings against .NET 3.5.. or just biting the bullet and converting everything over to NT8 (which might be best.)
     
  4. There is a Net 3 zmq binding though it's not updated anymore:

    https://www.nuget.org/packages/clrzmq/3.0.0-rc1

    Also don't forget NetMq - the native c# implementation of zmq, could be easier fault finding.

    Definitely won't be able to use clrzmq4 in NT7. NT8 is stable nowadays, and way better performance for custom indicators. They don't all run on the same thread nowadays.

    Good luck
     
  5. Thanks a bunch for pointing me in the right direction.

    I cut over to NT8, and some progress was made.

    The only gotcha' so far is the libzmq.dll library looking in the user AppData Temp directory for itself and not finding it.. so probably related to how NT8 compiles and creates file references. I just tossed a copy into that folder, restarted NT8, and it got past the error. Really funny how that works. . . probably related to how you need to set a copy or replace on the resource within Visual Studio but have no such options within NT's environment.

    Thankfully the above was easy to sort out after I put in a try/catch and dumped the exception to NT's output window.
     
    grahamglover likes this.
  6. Got it working as expected on NT8...

    Think I'll just put the effort into converting what few NT7 specific things I had into NT8 as it seems better overall anyway (NT7 was a headache.)

    Really the only gotcha' was that file that wasn't copied to the temp folder automatically.. other than that it works as expected.
     
  7. Good to hear Jack! Would be interested to hear about any throughput tests you do with market data. The only disappointment with zmq is the lack of interprocess messaging on windows - but throughput has been good enough for me using TCP sockets.
     
  8. conduit

    conduit

    I recommend you take a look at RedisDB, in case you are looking for blazing fast pub/sub. Redis is generally a kv-db but it also offers pub-sub, in memory and across app domains, even between different machines.