Port to `pendulum` equivalent apis throughout

drop_arrow_add_predulum
Tyler Goodlet 2022-04-16 13:17:15 -04:00
parent d334e61b1f
commit 72ec34ffd2
3 changed files with 14 additions and 12 deletions

View File

@ -27,7 +27,7 @@ import time
import trio import trio
from trio_typing import TaskStatus from trio_typing import TaskStatus
import arrow import pendulum
import asks import asks
from fuzzywuzzy import process as fuzzy from fuzzywuzzy import process as fuzzy
import numpy as np import numpy as np
@ -132,7 +132,7 @@ class OHLC:
bar_wap: float = 0.0 bar_wap: float = 0.0
# convert arrow timestamp to unixtime in miliseconds # convert datetime obj timestamp to unixtime in milliseconds
def binance_timestamp(when): def binance_timestamp(when):
return int((when.timestamp() * 1000) + (when.microsecond / 1000)) return int((when.timestamp() * 1000) + (when.microsecond / 1000))
@ -230,11 +230,11 @@ class Client:
if start_time is None: if start_time is None:
start_time = binance_timestamp( 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: 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 # https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data
bars = await self._api( bars = await self._api(

View File

@ -25,7 +25,7 @@ import time
from trio_typing import TaskStatus from trio_typing import TaskStatus
import trio import trio
import arrow import pendulum
import asks import asks
from fuzzywuzzy import process as fuzzy from fuzzywuzzy import process as fuzzy
import numpy as np import numpy as np
@ -401,8 +401,8 @@ class Client:
as_np: bool = True, as_np: bool = True,
) -> dict: ) -> dict:
if since is None: if since is None:
since = arrow.utcnow().floor('minute').shift( since = pendulum.now('UTC').start_of('minute').subtract(
minutes=-count).timestamp() minutes=count).timestamp()
# UTC 2017-07-02 12:53:20 is oldest seconds value # UTC 2017-07-02 12:53:20 is oldest seconds value
since = str(max(1499000000, since)) since = str(max(1499000000, since))

View File

@ -19,7 +19,6 @@ Questrade API backend.
""" """
from __future__ import annotations from __future__ import annotations
import inspect import inspect
import contextlib
import time import time
from datetime import datetime from datetime import datetime
from functools import partial from functools import partial
@ -32,7 +31,7 @@ from typing import (
Callable, Callable,
) )
import arrow import pendulum
import trio import trio
import tractor import tractor
from async_generator import asynccontextmanager from async_generator import asynccontextmanager
@ -46,7 +45,6 @@ from .._cacheables import open_cached_client, async_lifo_cache
from .. import config from .. import config
from ._util import resproc, BrokerError, SymbolNotFound from ._util import resproc, BrokerError, SymbolNotFound
from ..log import get_logger, colorize_json, get_console_log from ..log import get_logger, colorize_json, get_console_log
from . import get_brokermod
log = get_logger(__name__) log = get_logger(__name__)
@ -601,12 +599,16 @@ class Client:
sid = sids[symbol] sid = sids[symbol]
# get last market open end time # 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 # on non-paid feeds we can't retreive the first 15 mins
wd = now.isoweekday() wd = now.isoweekday()
if wd > 5: if wd > 5:
quotes = await self.quote([symbol]) quotes = await self.quote([symbol])
est_end = arrow.get(quotes[0]['lastTradeTime']) est_end = pendulum.parse(
quotes[0]['lastTradeTime']
)
if est_end.hour == 0: if est_end.hour == 0:
# XXX don't bother figuring out extended hours for now # XXX don't bother figuring out extended hours for now
est_end = est_end.replace(hour=17) est_end = est_end.replace(hour=17)