Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get current Bid Ask Price of Instrument?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Get current Bid Ask Price of Instrument?

    deleted...
    Last edited by defa0009; 09-20-2024, 03:27 PM.

    #2
    Hello defa0009,

    GetCurrentAsk() and GetCurrentBid() return the bid and ask for the instrument the script is running on.

    To get any data from another instrument, you would need to either add a data series with AddDataSeries() or do a BarsRequest.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      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


        #4
        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


          #5
          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


            #6
            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 Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            553 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            100 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            543 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            546 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X