Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How can I make socket calls from within NinjaScript ?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How can I make socket calls from within NinjaScript ?

    Hello,

    I understand that NinjaScript can communicate with third party platforms via the Automated Trading DLL interface, but the interface implementation is insufficient to support our purpose. Hence, I would like to find out if we can implement regular SOCKET calls within NinjaScript (it is C# after all) and make connections with our servers that way? Is there any restriction or do you foresee any problem (for example port range to avoid) implementing socket calls within NinjaScript? Thanks in advanced.

    Bill

    #2
    Originally posted by billythekid72 View Post
    if we can implement regular SOCKET calls within NinjaScript (it is C# after all) and make connections with our servers that way?
    Of course, no issues.

    Naturally, from NT support's point of view, this is unsupported C# code.

    But "unsupported" only means "we don't answer questions on that" -- but you
    can certainly achieve anything your skills allow.

    Originally posted by billythekid72 View Post
    Is there any restriction or do you foresee any problem (for example port range to avoid) implementing socket calls within NinjaScript?
    Port ranges to use (or to avoid) will have very little to do with NinjaTrader, but
    check the log files and you'll see server names followed by a slash followed
    by (presumably) port numbers.

    But you don't intend your socket code to be a server, do you?
    I mean, as a client, there is little worry. IIRC, port numbers are dictated by the
    server, so I presume you'll be connecting to your server using whatever port
    numbers it has already defined.

    You should think in terms of your code in your Indicator/Strategy plugin being the
    client in the TCP/IP client-server model. However ...

    If you're gonna be writing server side code, then probably best to use an Addon.
    For ex, a network aware Trade Copier would mean the Master makes the trades
    and notifies the Slaves, but the Slaves could be running on separate machines
    inside an Addon that is effectively a TCP server, waiting for a socket connection
    from the Master to be told what trades to take. In this case, the Master's Addon
    is the client, connecting to each Slave Addon, which acts like a server. (In this
    example, you'd probably want the Master client to establish a connection to each
    Slave server, and cache/reuse those connections for as long as possible -- I mean,
    repeatedly connecting to a Slave server for every order would create needless
    delays on the Slave, so best to do that once and just keep reusing the same
    connection over and over -- unless, perhaps, you make the Slave server use a
    RESTful API.)

    Probably wise to consider using a separate threads, and/or since NT8 has advanced
    into .NET 4.5 and beyond, you should seriously consider asynchronous sockets,
    see here and here for examples.

    I recommend you study Wireshark, in fact, become an expert user.
    Remember, from point of view of NinjaTrader, everything you're about to do is
    undocumented, so you'll need a detective mindset and forensic tools to help you.

    And, as always, Google is your friend.

    Sounds fun.
    Good luck!


    Comment


      #3
      Thank you, you have addressed my concerns. Thanks for answering on a Sunday afternoon, cheers!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by TheMarlin801, 10-13-2020, 01:40 AM
      21 responses
      3,915 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by timmbbo, 07-05-2023, 10:21 PM
      3 responses
      151 views
      0 likes
      Last Post grayfrog  
      Started by Lumbeezl, 01-11-2022, 06:50 PM
      30 responses
      808 views
      1 like
      Last Post grayfrog  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      3 responses
      11 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by Johnny Santiago, 10-11-2019, 09:21 AM
      95 responses
      6,194 views
      0 likes
      Last Post xiinteractive  
      Working...
      X