From ea42f66b545712005cb744096b60474db78cdc90 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 22 Mar 2023 12:32:21 -0400 Subject: [PATCH] Use common `.brokers` logger in most backends --- piker/brokers/cli.py | 12 ++++++++---- piker/brokers/core.py | 5 +---- piker/brokers/data.py | 8 ++++---- piker/brokers/ib/_util.py | 4 +--- piker/brokers/ib/api.py | 4 +--- piker/brokers/questrade.py | 11 +++++++---- piker/brokers/robinhood.py | 15 +++++++++------ 7 files changed, 31 insertions(+), 28 deletions(-) diff --git a/piker/brokers/cli.py b/piker/brokers/cli.py index f86c679e..1bfb05d6 100644 --- a/piker/brokers/cli.py +++ b/piker/brokers/cli.py @@ -28,7 +28,13 @@ import tractor from ..cli import cli from .. import watchlists as wl -from ..log import get_console_log, colorize_json, get_logger +from ..log import ( + colorize_json, +) +from ._util import ( + log, + get_console_log, +) from ..service import ( maybe_spawn_brokerd, maybe_open_pikerd, @@ -38,9 +44,7 @@ from ..brokers import ( get_brokermod, data, ) - -log = get_logger('cli') -DEFAULT_BROKER = 'questrade' +DEFAULT_BROKER = 'binance' _config_dir = click.get_app_dir('piker') _watchlists_data_path = os.path.join(_config_dir, 'watchlists.json') diff --git a/piker/brokers/core.py b/piker/brokers/core.py index 3e9e1614..b3651c1d 100644 --- a/piker/brokers/core.py +++ b/piker/brokers/core.py @@ -26,15 +26,12 @@ from typing import List, Dict, Any, Optional import trio -from ..log import get_logger +from ._util import log from . import get_brokermod from ..service import maybe_spawn_brokerd from .._cacheables import open_cached_client -log = get_logger(__name__) - - async def api(brokername: str, methname: str, **kwargs) -> dict: """Make (proxy through) a broker API call by name and return its result. """ diff --git a/piker/brokers/data.py b/piker/brokers/data.py index 5183d2c4..6d178b51 100644 --- a/piker/brokers/data.py +++ b/piker/brokers/data.py @@ -41,13 +41,13 @@ import tractor from tractor.experimental import msgpub from async_generator import asynccontextmanager -from ..log import get_logger, get_console_log +from ._util import ( + log, + get_console_log, +) from . import get_brokermod -log = get_logger(__name__) - - async def wait_for_network( net_func: Callable, sleep: int = 1 diff --git a/piker/brokers/ib/_util.py b/piker/brokers/ib/_util.py index 14fd4d0b..a94f77f1 100644 --- a/piker/brokers/ib/_util.py +++ b/piker/brokers/ib/_util.py @@ -24,9 +24,7 @@ import subprocess import tractor -from piker.log import get_logger - -log = get_logger(__name__) +from .._util import log _reset_tech: Literal[ diff --git a/piker/brokers/ib/api.py b/piker/brokers/ib/api.py index c6513204..62c0adeb 100644 --- a/piker/brokers/ib/api.py +++ b/piker/brokers/ib/api.py @@ -68,12 +68,10 @@ import numpy as np from piker import config from piker.log import get_logger +from piker.brokers._util import log from piker.data._source import base_ohlc_dtype -log = get_logger(__name__) - - _time_units = { 's': ' sec', 'm': ' mins', diff --git a/piker/brokers/questrade.py b/piker/brokers/questrade.py index a3b5cfe0..b7042bdf 100644 --- a/piker/brokers/questrade.py +++ b/piker/brokers/questrade.py @@ -43,10 +43,13 @@ from ..calc import humanize, percent_change 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 - - -log = get_logger(__name__) +from ..log import ( + colorize_json, +) +from .util import ( + log, + get_console_log, +) _use_practice_account = False _refresh_token_ep = 'https://{}login.questrade.com/oauth2/' diff --git a/piker/brokers/robinhood.py b/piker/brokers/robinhood.py index 71b21055..8fc5739f 100644 --- a/piker/brokers/robinhood.py +++ b/piker/brokers/robinhood.py @@ -27,12 +27,13 @@ from typing import List from async_generator import asynccontextmanager import asks -from ..log import get_logger -from ._util import resproc, BrokerError +from ._util import ( + resproc, + BrokerError, + log, +) from ..calc import percent_change -log = get_logger(__name__) - _service_ep = 'https://api.robinhood.com' @@ -65,8 +66,10 @@ class Client: self.api = _API(self._sess) def _zip_in_order(self, symbols: [str], quotes: List[dict]): - return {quote.get('symbol', sym) if quote else sym: quote - for sym, quote in zip(symbols, results_dict)} + return { + quote.get('symbol', sym) if quote else sym: quote + for sym, quote in zip(symbols, quotes) + } async def quote(self, symbols: [str]): """Retrieve quotes for a list of ``symbols``.