diff --git a/vega_query/scripts/plots.py b/vega_query/scripts/plots.py index b917f0aff..58547076a 100644 --- a/vega_query/scripts/plots.py +++ b/vega_query/scripts/plots.py @@ -8,7 +8,7 @@ import vega_protos.protos as protos from vega_query.service.service import Service from vega_query.service.networks.constants import Network -from scripts.parser import PARSER +from vega_query.scripts.parser import PARSER if __name__ == "__main__": # Enrich parser with script specific options diff --git a/vega_query/utils.py b/vega_query/utils.py index f9768ef93..d5ac45c87 100644 --- a/vega_query/utils.py +++ b/vega_query/utils.py @@ -8,7 +8,7 @@ def timestamp_to_datetime(ts: int, nano: bool = True): if nano: ts = ts / 1e9 - return datetime.datetime.fromtimestamp(ts) + return datetime.datetime.fromtimestamp(ts, tz=datetime.timezone.utc) def datetime_to_timestamp(dt: datetime.datetime, nano: bool = True) -> int: diff --git a/vega_query/visualisations/plots/amm.py b/vega_query/visualisations/plots/amm.py index 2fdfffe31..e02c89802 100644 --- a/vega_query/visualisations/plots/amm.py +++ b/vega_query/visualisations/plots/amm.py @@ -49,9 +49,11 @@ def create( # Default timestamps for getting data if required network_timestamp = service.api.data.get_vega_time() start_timestamp = ( - market.market_timestamps.proposed if start_timestamp is None else None + market.market_timestamps.proposed + if start_timestamp is None + else start_timestamp ) - end_timestamp = network_timestamp if end_timestamp is None else None + end_timestamp = network_timestamp if end_timestamp is None else end_timestamp # Get market specific information market_data_history = service.api.data.get_market_data_history_by_id( @@ -156,7 +158,7 @@ def create( if __name__ == "__main__": - from scripts.parser import PARSER + from vega_query.scripts.parser import PARSER args = PARSER.parse_args() @@ -188,14 +190,12 @@ def create( service, market_code=args.market, start_timestamp=( - timestamp_to_datetime(args.start_time, nano=True) + int(args.start_time.timestamp() * 1e9) if args.start_time is not None else None ), end_timestamp=( - timestamp_to_datetime(args.end_time, nano=True) - if args.end_time is not None - else None + int(args.end_time.timestamp() * 1e9) if args.end_time is not None else None ), ) plt.show() diff --git a/vega_query/visualisations/plots/sla.py b/vega_query/visualisations/plots/sla.py index 38f737fc8..391894239 100644 --- a/vega_query/visualisations/plots/sla.py +++ b/vega_query/visualisations/plots/sla.py @@ -52,9 +52,11 @@ def create( # Default timestamps for getting data if required network_timestamp = service.api.data.get_vega_time() start_timestamp = ( - market.market_timestamps.proposed if start_timestamp is None else None + market.market_timestamps.proposed + if start_timestamp is None + else start_timestamp ) - end_timestamp = network_timestamp if end_timestamp is None else None + end_timestamp = network_timestamp if end_timestamp is None else end_timestamp # Get market specific information market_data_history = service.api.data.get_market_data_history_by_id( @@ -155,7 +157,7 @@ def create( if __name__ == "__main__": - from scripts.parser import PARSER + from vega_query.scripts.parser import PARSER args = PARSER.parse_args() @@ -187,14 +189,12 @@ def create( service, market_code=args.market, start_timestamp=( - timestamp_to_datetime(args.start_time, nano=True) + int(args.start_time.timestamp() * 1e9) if args.start_time is not None else None ), end_timestamp=( - timestamp_to_datetime(args.end_time, nano=True) - if args.end_time is not None - else None + int(args.end_time.timestamp() * 1e9) if args.end_time is not None else None ), ) plt.show()