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 sjsj2732, Today, 04:31 AM
            0 responses
            20 views
            0 likes
            Last Post sjsj2732  
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            280 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            279 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            130 views
            1 like
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            90 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Working...
            X