Skip to content

Technical Indicators incorrect Time Conversion #689

Open
@TheBlackPlague

Description

@TheBlackPlague

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions