diff --git a/piker/brokers/binance.py b/piker/brokers/binance.py index 5034aca6..d0a00b68 100644 --- a/piker/brokers/binance.py +++ b/piker/brokers/binance.py @@ -27,7 +27,7 @@ import time import trio from trio_typing import TaskStatus -import arrow +import pendulum import asks from fuzzywuzzy import process as fuzzy import numpy as np @@ -132,7 +132,7 @@ class OHLC: bar_wap: float = 0.0 -# convert arrow timestamp to unixtime in miliseconds +# convert datetime obj timestamp to unixtime in milliseconds def binance_timestamp(when): return int((when.timestamp() * 1000) + (when.microsecond / 1000)) @@ -230,11 +230,11 @@ class Client: if start_time is None: start_time = binance_timestamp( - arrow.utcnow().floor('minute').shift(minutes=-limit) + pendulum.now('UTC').start_of('minute').subtract(minutes=limit) ) if end_time is None: - end_time = binance_timestamp(arrow.utcnow()) + end_time = binance_timestamp(pendulum.now('UTC')) # https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data bars = await self._api( diff --git a/piker/brokers/ib.py b/piker/brokers/ib.py index 51724e5a..65d6f4c0 100644 --- a/piker/brokers/ib.py +++ b/piker/brokers/ib.py @@ -1519,13 +1519,13 @@ async def get_bars( ('history', hist_ev), # ('live', live_ev), ]: - with trio.move_on_after(22) as cs: - await ev.wait() - log.info(f"{name} DATA RESET") + # with trio.move_on_after(22) as cs: + await ev.wait() + log.info(f"{name} DATA RESET") - if cs.cancelled_caught: - log.warning("reset hack failed on first try?") - # await tractor.breakpoint() + # if cs.cancelled_caught: + # log.warning("reset hack failed on first try?") + # await tractor.breakpoint() fails += 1 continue @@ -1583,7 +1583,7 @@ async def backfill_bars( # on that until we have the `marketstore` daemon in place in which # case the shm size will be driven by user config and available sys # memory. - count: int = 16, + count: int = 100, task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED, diff --git a/piker/brokers/kraken.py b/piker/brokers/kraken.py index 4f5166db..ed3cbf2e 100644 --- a/piker/brokers/kraken.py +++ b/piker/brokers/kraken.py @@ -25,7 +25,7 @@ import time from trio_typing import TaskStatus import trio -import arrow +import pendulum import asks from fuzzywuzzy import process as fuzzy import numpy as np @@ -401,8 +401,8 @@ class Client: as_np: bool = True, ) -> dict: if since is None: - since = arrow.utcnow().floor('minute').shift( - minutes=-count).timestamp() + since = pendulum.now('UTC').start_of('minute').subtract( + minutes=count).timestamp() # UTC 2017-07-02 12:53:20 is oldest seconds value since = str(max(1499000000, since)) diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index 30ba049e..bd364615 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -19,7 +19,6 @@ Questrade API backend. """ from __future__ import annotations import inspect -import contextlib import time from datetime import datetime from functools import partial @@ -32,7 +31,7 @@ from typing import ( Callable, ) -import arrow +import pendulum import trio import tractor from async_generator import asynccontextmanager @@ -46,7 +45,6 @@ from .._cacheables import open_cached_client, async_lifo_cache from .. import config from ._util import resproc, BrokerError, SymbolNotFound from ..log import get_logger, colorize_json, get_console_log -from . import get_brokermod log = get_logger(__name__) @@ -601,12 +599,16 @@ class Client: sid = sids[symbol] # get last market open end time - est_end = now = arrow.utcnow().to('US/Eastern').floor('minute') + est_end = now = pendulum.now('UTC').in_timezoe( + 'America/New_York').start_of('minute') + # on non-paid feeds we can't retreive the first 15 mins wd = now.isoweekday() if wd > 5: quotes = await self.quote([symbol]) - est_end = arrow.get(quotes[0]['lastTradeTime']) + est_end = pendulum.parse( + quotes[0]['lastTradeTime'] + ) if est_end.hour == 0: # XXX don't bother figuring out extended hours for now est_end = est_end.replace(hour=17) diff --git a/setup.py b/setup.py index faaa8dac..fc3ce78a 100755 --- a/setup.py +++ b/setup.py @@ -60,7 +60,7 @@ setup( 'ib_insync', # numerics - 'arrow', # better datetimes + 'pendulum', # easier datetimes 'bidict', # 2 way map 'cython', 'numpy',