NexusFi: Find Your Edge


Home Menu

 





Console app for Ninja ATI


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one MXASJ with 5 posts (26 thanks)
    2. looks_two timmyb with 2 posts (0 thanks)
    3. looks_3 Big Mike with 1 posts (0 thanks)
    4. looks_4 abdunbar with 1 posts (0 thanks)
    1. trending_up 8,291 views
    2. thumb_up 26 thanks given
    3. group 13 followers
    1. forum 12 posts
    2. attach_file 3 attachments




 
Search this Thread

Console app for Ninja ATI

  #1 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

I wrote this small console application in C# to help a guy in another forum, but thought some users here might find it interesting. It is pretty basic and just gets the last price on ES 12-10 before shutting down. It uses the ATI interface to Ninja.

You can compile it as an exe or run it in your IDE's debug mode to check it out.

If you are really bored you can turn it into a WinForms or WPF app and post it back .

 
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using NinjaTrader.Client;
namespace NTConnectTest
{
classProgram
{
staticvoid Main(string[] args)
{
string inst = "ES 12-10";
string input1;
string input2;
double last = 0;
int connStatus;
bool getData = false;
int myCounter = 0;
 
NinjaTrader.Client.Client NTClient = new NinjaTrader.Client.Client();
Console.WriteLine("Connect to Ninja Trader? y/n");
input1 = Console.ReadLine();
switch (input1)
{
case"y":
getData = true;
NTClient.SubscribeMarketData(inst);
break;
case"n":
getData = false;
Console.WriteLine("Ok. Bye. Press <ENTER> to terminate program...", input1);
input2 = Console.ReadLine();
break;
 
default:
getData = false;
Console.WriteLine("ERROR: Your input {0} is incorrect. Press <ENTER> to terminate program...", input1);
input2 = Console.ReadLine();
break;
}
connStatus = NTClient.Connected(0);
if (connStatus == 0 && getData == true) Console.WriteLine("Connected to NinjaTrader");
elseif (connStatus != 0 && getData == true)
{
getData = false;
Console.WriteLine("ERROR: Can not connect. Press <ENTER> to terminate program...", input1);
input2 = Console.ReadLine();
}
 
if (getData)
{
 
last = NTClient.MarketData(inst, 0);
Console.WriteLine(inst + " Last Price: " + last);
Console.Write("Logging off in 10 secs");
while (myCounter <= 10)
{
Thread.Sleep(500);
Console.Write(".");
myCounter++;
}
NTClient.UnsubscribeMarketData(inst);
NTClient.TearDown();
}
if (!getData)
{
NTClient.UnsubscribeMarketData(inst);
NTClient.TearDown();
}
 
 
 
 
}
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Better Renko Gaps
The Elite Circle
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
Exit Strategy
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
Battlestations: Show us your trading desks!
26 thanks
The Program
18 thanks
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,396 since Jun 2009
Thanks Given: 33,172
Thanks Received: 101,534


Brilliant, I hadn't considered such an approach before for getting information out of NinjaTrader, only pushing information to...



Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

Thanks for the kind words, Mike.

Its a holiday here and I was bored so I actually did write a extremely basic WinForms app called APITrader that buys and sells ES 12-10 and shows the bid/ask/last/market position. If anyone is interested holla back and and I'll post it as a VS 2010 Project file.

It is coded by a complete neophyte (me) but I'm under pressure to get up to speed on this kind of thing quickly, so welcome to WinForms 101 for Ninja .

Attached Thumbnails
Click image for larger version

Name:	APITrader.JPG
Views:	458
Size:	183.4 KB
ID:	25365  
Started this thread Reply With Quote
Thanked by:
  #5 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

Last post for me tonight. By Monday this might be interesting...

Attached Thumbnails
Click image for larger version

Name:	LastFriday.JPG
Views:	523
Size:	168.7 KB
ID:	25380  
Started this thread Reply With Quote
Thanked by:
  #6 (permalink)
 timmyb 
duluth,mn
 
Experience: Advanced
Platform: ninja,thinkorswim
Broker: Amp-Zenfire
Trading: ES,Options
Posts: 654 since Feb 2010
Thanks Given: 81
Thanks Received: 1,361

I would sure like to play with it if your willing to share. I am thinking of heading in this direction for some other ideas and this reading of your code might really give me a jumpstart

Thanks

Tim

Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


timmyb View Post
I would sure like to play with it if your willing to share. I am thinking of heading in this direction for some other ideas and this reading of your code might really give me a jumpstart

Thanks

Tim

Sure. Do you have VS2010? I can attached zipped project files. If not I can attach the main code files.

Note the Ninja ATI is pretty limited in what it can do. But it's a great place to start.

EDIT: Attached the VS2010 Project for the APITrader thing I posted November 5th. I haven't played with it since (other things to do), and it is set up only to buy/sell ES 12-10, but the code might be a starting point for something.

Attached Files
Elite Membership required to download: APITrader.zip
Started this thread Reply With Quote
Thanked by:
  #8 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800

If you are OK with console apps this is something I played with more recently to add other examples and play with stuff:

 
Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using NinjaTrader.Client;
namespace NTConnectTest
{
classProgram
{
staticvoid Main(string[] args)
{
string inst = "ES 12-10";
string input1;
string input2;
double last;
double bid;
double ask;
int connStatus;
bool getData = false;
int myCounter = 0;

NinjaTrader.Client.Client NTClient = new NinjaTrader.Client.Client();
Console.WindowWidth = 100;
Console.Title = "NT Connect Test";

Console.WriteLine("Connect to Ninja Trader? y/n");
input1 = Console.ReadLine();
switch (input1)
{
case"y":
getData = true;
NTClient.SubscribeMarketData(inst);
break;
case"n":
getData = false;
Console.WriteLine("Ok. Bye. Press <ENTER> to terminate program...", input1);
input2 = Console.ReadLine();
break;

default:
getData = false;
Console.WriteLine("ERROR: Your input {0} is incorrect. Press <ENTER> to terminate program...", input1);
input2 = Console.ReadLine();
break;
}
connStatus = NTClient.Connected(0);
if (connStatus == 0 && getData == true)
{
Console.WriteLine("Connected to NinjaTrader");
Console.WriteLine("");
}
elseif (connStatus != 0 && getData == true)
{
getData = false;
Console.WriteLine("ERROR: Can not connect. Press <ENTER> to terminate program...", input1);
input2 = Console.ReadLine();
}

if (getData)
{
//if (connStatus == 0) Console.WriteLine("Connected to NinjaTrader");
last = NTClient.MarketData(inst, 0);
bid = NTClient.MarketData(inst, 1);
ask = NTClient.MarketData(inst, 2);
string orders = NTClient.Orders("Sim101");
double pnl = NTClient.RealizedPnL("Sim101");

Console.WriteLine("Return of NTClient.MarketData:");
Console.WriteLine(DateTime.Now + " " + inst + " Last Price: " + last + " Bid/Ask: " + bid+"/"+ask);
Console.WriteLine("");
Console.WriteLine("Return of NTClient.Orders:");
Console.WriteLine(orders);
Console.WriteLine("");
Console.WriteLine("Return of NTClient.RealizedPnL:");
Console.WriteLine(Math.Round(pnl,2));
Console.Write("Logging off in 10 secs");
while (myCounter <= 10)
{
Thread.Sleep(500);
Console.Write(".");
myCounter++;
}
NTClient.UnsubscribeMarketData(inst);
NTClient.TearDown();
}
if (!getData)
{
NTClient.UnsubscribeMarketData(inst);
NTClient.TearDown();
}
 
 
 
 
}
}
}

Started this thread Reply With Quote
  #9 (permalink)
 timmyb 
duluth,mn
 
Experience: Advanced
Platform: ninja,thinkorswim
Broker: Amp-Zenfire
Trading: ES,Options
Posts: 654 since Feb 2010
Thanks Given: 81
Thanks Received: 1,361


MXASJ View Post
Sure. Do you have VS2010? I can attached zipped project files. If not I can attach the main code files.

Note the Ninja ATI is pretty limited in what it can do. But it's a great place to start.

EDIT: Attached the VS2010 Project for the APITrader thing I posted November 5th. I haven't played with it since (other things to do), and it is set up only to buy/sell ES 12-10, but the code might be a starting point for something.

thanks I will look at it, I have visual studio 2008 pro. I am thinking the files should work fine. Thanks again for sharing

Visit my NexusFi Trade Journal Reply With Quote
  #10 (permalink)
jirkoo
New York USA
 
Posts: 1 since May 2011
Thanks Given: 0
Thanks Received: 0


Thanks for the APITrader code.

I downloaded APITrader and I am using NinjaTrader 7.0.1000.4

I have VS2010 and when I run APITrader it does not connect to NinjaTrader - I have NinjaTrader running along with the Simulated Data Feed.
The bottom left is in red and it indicates the connection to NinjaTrader is not active. I have also tried the file menu connect option and it does not work.

Any ideas?

Reply With Quote




Last Updated on October 8, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts