Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technical Indicators incorrect Time Conversion #689

Open
TheBlackPlague opened this issue Jun 22, 2024 · 1 comment
Open

Technical Indicators incorrect Time Conversion #689

TheBlackPlague opened this issue Jun 22, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@TheBlackPlague
Copy link

Describe the bug
The time conversion is done from datetime when querying for technical indicators is to a nanoseconds resolution which conflicts with what Polygon is expecting (milliseconds). This, in turn, leads to Polygon thinking the wrong period is queried.

Code Links

  • @staticmethod
    def time_mult(timestamp_res: str) -> int:
    if timestamp_res == "nanos":
    return 1000000000
    elif timestamp_res == "micros":
    return 1000000
    elif timestamp_res == "millis":
    return 1000
    return 1
  • elif isinstance(val, datetime):
    val = int(val.timestamp() * self.time_mult(datetime_res))

As you can see, this is different from the way say the Aggregates call is done:

if isinstance(from_, datetime):
from_ = int(from_.timestamp() * self.time_mult("millis"))
if isinstance(to, datetime):
to = int(to.timestamp() * self.time_mult("millis"))

The aggregates call is the right way. The SMA indicator also expects a millisecond timestamp: https://polygon.io/docs/stocks/get_v1_indicators_sma__stockticker

@TheBlackPlague TheBlackPlague added the bug Something isn't working label Jun 22, 2024
@justinpolygon justinpolygon self-assigned this Jun 22, 2024
@justinpolygon
Copy link
Contributor

Thanks for reporting. I'll check this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants