I put my file reference in: C:\Program Files\NinjaTrader 8\bin\NinjaTrader.Client.dll
However, I supose this reference does not work very well
Please I need to connect my program with NT8 in my laptop for my own use.
There is a update demo because this is from 2016-12-06.
Here my code in:
Microsoft Visual Studio Community 2022 (64 bits) - Current
Versión 17.6.5
Microsoft.Net Framework Version 4.8.04084
My code: (the same like demo by NT support)
using System;
using System.Windows;
using NinjaTrader.Client;
// set Built -> Cinfiguration Manager -> Active solution Platform -> X64
// Reference -> C:\Program Files\NinjaTrader 8\bin\NinjaTrader.Client.dll
// NT8
namespace NT8Client
{
public partial class MainWindow : Window
{
private Client myClient = new Client();
private bool shuttingDown = false;
private System.Timers.Timer timer;
public MainWindow()
{
InitializeComponent();
Closed += MainWindow_Closed;
Loaded += MainWindow_Loaded;
}
private void MainWindow_Closed(object sender, EventArgs e)
{
if (shuttingDown)
return;
myClient.UnsubscribeMarketData("ES");
timer.Enabled = false;
shuttingDown = true;
Environment.Exit(0);
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
int connect = myClient.Connected(1);
Console.WriteLine(string.Format("{0} | Connected to NT8: {1}", DateTime.Now, connect.ToString()));
myClient.SubscribeMarketData("ES");
timer = new System.Timers.Timer()
{
Interval = 1000
};
timer.Elapsed += TimerElapsed;
timer.Enabled = true;
}
public void TimerElapsed(object sender, System.Timers.ElapsedEventArgs args)
{
if (myClient == null)
return;
double lastPrice = myClient.MarketData("ES", 0);
Console.WriteLine(string.Format("{0} | Last {1}", DateTime.Now, lastPrice));
}
}
}
Errors:
Comment