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 Barry Milan, Today, 10:35 PM
|
1 response
8 views
0 likes
|
Last Post Today, 10:48 PM | ||
Started by WeyldFalcon, 12-10-2020, 06:48 PM
|
14 responses
1,428 views
0 likes
|
Last Post
by Handclap0241
Today, 10:43 PM
|
||
Started by DJ888, Yesterday, 06:09 PM
|
2 responses
9 views
0 likes
|
Last Post
by DJ888
Today, 10:31 PM
|
||
Started by jeronymite, 04-12-2024, 04:26 PM
|
3 responses
40 views
0 likes
|
Last Post
by jeronymite
Today, 10:10 PM
|
||
Started by bill2023, Today, 08:51 AM
|
2 responses
16 views
0 likes
|
Last Post
by bill2023
Today, 10:10 PM
|
Comment