diff --git a/piker/accounting/__init__.py b/piker/accounting/__init__.py index d6e1c3b6..e7ff16f1 100644 --- a/piker/accounting/__init__.py +++ b/piker/accounting/__init__.py @@ -50,6 +50,8 @@ from ._allocate import ( mk_allocator, Allocator, ) +from .models import CostModel + log = get_logger(__name__) @@ -57,6 +59,7 @@ __all__ = [ 'Account', 'Allocator', 'Asset', + 'CostModel', 'MktPair', 'Position', 'Symbol', diff --git a/piker/accounting/_allocate.py b/piker/accounting/_allocate.py index deeec498..ab3fa965 100644 --- a/piker/accounting/_allocate.py +++ b/piker/accounting/_allocate.py @@ -25,7 +25,7 @@ from bidict import bidict from ._pos import Position from . import MktPair -from ..data.types import Struct +from piker.types import Struct _size_units = bidict({ diff --git a/piker/accounting/_ledger.py b/piker/accounting/_ledger.py index 5f1865c9..8eac518a 100644 --- a/piker/accounting/_ledger.py +++ b/piker/accounting/_ledger.py @@ -37,8 +37,8 @@ from pendulum import ( ) import tomli_w # for fast ledger writing -from .. import config -from ..data.types import Struct +from piker.types import Struct +from piker import config from ..log import get_logger from .calc import ( iter_by_dt, diff --git a/piker/accounting/_mktinfo.py b/piker/accounting/_mktinfo.py index 4197c1bb..34adafa2 100644 --- a/piker/accounting/_mktinfo.py +++ b/piker/accounting/_mktinfo.py @@ -36,7 +36,7 @@ from typing import ( Literal, ) -from ..data.types import Struct +from piker.types import Struct # TODO: make these literals.. diff --git a/piker/accounting/_pos.py b/piker/accounting/_pos.py index 87c36d24..1a2378da 100644 --- a/piker/accounting/_pos.py +++ b/piker/accounting/_pos.py @@ -58,8 +58,8 @@ from .. import config from ..clearing._messages import ( BrokerdPosition, ) -from ..data.types import Struct -from ..data._symcache import SymbologyCache +from piker.types import Struct +from piker.data._symcache import SymbologyCache from ..log import get_logger log = get_logger(__name__) diff --git a/piker/accounting/calc.py b/piker/accounting/calc.py index 96889c71..6ab89d2b 100644 --- a/piker/accounting/calc.py +++ b/piker/accounting/calc.py @@ -422,7 +422,12 @@ def ledger_to_dfs( # fdf = df.filter(pred) - # break up into a frame per mkt / fqme + # TODO: originally i had tried just using a plain ol' groupby + # + agg here but the issue was re-inserting to the src frame. + # however, learning more about `polars` seems like maybe we can + # use `.over()`? + # https://pola-rs.github.io/polars/py-polars/html/reference/expressions/api/polars.Expr.over.html#polars.Expr.over + # => CURRENTLY we break up into a frame per mkt / fqme dfs: dict[str, pl.DataFrame] = ldf.partition_by( 'bs_mktid', as_dict=True, @@ -435,14 +440,9 @@ def ledger_to_dfs( # covert to lazy form (since apparently we might need it # eventually ...) - df = dfs[key] + df: pl.DataFrame = dfs[key] - ldf = df.lazy() - # TODO: pass back the current `Position` object loaded from - # the account as well? Would provide incentive to do all - # this ledger loading inside a new async open_account(). - # bs_mktid: str = df[0]['bs_mktid'] - # pos: Position = acnt.pps[bs_mktid] + ldf: pl.LazyFrame = df.lazy() df = dfs[key] = ldf.with_columns([ @@ -688,4 +688,10 @@ def ledger_to_dfs( last_ppu: float = ppu last_cumsize: float = cumsize + # TODO?: pass back the current `Position` object loaded from + # the account as well? Would provide incentive to do all + # this ledger loading inside a new async open_account(). + # bs_mktid: str = df[0]['bs_mktid'] + # pos: Position = acnt.pps[bs_mktid] + return dfs diff --git a/piker/brokers/binance/api.py b/piker/brokers/binance/api.py index 2ade69ed..25cd31a8 100644 --- a/piker/brokers/binance/api.py +++ b/piker/brokers/binance/api.py @@ -53,7 +53,7 @@ from piker.accounting import ( Asset, digits_to_dec, ) -from piker.data.types import Struct +from piker.types import Struct from piker.data import def_iohlcv_fields from piker.brokers import ( resproc, diff --git a/piker/brokers/binance/feed.py b/piker/brokers/binance/feed.py index 6d6ae28d..713f76c6 100644 --- a/piker/brokers/binance/feed.py +++ b/piker/brokers/binance/feed.py @@ -58,7 +58,7 @@ from piker.accounting import ( MktPair, unpack_fqme, ) -from piker.data.types import Struct +from piker.types import Struct from piker.data.validate import FeedInit from piker.data._web_bs import ( open_autorecon_ws, diff --git a/piker/brokers/binance/venues.py b/piker/brokers/binance/venues.py index 3510d6f6..dc3312be 100644 --- a/piker/brokers/binance/venues.py +++ b/piker/brokers/binance/venues.py @@ -26,7 +26,7 @@ from decimal import Decimal from msgspec import field -from piker.data.types import Struct +from piker.types import Struct # API endpoint paths by venue / sub-API diff --git a/piker/brokers/ib/broker.py b/piker/brokers/ib/broker.py index b32f4eac..262cbc1d 100644 --- a/piker/brokers/ib/broker.py +++ b/piker/brokers/ib/broker.py @@ -49,6 +49,7 @@ from ib_insync.objects import ( ) from piker import config +from piker.types import Struct from piker.accounting import ( Position, Transaction, @@ -62,7 +63,6 @@ from piker.accounting import ( from piker.data import ( open_symcache, SymbologyCache, - Struct, ) from piker.clearing._messages import ( Order, diff --git a/piker/brokers/ib/ledger.py b/piker/brokers/ib/ledger.py index 9143cce6..7273d8c9 100644 --- a/piker/brokers/ib/ledger.py +++ b/piker/brokers/ib/ledger.py @@ -39,8 +39,8 @@ from ib_insync.objects import ( CommissionReport, ) +from piker.types import Struct from piker.data import ( - Struct, SymbologyCache, ) from piker.accounting import ( diff --git a/piker/brokers/kraken/feed.py b/piker/brokers/kraken/feed.py index 63072fd0..298acdca 100644 --- a/piker/brokers/kraken/feed.py +++ b/piker/brokers/kraken/feed.py @@ -46,7 +46,7 @@ from piker.brokers._util import ( DataThrottle, DataUnavailable, ) -from piker.data.types import Struct +from piker.types import Struct from piker.data.validate import FeedInit from piker.data._web_bs import open_autorecon_ws, NoBsWs from .api import ( diff --git a/piker/brokers/kraken/ledger.py b/piker/brokers/kraken/ledger.py index 6515568f..6dcd327e 100644 --- a/piker/brokers/kraken/ledger.py +++ b/piker/brokers/kraken/ledger.py @@ -34,9 +34,9 @@ from piker.accounting import ( TransactionLedger, # MktPair, ) +from piker.types import Struct from piker.data import ( SymbologyCache, - Struct, ) from .api import ( log, diff --git a/piker/brokers/kraken/symbols.py b/piker/brokers/kraken/symbols.py index ea2c68f4..d71828b2 100644 --- a/piker/brokers/kraken/symbols.py +++ b/piker/brokers/kraken/symbols.py @@ -33,7 +33,7 @@ from piker.brokers import ( open_cached_client, SymbolNotFound, ) -from piker.data.types import Struct +from piker.types import Struct from piker.accounting._mktinfo import ( Asset, MktPair, diff --git a/piker/brokers/kucoin.py b/piker/brokers/kucoin.py index a85b18f4..26aab4df 100755 --- a/piker/brokers/kucoin.py +++ b/piker/brokers/kucoin.py @@ -64,7 +64,7 @@ from piker._cacheables import ( ) from piker.log import get_logger from piker.data.validate import FeedInit -from piker.data.types import Struct +from piker.types import Struct from piker.data import def_iohlcv_fields from piker.data._web_bs import ( open_autorecon_ws, diff --git a/piker/clearing/__init__.py b/piker/clearing/__init__.py index 19d6390f..1c25a6fd 100644 --- a/piker/clearing/__init__.py +++ b/piker/clearing/__init__.py @@ -27,13 +27,28 @@ from ._ems import ( open_brokerd_dialog, ) from ._util import OrderDialogs +from ._messages import( + Order, + Status, + Cancel, + + # TODO: deprecate these and replace end-2-end with + # client-side-dialog set above B) + # https://github.com/pikers/piker/issues/514 + BrokerdPosition +) __all__ = [ + 'FeeModel', 'open_ems', 'OrderClient', 'open_brokerd_dialog', 'OrderDialogs', + 'Order', + 'Status', + 'Cancel', + 'BrokerdPosition' ] diff --git a/piker/clearing/_client.py b/piker/clearing/_client.py index 9977f95d..9bb2aa74 100644 --- a/piker/clearing/_client.py +++ b/piker/clearing/_client.py @@ -30,7 +30,7 @@ from tractor.trionics import broadcast_receiver from ._util import ( log, # sub-sys logger ) -from ..data.types import Struct +from piker.types import Struct from ..service import maybe_open_emsd from ._messages import ( Order, diff --git a/piker/clearing/_ems.py b/piker/clearing/_ems.py index b43d8fd1..9e30351e 100644 --- a/piker/clearing/_ems.py +++ b/piker/clearing/_ems.py @@ -51,9 +51,9 @@ from ..accounting._mktinfo import ( unpack_fqme, dec_digits, ) +from piker.types import Struct from ..ui._notify import notify_from_ems_status_msg from ..data import iterticks -from ..data.types import Struct from ._messages import ( Order, Status, diff --git a/piker/clearing/_messages.py b/piker/clearing/_messages.py index 4946b0c0..6e44969e 100644 --- a/piker/clearing/_messages.py +++ b/piker/clearing/_messages.py @@ -28,7 +28,7 @@ from typing import ( from msgspec import field -from ..data.types import Struct +from piker.types import Struct # TODO: a composite for tracking msg flow on 2-legged diff --git a/piker/clearing/_paper_engine.py b/piker/clearing/_paper_engine.py index 67c789a4..6af25426 100644 --- a/piker/clearing/_paper_engine.py +++ b/piker/clearing/_paper_engine.py @@ -40,21 +40,22 @@ import tractor from piker.brokers import get_brokermod from piker.accounting import ( - Position, Account, + CostModel, + MktPair, + Position, Transaction, TransactionLedger, - open_trade_ledger, open_account, - MktPair, + open_trade_ledger, unpack_fqme, ) from piker.data import ( - open_feed, - iterticks, Struct, - open_symcache, SymbologyCache, + iterticks, + open_feed, + open_symcache, ) from ._util import ( log, # sub-sys logger @@ -83,6 +84,7 @@ class PaperBoi(Struct): ems_trades_stream: tractor.MsgStream acnt: Account ledger: TransactionLedger + fees: CostModel # map of paper "live" orders which be used # to simulate fills based on paper engine settings diff --git a/piker/clearing/_util.py b/piker/clearing/_util.py index 3ba7f55f..962861e8 100644 --- a/piker/clearing/_util.py +++ b/piker/clearing/_util.py @@ -25,7 +25,7 @@ from ..log import ( get_logger, get_console_log, ) -from piker.data.types import Struct +from piker.types import Struct subsys: str = 'piker.clearing' log = get_logger(subsys) diff --git a/piker/data/__init__.py b/piker/data/__init__.py index 95c47e19..9b12697e 100644 --- a/piker/data/__init__.py +++ b/piker/data/__init__.py @@ -44,7 +44,7 @@ from ._symcache import ( open_symcache, get_symcache, ) -from .types import Struct +from ._sampling import open_sample_stream __all__: list[str] = [ @@ -60,7 +60,8 @@ __all__: list[str] = [ 'def_iohlcv_fields', 'def_ohlcv_fields', 'open_symcache', + 'open_sample_stream', 'get_symcache', 'SymbologyCache', - 'Struct', + 'types', ] diff --git a/piker/data/_sharedmem.py b/piker/data/_sharedmem.py index 78f66f63..0a797600 100644 --- a/piker/data/_sharedmem.py +++ b/piker/data/_sharedmem.py @@ -34,7 +34,7 @@ import tractor from ._util import log from ._source import def_iohlcv_fields -from .types import Struct +from piker.types import Struct def cuckoff_mantracker(): diff --git a/piker/data/_symcache.py b/piker/data/_symcache.py index e6c94fa6..abb0145d 100644 --- a/piker/data/_symcache.py +++ b/piker/data/_symcache.py @@ -47,11 +47,11 @@ from msgspec import field from piker.log import get_logger from piker import config +from piker.types import Struct from piker.brokers import ( open_cached_client, get_brokermod, ) -from .types import Struct if TYPE_CHECKING: from ..accounting import ( diff --git a/piker/data/_web_bs.py b/piker/data/_web_bs.py index 9c2753b1..e60f871b 100644 --- a/piker/data/_web_bs.py +++ b/piker/data/_web_bs.py @@ -50,8 +50,8 @@ from trio_websocket._impl import ( ConnectionTimeout, ) +from piker.types import Struct from ._util import log -from .types import Struct class NoBsWs: diff --git a/piker/data/feed.py b/piker/data/feed.py index fcd193da..7691538c 100644 --- a/piker/data/feed.py +++ b/piker/data/feed.py @@ -50,15 +50,21 @@ from tractor.trionics import ( gather_contexts, ) -from ..brokers import get_brokermod -from ..calc import humanize +from piker.accounting import ( + MktPair, + unpack_fqme, +) +from piker.types import Struct +from piker.brokers import get_brokermod +from piker.service import ( + maybe_spawn_brokerd, +) +from piker.ui import _search +from piker.calc import humanize from ._util import ( log, get_console_log, ) -from ..service import ( - maybe_spawn_brokerd, -) from .flows import Flume from .validate import ( FeedInit, @@ -68,12 +74,6 @@ from .history import ( manage_history, ) from .ingest import get_ingestormod -from .types import Struct -from ..accounting import ( - MktPair, - unpack_fqme, -) -from ..ui import _search from ._sampling import ( sample_and_broadcast, uniform_rate_send, diff --git a/piker/data/flows.py b/piker/data/flows.py index 86e5370f..38345cea 100644 --- a/piker/data/flows.py +++ b/piker/data/flows.py @@ -30,8 +30,7 @@ import tractor import pendulum import numpy as np -from ..accounting import MktPair -from .types import Struct +from piker.types import Struct from ._sharedmem import ( attach_shm_array, ShmArray, @@ -39,7 +38,7 @@ from ._sharedmem import ( ) if TYPE_CHECKING: - # from pyqtgraph import PlotItem + from ..accounting import MktPair from .feed import Feed @@ -189,6 +188,7 @@ class Flume(Struct): ''' mkt_msg = msg.pop('mkt') + from ..accounting import MktPair # cycle otherwise.. mkt = MktPair.from_msg(mkt_msg) return cls(mkt=mkt, **msg) diff --git a/piker/data/validate.py b/piker/data/validate.py index f54992cf..cefa0f1f 100644 --- a/piker/data/validate.py +++ b/piker/data/validate.py @@ -18,6 +18,7 @@ Data feed synchronization protocols, init msgs, and general data-provider-backend-agnostic schema definitions. ''' +from __future__ import annotations from decimal import Decimal from pprint import pformat from types import ModuleType @@ -28,8 +29,8 @@ from typing import ( from msgspec import field -from .types import Struct -from ..accounting import ( +from piker.types import Struct +from piker.accounting import ( Asset, MktPair, ) diff --git a/piker/fsp/__init__.py b/piker/fsp/__init__.py index 5e88ed69..e463ac26 100644 --- a/piker/fsp/__init__.py +++ b/piker/fsp/__init__.py @@ -22,9 +22,25 @@ from typing import AsyncIterator import numpy as np +from ._api import ( + maybe_mk_fsp_shm, + Fsp, +) from ._engine import cascade +from ._volume import ( + dolla_vlm, + flow_rates, + tina_vwap, +) -__all__ = ['cascade'] +__all__: list[str] = [ + 'cascade', + 'maybe_mk_fsp_shm', + 'Fsp', + 'dolla_vlm', + 'flow_rates', + 'tina_vwap', +] async def latency( diff --git a/piker/data/types.py b/piker/types.py similarity index 100% rename from piker/data/types.py rename to piker/types.py diff --git a/piker/ui/_display.py b/piker/ui/_display.py index 47704e3f..5f9e2cb9 100644 --- a/piker/ui/_display.py +++ b/piker/ui/_display.py @@ -36,25 +36,27 @@ import pyqtgraph as pg from msgspec import field # from .. import brokers -from ..accounting import ( +from piker.accounting import ( MktPair, ) -from ..data import ( +from piker.types import Struct +from piker.data import ( open_feed, Feed, Flume, + open_sample_stream, + ShmArray, ) -from ..data.ticktools import ( +from piker.data.ticktools import ( _tick_groups, _auction_ticks, ) -from ..data.types import Struct -from ..data._sharedmem import ( - ShmArray, -) -from ..data._sampling import ( - open_sample_stream, +from piker.toolz import ( + pg_profile_enabled, + ms_slower_then, + Profiler, ) +from piker.log import get_logger # from ..data._source import tf_in_1s from ._axes import YAxisLabel from ._chart import ( @@ -79,12 +81,6 @@ from .order_mode import ( open_order_mode, OrderMode, ) -from ..toolz import ( - pg_profile_enabled, - ms_slower_then, - Profiler, -) -from ..log import get_logger if TYPE_CHECKING: from ._interaction import ChartView diff --git a/piker/ui/_editors.py b/piker/ui/_editors.py index df881314..4e489f0f 100644 --- a/piker/ui/_editors.py +++ b/piker/ui/_editors.py @@ -42,10 +42,10 @@ from pyqtgraph import functions as fn from PyQt5.QtCore import QPointF import numpy as np +from piker.types import Struct from ._style import hcolor, _font from ._lines import LevelLine from ..log import get_logger -from ..data.types import Struct if TYPE_CHECKING: from ._chart import GodWidget diff --git a/piker/ui/_event.py b/piker/ui/_event.py index 3edfb2ff..b83dd578 100644 --- a/piker/ui/_event.py +++ b/piker/ui/_event.py @@ -30,7 +30,7 @@ from PyQt5.QtWidgets import ( QGraphicsSceneMouseEvent as gs_mouse, ) -from ..data.types import Struct +from piker.types import Struct MOUSE_EVENTS = { diff --git a/piker/ui/_fsp.py b/piker/ui/_fsp.py index bcbd95d4..23cec162 100644 --- a/piker/ui/_fsp.py +++ b/piker/ui/_fsp.py @@ -36,16 +36,27 @@ from tractor.trionics import maybe_open_context import trio from trio_typing import TaskStatus -from piker.data.types import Struct -from ._axes import PriceAxis -from ..calc import humanize -from ..data._sharedmem import ( +from piker.accounting import MktPair +from piker.fsp import ( + cascade, + maybe_mk_fsp_shm, + Fsp, + dolla_vlm, + flow_rates, +) +from piker.data import ( + Flume, ShmArray, +) +from piker.data._sharedmem import ( _Token, try_read, ) -from ..data.feed import Flume -from ..accounting import MktPair +from piker.log import get_logger +from piker.toolz import Profiler +from piker.types import Struct +from ._axes import PriceAxis +from ..calc import humanize from ._chart import ( ChartPlotWidget, LinkedSplits, @@ -55,18 +66,6 @@ from ._forms import ( mk_form, open_form_input_handling, ) -from ..fsp._api import ( - maybe_mk_fsp_shm, - Fsp, -) -from ..fsp import cascade -from ..fsp._volume import ( - # tina_vwap, - dolla_vlm, - flow_rates, -) -from ..log import get_logger -from ..toolz import Profiler log = get_logger(__name__) diff --git a/piker/ui/_position.py b/piker/ui/_position.py index 8b07d80a..1e4895f9 100644 --- a/piker/ui/_position.py +++ b/piker/ui/_position.py @@ -30,40 +30,34 @@ from typing import ( TYPE_CHECKING, ) - # from PyQt5.QtWidgets import QStyle # from PyQt5.QtGui import ( # QIcon, QPixmap, QColor # ) from pyqtgraph import functions as fn +from piker.calc import ( + humanize, + pnl, + puterize, +) +from piker.accounting import ( + Allocator, + Position, + MktPair, +) +from piker.accounting._mktinfo import _derivs +from piker.types import Struct +from piker.data import ( + iterticks, + Feed, + Flume, +) from ._annotate import LevelMarker from ._anchors import ( pp_tight_and_right, # wanna keep it straight in the long run gpath_pin, ) -from ..calc import ( - humanize, - pnl, - puterize, -) -from ..accounting import ( - Allocator, - MktPair, -) -from ..accounting import ( - Position, -) -from ..accounting._mktinfo import ( - _derivs, -) - -from ..data import ( - iterticks, - Feed, - Flume, -) -from ..data.types import Struct from ._label import Label from ._lines import LevelLine, order_line from ._style import _font diff --git a/piker/ui/order_mode.py b/piker/ui/order_mode.py index ddc2d6f0..14d8b821 100644 --- a/piker/ui/order_mode.py +++ b/piker/ui/order_mode.py @@ -36,25 +36,29 @@ import tractor import trio from PyQt5.QtCore import Qt -from .. import config -from ..accounting import ( +from piker import config +from piker.accounting import ( Allocator, Position, mk_allocator, MktPair, Symbol, ) -from ..clearing._client import ( +from piker.clearing import ( open_ems, OrderClient, ) -from ._style import _font -from ..data.feed import ( +from piker.clearing._messages import ( + Order, + Status, + BrokerdPosition, +) +from piker.data import ( Feed, Flume, ) -from ..data.types import Struct -from ..log import get_logger +from piker.types import Struct +from piker.log import get_logger from ._editors import LineEditor, ArrowEditor from ._lines import order_line, LevelLine from ._position import ( @@ -63,14 +67,7 @@ from ._position import ( ) from ._forms import FieldsForm from ._window import MultiStatus -from ..clearing._messages import ( - # Cancel, - Order, - Status, - # BrokerdOrder, - # BrokerdStatus, - BrokerdPosition, -) +from ._style import _font from ._forms import open_form_input_handling from ._notify import notify_from_ems_status_msg diff --git a/piker/ui/view_mode.py b/piker/ui/view_mode.py index 191b62b9..a9a093d0 100644 --- a/piker/ui/view_mode.py +++ b/piker/ui/view_mode.py @@ -30,7 +30,7 @@ import numpy as np import pendulum import pyqtgraph as pg -from ..data.types import Struct +from piker.types import Struct from ..data._timeseries import slice_from_time from ..log import get_logger from ..toolz import Profiler