Bleh, move `.data.types` back up to top level pkg

Since it's depended on by `.data` stuff as well as pretty much
everything else, makes more sense to expose it as a top level module
(and maybe eventually as a subpkg as we add to it).
account_tests
Tyler Goodlet 2023-08-05 15:57:10 -04:00
parent 5d86d336f2
commit 5ed8544fd1
37 changed files with 159 additions and 129 deletions

View File

@ -50,6 +50,8 @@ from ._allocate import (
mk_allocator, mk_allocator,
Allocator, Allocator,
) )
from .models import CostModel
log = get_logger(__name__) log = get_logger(__name__)
@ -57,6 +59,7 @@ __all__ = [
'Account', 'Account',
'Allocator', 'Allocator',
'Asset', 'Asset',
'CostModel',
'MktPair', 'MktPair',
'Position', 'Position',
'Symbol', 'Symbol',

View File

@ -25,7 +25,7 @@ from bidict import bidict
from ._pos import Position from ._pos import Position
from . import MktPair from . import MktPair
from ..data.types import Struct from piker.types import Struct
_size_units = bidict({ _size_units = bidict({

View File

@ -37,8 +37,8 @@ from pendulum import (
) )
import tomli_w # for fast ledger writing import tomli_w # for fast ledger writing
from .. import config from piker.types import Struct
from ..data.types import Struct from piker import config
from ..log import get_logger from ..log import get_logger
from .calc import ( from .calc import (
iter_by_dt, iter_by_dt,

View File

@ -36,7 +36,7 @@ from typing import (
Literal, Literal,
) )
from ..data.types import Struct from piker.types import Struct
# TODO: make these literals.. # TODO: make these literals..

View File

@ -58,8 +58,8 @@ from .. import config
from ..clearing._messages import ( from ..clearing._messages import (
BrokerdPosition, BrokerdPosition,
) )
from ..data.types import Struct from piker.types import Struct
from ..data._symcache import SymbologyCache from piker.data._symcache import SymbologyCache
from ..log import get_logger from ..log import get_logger
log = get_logger(__name__) log = get_logger(__name__)

View File

@ -422,7 +422,12 @@ def ledger_to_dfs(
# fdf = df.filter(pred) # 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( dfs: dict[str, pl.DataFrame] = ldf.partition_by(
'bs_mktid', 'bs_mktid',
as_dict=True, as_dict=True,
@ -435,14 +440,9 @@ def ledger_to_dfs(
# covert to lazy form (since apparently we might need it # covert to lazy form (since apparently we might need it
# eventually ...) # eventually ...)
df = dfs[key] df: pl.DataFrame = dfs[key]
ldf = df.lazy() ldf: pl.LazyFrame = 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]
df = dfs[key] = ldf.with_columns([ df = dfs[key] = ldf.with_columns([
@ -688,4 +688,10 @@ def ledger_to_dfs(
last_ppu: float = ppu last_ppu: float = ppu
last_cumsize: float = cumsize 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 return dfs

View File

@ -53,7 +53,7 @@ from piker.accounting import (
Asset, Asset,
digits_to_dec, digits_to_dec,
) )
from piker.data.types import Struct from piker.types import Struct
from piker.data import def_iohlcv_fields from piker.data import def_iohlcv_fields
from piker.brokers import ( from piker.brokers import (
resproc, resproc,

View File

@ -58,7 +58,7 @@ from piker.accounting import (
MktPair, MktPair,
unpack_fqme, unpack_fqme,
) )
from piker.data.types import Struct from piker.types import Struct
from piker.data.validate import FeedInit from piker.data.validate import FeedInit
from piker.data._web_bs import ( from piker.data._web_bs import (
open_autorecon_ws, open_autorecon_ws,

View File

@ -26,7 +26,7 @@ from decimal import Decimal
from msgspec import field from msgspec import field
from piker.data.types import Struct from piker.types import Struct
# API endpoint paths by venue / sub-API # API endpoint paths by venue / sub-API

View File

@ -49,6 +49,7 @@ from ib_insync.objects import (
) )
from piker import config from piker import config
from piker.types import Struct
from piker.accounting import ( from piker.accounting import (
Position, Position,
Transaction, Transaction,
@ -62,7 +63,6 @@ from piker.accounting import (
from piker.data import ( from piker.data import (
open_symcache, open_symcache,
SymbologyCache, SymbologyCache,
Struct,
) )
from piker.clearing._messages import ( from piker.clearing._messages import (
Order, Order,

View File

@ -39,8 +39,8 @@ from ib_insync.objects import (
CommissionReport, CommissionReport,
) )
from piker.types import Struct
from piker.data import ( from piker.data import (
Struct,
SymbologyCache, SymbologyCache,
) )
from piker.accounting import ( from piker.accounting import (

View File

@ -46,7 +46,7 @@ from piker.brokers._util import (
DataThrottle, DataThrottle,
DataUnavailable, DataUnavailable,
) )
from piker.data.types import Struct from piker.types import Struct
from piker.data.validate import FeedInit from piker.data.validate import FeedInit
from piker.data._web_bs import open_autorecon_ws, NoBsWs from piker.data._web_bs import open_autorecon_ws, NoBsWs
from .api import ( from .api import (

View File

@ -34,9 +34,9 @@ from piker.accounting import (
TransactionLedger, TransactionLedger,
# MktPair, # MktPair,
) )
from piker.types import Struct
from piker.data import ( from piker.data import (
SymbologyCache, SymbologyCache,
Struct,
) )
from .api import ( from .api import (
log, log,

View File

@ -33,7 +33,7 @@ from piker.brokers import (
open_cached_client, open_cached_client,
SymbolNotFound, SymbolNotFound,
) )
from piker.data.types import Struct from piker.types import Struct
from piker.accounting._mktinfo import ( from piker.accounting._mktinfo import (
Asset, Asset,
MktPair, MktPair,

View File

@ -64,7 +64,7 @@ from piker._cacheables import (
) )
from piker.log import get_logger from piker.log import get_logger
from piker.data.validate import FeedInit 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 import def_iohlcv_fields
from piker.data._web_bs import ( from piker.data._web_bs import (
open_autorecon_ws, open_autorecon_ws,

View File

@ -27,13 +27,28 @@ from ._ems import (
open_brokerd_dialog, open_brokerd_dialog,
) )
from ._util import OrderDialogs 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__ = [ __all__ = [
'FeeModel',
'open_ems', 'open_ems',
'OrderClient', 'OrderClient',
'open_brokerd_dialog', 'open_brokerd_dialog',
'OrderDialogs', 'OrderDialogs',
'Order',
'Status',
'Cancel',
'BrokerdPosition'
] ]

View File

@ -30,7 +30,7 @@ from tractor.trionics import broadcast_receiver
from ._util import ( from ._util import (
log, # sub-sys logger log, # sub-sys logger
) )
from ..data.types import Struct from piker.types import Struct
from ..service import maybe_open_emsd from ..service import maybe_open_emsd
from ._messages import ( from ._messages import (
Order, Order,

View File

@ -51,9 +51,9 @@ from ..accounting._mktinfo import (
unpack_fqme, unpack_fqme,
dec_digits, dec_digits,
) )
from piker.types import Struct
from ..ui._notify import notify_from_ems_status_msg from ..ui._notify import notify_from_ems_status_msg
from ..data import iterticks from ..data import iterticks
from ..data.types import Struct
from ._messages import ( from ._messages import (
Order, Order,
Status, Status,

View File

@ -28,7 +28,7 @@ from typing import (
from msgspec import field from msgspec import field
from ..data.types import Struct from piker.types import Struct
# TODO: a composite for tracking msg flow on 2-legged # TODO: a composite for tracking msg flow on 2-legged

View File

@ -40,21 +40,22 @@ import tractor
from piker.brokers import get_brokermod from piker.brokers import get_brokermod
from piker.accounting import ( from piker.accounting import (
Position,
Account, Account,
CostModel,
MktPair,
Position,
Transaction, Transaction,
TransactionLedger, TransactionLedger,
open_trade_ledger,
open_account, open_account,
MktPair, open_trade_ledger,
unpack_fqme, unpack_fqme,
) )
from piker.data import ( from piker.data import (
open_feed,
iterticks,
Struct, Struct,
open_symcache,
SymbologyCache, SymbologyCache,
iterticks,
open_feed,
open_symcache,
) )
from ._util import ( from ._util import (
log, # sub-sys logger log, # sub-sys logger
@ -83,6 +84,7 @@ class PaperBoi(Struct):
ems_trades_stream: tractor.MsgStream ems_trades_stream: tractor.MsgStream
acnt: Account acnt: Account
ledger: TransactionLedger ledger: TransactionLedger
fees: CostModel
# map of paper "live" orders which be used # map of paper "live" orders which be used
# to simulate fills based on paper engine settings # to simulate fills based on paper engine settings

View File

@ -25,7 +25,7 @@ from ..log import (
get_logger, get_logger,
get_console_log, get_console_log,
) )
from piker.data.types import Struct from piker.types import Struct
subsys: str = 'piker.clearing' subsys: str = 'piker.clearing'
log = get_logger(subsys) log = get_logger(subsys)

View File

@ -44,7 +44,7 @@ from ._symcache import (
open_symcache, open_symcache,
get_symcache, get_symcache,
) )
from .types import Struct from ._sampling import open_sample_stream
__all__: list[str] = [ __all__: list[str] = [
@ -60,7 +60,8 @@ __all__: list[str] = [
'def_iohlcv_fields', 'def_iohlcv_fields',
'def_ohlcv_fields', 'def_ohlcv_fields',
'open_symcache', 'open_symcache',
'open_sample_stream',
'get_symcache', 'get_symcache',
'SymbologyCache', 'SymbologyCache',
'Struct', 'types',
] ]

View File

@ -34,7 +34,7 @@ import tractor
from ._util import log from ._util import log
from ._source import def_iohlcv_fields from ._source import def_iohlcv_fields
from .types import Struct from piker.types import Struct
def cuckoff_mantracker(): def cuckoff_mantracker():

View File

@ -47,11 +47,11 @@ from msgspec import field
from piker.log import get_logger from piker.log import get_logger
from piker import config from piker import config
from piker.types import Struct
from piker.brokers import ( from piker.brokers import (
open_cached_client, open_cached_client,
get_brokermod, get_brokermod,
) )
from .types import Struct
if TYPE_CHECKING: if TYPE_CHECKING:
from ..accounting import ( from ..accounting import (

View File

@ -50,8 +50,8 @@ from trio_websocket._impl import (
ConnectionTimeout, ConnectionTimeout,
) )
from piker.types import Struct
from ._util import log from ._util import log
from .types import Struct
class NoBsWs: class NoBsWs:

View File

@ -50,15 +50,21 @@ from tractor.trionics import (
gather_contexts, gather_contexts,
) )
from ..brokers import get_brokermod from piker.accounting import (
from ..calc import humanize 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 ( from ._util import (
log, log,
get_console_log, get_console_log,
) )
from ..service import (
maybe_spawn_brokerd,
)
from .flows import Flume from .flows import Flume
from .validate import ( from .validate import (
FeedInit, FeedInit,
@ -68,12 +74,6 @@ from .history import (
manage_history, manage_history,
) )
from .ingest import get_ingestormod from .ingest import get_ingestormod
from .types import Struct
from ..accounting import (
MktPair,
unpack_fqme,
)
from ..ui import _search
from ._sampling import ( from ._sampling import (
sample_and_broadcast, sample_and_broadcast,
uniform_rate_send, uniform_rate_send,

View File

@ -30,8 +30,7 @@ import tractor
import pendulum import pendulum
import numpy as np import numpy as np
from ..accounting import MktPair from piker.types import Struct
from .types import Struct
from ._sharedmem import ( from ._sharedmem import (
attach_shm_array, attach_shm_array,
ShmArray, ShmArray,
@ -39,7 +38,7 @@ from ._sharedmem import (
) )
if TYPE_CHECKING: if TYPE_CHECKING:
# from pyqtgraph import PlotItem from ..accounting import MktPair
from .feed import Feed from .feed import Feed
@ -189,6 +188,7 @@ class Flume(Struct):
''' '''
mkt_msg = msg.pop('mkt') mkt_msg = msg.pop('mkt')
from ..accounting import MktPair # cycle otherwise..
mkt = MktPair.from_msg(mkt_msg) mkt = MktPair.from_msg(mkt_msg)
return cls(mkt=mkt, **msg) return cls(mkt=mkt, **msg)

View File

@ -18,6 +18,7 @@ Data feed synchronization protocols, init msgs, and general
data-provider-backend-agnostic schema definitions. data-provider-backend-agnostic schema definitions.
''' '''
from __future__ import annotations
from decimal import Decimal from decimal import Decimal
from pprint import pformat from pprint import pformat
from types import ModuleType from types import ModuleType
@ -28,8 +29,8 @@ from typing import (
from msgspec import field from msgspec import field
from .types import Struct from piker.types import Struct
from ..accounting import ( from piker.accounting import (
Asset, Asset,
MktPair, MktPair,
) )

View File

@ -22,9 +22,25 @@ from typing import AsyncIterator
import numpy as np import numpy as np
from ._api import (
maybe_mk_fsp_shm,
Fsp,
)
from ._engine import cascade 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( async def latency(

View File

@ -36,25 +36,27 @@ import pyqtgraph as pg
from msgspec import field from msgspec import field
# from .. import brokers # from .. import brokers
from ..accounting import ( from piker.accounting import (
MktPair, MktPair,
) )
from ..data import ( from piker.types import Struct
from piker.data import (
open_feed, open_feed,
Feed, Feed,
Flume, Flume,
open_sample_stream,
ShmArray,
) )
from ..data.ticktools import ( from piker.data.ticktools import (
_tick_groups, _tick_groups,
_auction_ticks, _auction_ticks,
) )
from ..data.types import Struct from piker.toolz import (
from ..data._sharedmem import ( pg_profile_enabled,
ShmArray, ms_slower_then,
) Profiler,
from ..data._sampling import (
open_sample_stream,
) )
from piker.log import get_logger
# from ..data._source import tf_in_1s # from ..data._source import tf_in_1s
from ._axes import YAxisLabel from ._axes import YAxisLabel
from ._chart import ( from ._chart import (
@ -79,12 +81,6 @@ from .order_mode import (
open_order_mode, open_order_mode,
OrderMode, OrderMode,
) )
from ..toolz import (
pg_profile_enabled,
ms_slower_then,
Profiler,
)
from ..log import get_logger
if TYPE_CHECKING: if TYPE_CHECKING:
from ._interaction import ChartView from ._interaction import ChartView

View File

@ -42,10 +42,10 @@ from pyqtgraph import functions as fn
from PyQt5.QtCore import QPointF from PyQt5.QtCore import QPointF
import numpy as np import numpy as np
from piker.types import Struct
from ._style import hcolor, _font from ._style import hcolor, _font
from ._lines import LevelLine from ._lines import LevelLine
from ..log import get_logger from ..log import get_logger
from ..data.types import Struct
if TYPE_CHECKING: if TYPE_CHECKING:
from ._chart import GodWidget from ._chart import GodWidget

View File

@ -30,7 +30,7 @@ from PyQt5.QtWidgets import (
QGraphicsSceneMouseEvent as gs_mouse, QGraphicsSceneMouseEvent as gs_mouse,
) )
from ..data.types import Struct from piker.types import Struct
MOUSE_EVENTS = { MOUSE_EVENTS = {

View File

@ -36,16 +36,27 @@ from tractor.trionics import maybe_open_context
import trio import trio
from trio_typing import TaskStatus from trio_typing import TaskStatus
from piker.data.types import Struct from piker.accounting import MktPair
from ._axes import PriceAxis from piker.fsp import (
from ..calc import humanize cascade,
from ..data._sharedmem import ( maybe_mk_fsp_shm,
Fsp,
dolla_vlm,
flow_rates,
)
from piker.data import (
Flume,
ShmArray, ShmArray,
)
from piker.data._sharedmem import (
_Token, _Token,
try_read, try_read,
) )
from ..data.feed import Flume from piker.log import get_logger
from ..accounting import MktPair from piker.toolz import Profiler
from piker.types import Struct
from ._axes import PriceAxis
from ..calc import humanize
from ._chart import ( from ._chart import (
ChartPlotWidget, ChartPlotWidget,
LinkedSplits, LinkedSplits,
@ -55,18 +66,6 @@ from ._forms import (
mk_form, mk_form,
open_form_input_handling, 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__) log = get_logger(__name__)

View File

@ -30,40 +30,34 @@ from typing import (
TYPE_CHECKING, TYPE_CHECKING,
) )
# from PyQt5.QtWidgets import QStyle # from PyQt5.QtWidgets import QStyle
# from PyQt5.QtGui import ( # from PyQt5.QtGui import (
# QIcon, QPixmap, QColor # QIcon, QPixmap, QColor
# ) # )
from pyqtgraph import functions as fn 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 ._annotate import LevelMarker
from ._anchors import ( from ._anchors import (
pp_tight_and_right, # wanna keep it straight in the long run pp_tight_and_right, # wanna keep it straight in the long run
gpath_pin, 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 ._label import Label
from ._lines import LevelLine, order_line from ._lines import LevelLine, order_line
from ._style import _font from ._style import _font

View File

@ -36,25 +36,29 @@ import tractor
import trio import trio
from PyQt5.QtCore import Qt from PyQt5.QtCore import Qt
from .. import config from piker import config
from ..accounting import ( from piker.accounting import (
Allocator, Allocator,
Position, Position,
mk_allocator, mk_allocator,
MktPair, MktPair,
Symbol, Symbol,
) )
from ..clearing._client import ( from piker.clearing import (
open_ems, open_ems,
OrderClient, OrderClient,
) )
from ._style import _font from piker.clearing._messages import (
from ..data.feed import ( Order,
Status,
BrokerdPosition,
)
from piker.data import (
Feed, Feed,
Flume, Flume,
) )
from ..data.types import Struct from piker.types import Struct
from ..log import get_logger from piker.log import get_logger
from ._editors import LineEditor, ArrowEditor from ._editors import LineEditor, ArrowEditor
from ._lines import order_line, LevelLine from ._lines import order_line, LevelLine
from ._position import ( from ._position import (
@ -63,14 +67,7 @@ from ._position import (
) )
from ._forms import FieldsForm from ._forms import FieldsForm
from ._window import MultiStatus from ._window import MultiStatus
from ..clearing._messages import ( from ._style import _font
# Cancel,
Order,
Status,
# BrokerdOrder,
# BrokerdStatus,
BrokerdPosition,
)
from ._forms import open_form_input_handling from ._forms import open_form_input_handling
from ._notify import notify_from_ems_status_msg from ._notify import notify_from_ems_status_msg

View File

@ -30,7 +30,7 @@ import numpy as np
import pendulum import pendulum
import pyqtgraph as pg import pyqtgraph as pg
from ..data.types import Struct from piker.types import Struct
from ..data._timeseries import slice_from_time from ..data._timeseries import slice_from_time
from ..log import get_logger from ..log import get_logger
from ..toolz import Profiler from ..toolz import Profiler