Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    api.polygon.historic_agg returns incorrect timestamp

    General Code/Help
    3
    5
    472
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Ronan Dunham last edited by

      symbols="TSLA"
      minute_history ={}
      minute_history[symbols] = api.polygon.historic_agg(
          size="minute", symbol=symbols, limit=6,to='2020-01-03 14:59:00-0500'
      ).df
      df=minute_history[symbols]
      df
      

      the output seems as below:
      82ea676c-d2e3-4921-ae82-1fb90f766e4d-image.png

      i am only looking at last 6 data points (each every last 6 mins before 1-3 14:59 pm.

      What is wrong here. Please help

      B 1 Reply Last reply Reply Quote 0
      • vladisld
        vladisld last edited by

        https://forum.alpaca.markets/ is probably a better place to ask about it.

        1 Reply Last reply Reply Quote 0
        • B
          backtrader administrators @Ronan Dunham last edited by backtrader

          Without knowing nothing about that API I would argue that this call

          @Ronan-Dunham said in api.polygon.historic_agg returns incorrect timestamp:

          minute_history[symbols] = api.polygon.historic_agg(
              size="minute", symbol=symbols, limit=6,to='2020-01-03 14:59:00-0500'
          ).df
          

          returns probably the right things,. i.e.:

          • A 1st timestamp which is the beginning of the epoch adjusted for the timezone -5 (hence 19:00 on 1969-12-31, instead of 00:00 on 1970-01-01)
          • The 1st additional 5 bars to honor the limit=6 (1 timestamp bar + 5 data bars)
          • The to='2020-01-03 14:59:00-0500' can obviously not be reached, because there are many more minutes than 6 from the beginning of the simybol (apparently it started trading on 2016-06-29 15:25 UTC, which was probably the pre-market before the opening at 15:30 UTC)

          There is no obvious from limitation in the call, so the API seems to be doing its best to grant the request as issued.

          1 Reply Last reply Reply Quote 0
          • R
            Ronan Dunham last edited by

            Hi @backtrader ,

            Thank you for the reply.

            api = alpaca_trade_api.REST(
                base_url=base_url,
                key_id=api_key_id,
                secret_key=api_secret)
            

            this is indeed alpaca_trade_api.REST(). How can I get only the last 6 data bars from the code? what changes would i have to make. Would you happen to know? Thanks in advance.

            @vladisld I did post in alpaca forum but havenot received any feedback for days. I seem to get help here more often. Sorry didnot mean to spam this forum.

            1 Reply Last reply Reply Quote 0
            • B
              backtrader administrators last edited by

              To me it would seem sensible to try a from parameter.

              The problem is the limit=6, which seems arbitrary. Backfilling is difficult, because you may know what you want, but APIs have to cope with facts like non-trading hours. That's why you usually says from => to and get the number of bars that are available, regardless of non-trading days and non-trading hours.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors