Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to get bid ask prices for Instrument in AddOn
Collapse
X
-
How to get bid ask prices for Instrument in AddOn
I have AddOn in which I make BarsRequest for the Instrument for which I have an open position to get the open close last high and low for last 1 second. Is there a way I can get the bid ask as well if I supply quantity ?Tags: None
-
Thanks so I am having the below code.
- Will the I get the correct Exchange pushed here by the Broker. I am using TD ameritrade and not getting the exchange name here. Instead I get null.
- Will I get the latest Bid and Ask price of the today's bar ?
public static void SendQuoteForCharts(ChartQuoteRequest request)
{
Thread subscriptionThread=new Thread(() =>
{
Thread.CurrentThread.IsBackground = true;
// create a new bars request. This will determine the insturment and range for the bars to be requested
BarsRequest barsRequest = new BarsRequest(NinjaTrader.Cbi.Instrument.GetInstrume nt(request.Symbol), 2);
// Parametrize your request.
barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Day, Value = 1 };
barsRequest.TradingHours = TradingHours.Get("Default 24 x 7");
// Request the bars
barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage) =>
{
if (errorCode != ErrorCode.NoError)
{
// Handle any errors in requesting bars here
NinjaTrader.Code.Output.Process(string.Format("Err or on requesting bars: {0}, {1}",
errorCode, errorMessage), PrintTo.OutputTab1);
return;
}
if(bars.Bars.Count==2)
{
String messageBody="{{ "s": "ok","d": [\n";
messageBody+=string.Format("{{\n "s": "ok",\n "n": "{0}:{3}",\n "v": {{\n "ch": "{1}",\n "chp": "{2}",\n "short_name": "{3}",\n "exchange": "{4}",\n "description": "{5}",\n "lp": "{6}",\n "ask": "{7}",\n "bid": "{8}",\n "open_price": "{9}",\n "high_price": "{10}",\n "low_price": "{11}",\n "prev_close_price": "{12}",\n "volume": "{13}"\n }}\n }},",
NinjaTrader.Cbi.Instrument.GetInstrument(request.S ymbol).Exchange.ToString(),
bars.Bars.GetClose(1)-bars.Bars.GetOpen(1),
100*(bars.Bars.GetClose(1)-bars.Bars.GetOpen(1))/bars.Bars.GetOpen(1),
request.Symbol,
NinjaTrader.Cbi.Instrument.GetInstrument(request.S ymbol).Exchange.ToString(),
NinjaTrader.Cbi.Instrument.GetInstrument(request.S ymbol).FullName,
bars.Bars.GetClose(1),
bars.Bars.GetAsk(1),
bars.Bars.GetBid(1),
bars.Bars.GetOpen(1),
bars.Bars.GetHigh(1),
bars.Bars.GetLow(1),
bars.Bars.GetClose(0),
bars.Bars.GetVolume(1)
);
messageBody=messageBody.Substring(0,messageBody.Le ngth-2);
messageBody+="\n ]\n}";
SendChartData(messageBody, Tradelytics.Instructions.GetQuotesForCharts);
}
}));
});
subscriptionThread.Priority=ThreadPriority.Highest ;
subscriptionThread.Start();
}
Comment
-
Hello vivekniwas,
The Exchange is set in the instrument settings.
https://ninjatrader.com/support/help...nderstandingGe neralSection
What exchange or exchanges are selected in the instrument settings for this instrument?
May we have a screenshot?
From the chart, I am seeing that TD Ameritrade does not provide historical ask daily data.
Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Mestor, 03-10-2023, 01:50 AM
|
11 responses
303 views
0 likes
|
Last Post
by z.franck
Today, 02:29 AM
|
||
Started by Padan, Today, 02:02 AM
|
0 responses
6 views
0 likes
|
Last Post
by Padan
Today, 02:02 AM
|
||
Started by bukowa, 11-09-2023, 06:07 PM
|
20 responses
407 views
0 likes
|
Last Post
by Adfra
Today, 01:36 AM
|
||
Started by yertle, Yesterday, 05:49 PM
|
2 responses
11 views
0 likes
|
Last Post
by yertle
Today, 12:12 AM
|
||
Started by kaywai, Today, 12:06 AM
|
0 responses
10 views
0 likes
|
Last Post
by kaywai
Today, 12:06 AM
|
Comment