First, there is a packages.config inside bin\Custom that includes the following contents:
<?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>
Then I went into NinjaScript editor and added references to the Grpc.Core.Api and Grpc.Net.Client files, which looks like this:
Then I have code as simple as this indicator code, just to see if I can connect to my gRPC server.
#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

Comment