Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Get current Bid Ask Price of Instrument?
Collapse
X
-
Hello defa0009,
The BarsRequest.Request() has a bars parameter which contains a Bars object.
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;
}
Print( bars.Bars.GetAsk(bars.Bars.Count() -1) );
Print( bars.Bars.GetBid(bars.Bars.Count() -1) );
}));
}Chelsea B.NinjaTrader Customer Service
Comment
-
Hello defa0009,
The BarsBack value must be 1 or greater to request at least 1 bar.
You could request a single tick to get the most recent tick.
barsRequest = new BarsRequest(instrument, 1);
barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Tick, Value = 1 };
If you want each new update, you must add an event handler method to the barsRequest.Update event.
The argument contains the bars object as shown in the sample code in the help guide.
BarsRequest is in the NinjaTrader.Data namespace.Chelsea B.NinjaTrader Customer Service
Comment
-
Hello defa0009,
You would be requesting 1 tick bar, and getting the ask and bid from that tick.
Are you seeing the bars.Bars.GetClose(0); is producing a value?
Or what time is bars.Bars.GetTime(0) showing?
You could also choose to get the MarketData updates as these stream in.
It's not documented, but you could also try using the Instrument.MarketData.Ask / Instrument.MarketData.Bid.Chelsea B.NinjaTrader Customer Service
Comment
-
Hello defa0009,
If there is no subscription to the instrument made by a subscriber, then no data is coming in.
This is why a BarsRequest or AddDataSeries() call is necessary. (and likely why using instrument.MarketData.Ask is not documented)
"I also can't wait for the bars callback"
You probably will have to run the logic from the callback of a BarsRequest. The BarsRequest and event handler method would create a subscription to the instrument so the data is flowing.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by SalmaTrader, 07-07-2026, 10:26 PM
|
0 responses
54 views
0 likes
|
Last Post
by SalmaTrader
07-07-2026, 10:26 PM
|
||
|
Started by CarlTrading, 07-05-2026, 01:16 PM
|
0 responses
25 views
0 likes
|
Last Post
by CarlTrading
07-05-2026, 01:16 PM
|
||
|
Started by CaptainJack, 06-17-2026, 10:32 AM
|
0 responses
17 views
0 likes
|
Last Post
by CaptainJack
06-17-2026, 10:32 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:15 AM
|
0 responses
23 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:15 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:06 AM
|
0 responses
24 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:06 AM
|

Comment