Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding nuget packages to NT8?

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

    Adding nuget packages to NT8?

    Outside of NT 8.1.4.1, I've created a simple hello-world grpc client and server. Back in NT8, I created a script whose only goal is to try and connect to the gRPC and do nothing else, but it keeps failing to load my script with errors described below.

    First, there is a packages.config inside bin\Custom that includes the following contents:

    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <packages>
      <package id="Google.Protobuf" version="3.29.3" targetFramework="net48" />
      <package id="Grpc.Core.Api" version="2.67.0" targetFramework="net48" />
      <package id="Grpc.Net.Client" version="2.67.0" targetFramework="net48" />
      <package id="Grpc.Tools" version="2.69.0" targetFramework="net48" />
    </packages>​
    When I use nuget.exe to install these, it places all of the folders locally in bin\Custom.

    Then I went into NinjaScript editor and added references to the Grpc.Core.Api and Grpc.Net.Client files, which looks like this:

    Click image for larger version  Name:	Screenshot 2025-01-29 005643.png Views:	0 Size:	19.5 KB ID:	1332731

    Then I have code as simple as this indicator code, just to see if I can connect to my gRPC server.

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    using Grpc.Net.Client;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class gRPCTestClient : Indicator
        {
            private static GrpcChannel channel;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                        = @"This code does nothing other than connect to a gRPC server and send a message to get an echoed response.";
                    Name                            = "gRPCTestClient";
                    Calculate                        = Calculate.OnBarClose;
                    IsOverlay                        = false;
                    DisplayInDataBox                = true;
                    DrawOnPricePanel                = true;
                    DrawHorizontalGridLines            = true;
                    DrawVerticalGridLines            = true;
                    PaintPriceMarkers                = true;
                    ScaleJustification                = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive        = true;
                }
                else if (State == State.Configure)
                {
                    channel = GrpcChannel.ForAddress("https://localhost:7257");
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom indicator logic here.
            }
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private gRPCTestClient[] cachegRPCTestClient;
            public gRPCTestClient gRPCTestClient()
            {
                return gRPCTestClient(Input);
            }
    
            public gRPCTestClient gRPCTestClient(ISeries<double> input)
            {
                if (cachegRPCTestClient != null)
                    for (int idx = 0; idx < cachegRPCTestClient.Length; idx++)
                        if (cachegRPCTestClient[idx] != null &&  cachegRPCTestClient[idx].EqualsInput(input))
                            return cachegRPCTestClient[idx];
                return CacheIndicator<gRPCTestClient>(new gRPCTestClient(), input, ref cachegRPCTestClient);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.gRPCTestClient gRPCTestClient()
            {
                return indicator.gRPCTestClient(Input);
            }
    
            public Indicators.gRPCTestClient gRPCTestClient(ISeries<double> input )
            {
                return indicator.gRPCTestClient(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.gRPCTestClient gRPCTestClient()
            {
                return indicator.gRPCTestClient(Input);
            }
    
            public Indicators.gRPCTestClient gRPCTestClient(ISeries<double> input )
            {
                return indicator.gRPCTestClient(input);
            }
        }
    }
    
    #endregion
    When I try to add it as an indicator, well, for one, it just shows a row without a name. When I try to add it to a chart anyway, I get messages like these in the NT8 log window:

    Indicator 'gRPCTestClient': Error on calling 'OnStateChange' method: Could not load file or assembly 'Grpc.Net.Client Version=2.0.0.0 Culture=neutral PublicKeyToken=d754f35622e28bad' or one of its dependencies. The system cannot find the file specified.​
    which ultimately leads to a total failure that throws an exception box with the message:

    Unhandled exception: Non-static method requires a target.​
    If someone has a solution, that would be so awesome! NT support, do you have any answers?
    Last edited by grimwm00; 01-29-2025, 02:01 AM.

    #2
    Do not add references to DLLs located in subfolders under bin/Custom.
    All DLLs should be in bin/Custom, subfolders do not seem to be supported.

    My advice?
    NinjaTrader and nuget do not mix well.
    Extract/build/install all nuget packages somewhere outside of NinjaTrader folders.
    Copy desired DLLs to bin/Custom.

    Moral of story:
    When adding references using NinjaScript editor, try selecting only
    DLL files that have already been relocated to bin/Custom.

    If after this, things still seem wonky, try exiting/restarting NinjaTrader.

    Good luck!

    Last edited by bltdavid; 01-29-2025, 04:54 AM.

    Comment


      #3
      Good reading here and here.
      Last edited by bltdavid; 01-29-2025, 10:13 PM.

      Comment


        #4
        bltdavid that is amazing. I would have never figured out that the DLLs had to exist in the
        Code:
        bin\Custom
        directory itself.

        I was able to get grpc libs installed and referenced, but I cannot find a version that actually works with NT8. All of them seem to require some other library that ends up not being compatible, and I can't seem to figure out a set of dependencies that would work. Do you know of any?

        Or, more pertinently, do you know of any patterns to enable 2-way comms between NT8 and a network-connected model I'm planning to make? I've considered a REST API, which I hate, but I'm sure I could get something to work with that. I also know how to use tech like redis and kafka, but those already sound like they'd be too advanced to import the DLLs into NT8 properly.

        Comment


          #5
          Originally posted by grimwm00 View Post
          Do you know of any?
          Sorry, no.

          Originally posted by grimwm00 View Post
          Or, more pertinently, do you know of any patterns to enable 2-way comms between NT8 and a network-connected model I'm planning to make?
          My needs have not been that elaborate.

          I have used sockets in NT8 to great effect with a relatively simple client-server
          model using a text-based home-grown protocol. But that's about it.




          Comment


            #6
            bltdavid I didn't think about sockets. I suppose I could try something like that. Maybe I can at least use protobuf to help prevent me from having to design the structure itself, and then I can do a 3-layer set up: NT8 as a client, middleware (server to NT8 and client to the model), server (the model I really want to talk to). At the least, you have given me some ideas.

            Comment


              #7
              grimwm00 i got your message. i could not make it work due to dependency on the additional libraries.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              557 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X