Merge pull request #303 from pikers/drop_arrow_add_predulum

Drop `arrow` add `pendulum`
no_orderid_in_error
goodboy 2022-04-16 14:00:03 -04:00 committed by GitHub
commit 3ac9c55535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 20 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

@ -1519,12 +1519,12 @@ async def get_bars(
('history', hist_ev), ('history', hist_ev),
# ('live', live_ev), # ('live', live_ev),
]: ]:
with trio.move_on_after(22) as cs: # with trio.move_on_after(22) as cs:
await ev.wait() await ev.wait()
log.info(f"{name} DATA RESET") log.info(f"{name} DATA RESET")
if cs.cancelled_caught: # if cs.cancelled_caught:
log.warning("reset hack failed on first try?") # log.warning("reset hack failed on first try?")
# await tractor.breakpoint() # await tractor.breakpoint()
fails += 1 fails += 1
@ -1583,7 +1583,7 @@ async def backfill_bars(
# on that until we have the `marketstore` daemon in place in which # 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 # case the shm size will be driven by user config and available sys
# memory. # memory.
count: int = 16, count: int = 100,
task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED, task_status: TaskStatus[trio.CancelScope] = trio.TASK_STATUS_IGNORED,

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)

View File

@ -60,7 +60,7 @@ setup(
'ib_insync', 'ib_insync',
# numerics # numerics
'arrow', # better datetimes 'pendulum', # easier datetimes
'bidict', # 2 way map 'bidict', # 2 way map
'cython', 'cython',
'numpy', 'numpy',