Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
242 commits
Select commit Hold shift + click to select a range
89cedee
Init msg keys are always lower case
goodboy Nov 16, 2022
e5df002
TOSQUASH? revert sym.lower() usage?
goodboy Nov 16, 2022
e07b91e
Copy timestamps from source to FSP dest buffer
goodboy Nov 26, 2022
a7f0b36
Add default YAxisLable.x_offset: int`
goodboy Nov 13, 2022
d6a47ac
Add `Axis.add_sticky()` for creating axis labels
goodboy Nov 14, 2022
3b667b4
Simplify OHLC graphic color instance var name
goodboy Nov 14, 2022
b0dd7cd
Initial chart widget adjustments for agg feeds
goodboy Nov 14, 2022
0a3a73c
Passthrough fqsns list directly to `.load_symbols()`
goodboy Nov 14, 2022
ad8dc36
Allocate our internal `Axis` subtype in our `PlotItem` override
goodboy Nov 14, 2022
abb3579
Adjust L1 labels to expect `.pi: PlotItem`
goodboy Nov 14, 2022
9c08ad1
Pass plotitem to axis from cursor
goodboy Nov 14, 2022
e7f4340
Only update pnl label on quotes with an fqsn match
goodboy Nov 14, 2022
46d6bb0
Drop the legacy `relayed_from` cruft from our view box
goodboy Nov 14, 2022
e94620b
Adjust search to handle multi-sym results
goodboy Nov 15, 2022
5cec6a5
Only add plot to cursor set if not an overlay
goodboy Nov 15, 2022
99bba12
Make graphics-update-loop multi-sym aware B)
goodboy Nov 15, 2022
d03a566
Adjust FSP UI/mgmt apis to be `Flume` oriented
goodboy Nov 15, 2022
9529dd0
Drop tick frame builder loop for now
goodboy Nov 15, 2022
df9cc0d
Make `PlotItemOverlay` add items inwards->out
goodboy Nov 16, 2022
21984f6
Assign pnl calc output for use when debugging
goodboy Nov 16, 2022
857cc96
Define a single `ChartPlotWidget.feed: Feed` for pause/resume
goodboy Nov 16, 2022
67ad292
Factor setup loop, 1 FSP chain, colors, throttling
goodboy Nov 16, 2022
11b254b
Brighter last OHLC graphics datum by default
goodboy Nov 16, 2022
fe4a69b
Update/improve qt screen script
goodboy Nov 17, 2022
5a9e985
Factor info print into func
goodboy Nov 17, 2022
18857ac
Expect and update from by-type tick frames
goodboy Nov 17, 2022
0945033
Move all pre-path formatting routines to `._pathops`, proto formatter…
goodboy Nov 22, 2022
4c79938
Max out per symbol throttle @ 22Hz
goodboy Nov 22, 2022
d6ae75d
Add graphics incr-updated "formatter" subsys
goodboy Nov 22, 2022
d710454
Make curve graphics timeframe agnostic
goodboy Nov 23, 2022
c6b0eaa
Mask profile points and drop rect `.united()` attempts
goodboy Nov 23, 2022
437fc51
Drop px-cache-resets, failed try at path appends
goodboy Nov 23, 2022
b92ff7c
Pass `Flume`s throughout FSP-ui and charting APIs
goodboy Nov 24, 2022
42e0048
Adjust order mode to use `Flume.get_index()`
goodboy Nov 24, 2022
47b9e59
Rename `Flow` -> `Viz`
goodboy Nov 24, 2022
b8622d8
Rename `.ui._flows.py` -> `.ui._render.py`
goodboy Nov 24, 2022
6ec1136
Move `ui._compression`/`._pathops` to `.data` subpkg
goodboy Nov 24, 2022
b0a8728
Go back to hard-coded index field
goodboy Nov 25, 2022
f5f476f
`Order.symbol` is a `str`..
goodboy Nov 25, 2022
ba43b75
Add breakpoint on -ve range for now
goodboy Nov 28, 2022
0b596bf
Make `Viz.slice_from_time()` take input array
goodboy Nov 28, 2022
e3b9926
Add `Viz.bars_range()` (moved from chart API)
goodboy Nov 28, 2022
05a7a06
Pepper render routines with time-slice calls
goodboy Nov 28, 2022
99b1230
First attempt, field-index agnostic formatting
goodboy Nov 28, 2022
a9da114
TOSQUASH: f3d757c2 (flow->viz)
goodboy Nov 28, 2022
301bfa2
Simplify formatter update methodology
goodboy Nov 29, 2022
fc99314
Attempt to make `.default_view()` time-index ready
goodboy Nov 29, 2022
ea36849
Facepalm: pass correct flume to each FSP chart group..
goodboy Nov 29, 2022
7e3a172
TOSQUASH: 2dc706aa (.default_view w time)
goodboy Nov 29, 2022
fd3c72b
Expect `index_field: str` in all graphics objects
goodboy Nov 30, 2022
a63dd6c
Add `Viz.index_field: str`, pass to graphics objs
goodboy Nov 30, 2022
77c472f
Fix `.default_view()` to view-left-of-data
goodboy Nov 30, 2022
1d3b03c
TOSQUASH: f5dcf1dc (viz index field)
goodboy Nov 30, 2022
f980e2e
Call `Viz.bars_range()` from display loop
goodboy Nov 30, 2022
4835677
Comment out bps for time indexing
goodboy Nov 30, 2022
733a6e3
Don't disable non-enabled vlm chart y-autoranging
goodboy Nov 30, 2022
6ec30a2
Enable/disable vlm chart yranging (TO SQUASH)
goodboy Nov 30, 2022
f403deb
Explicitly enable chart widget yranging in display init
goodboy Nov 30, 2022
366310b
Drop diff state tracking in formatter
goodboy Nov 30, 2022
7c863b5
Move path ops routines to top of mod
goodboy Nov 30, 2022
e85e9f7
Move old label sizing cruft to label mod
goodboy Nov 30, 2022
a7cebc0
Fix from-time index slicing?
goodboy Nov 30, 2022
1144b3f
Look up "index field" in display cycles
goodboy Nov 30, 2022
ce8279b
Rename `.ui._pathops.py` -> `.ui._formatters.py
goodboy Nov 30, 2022
eda7b7f
Move qpath-ops routines back to separate mod
goodboy Nov 30, 2022
87e47f9
Move (unused) path gen routines to `.ui._pathops`
goodboy Dec 1, 2022
3cebfb0
Go with explicit `.data._m4` mod name
goodboy Dec 1, 2022
c0a5213
Facepalm: actually return latest index on time slice fail..
goodboy Dec 1, 2022
1ba92a0
TOSQUASH: 552a8c298cd (return index for arrow..)
goodboy Dec 1, 2022
cbd2c73
Facepalm: put graphics cycle in `do_ds: bool` block..
goodboy Dec 2, 2022
a681cd9
Markup OHLC->path gen with `numba` issue #
goodboy Dec 2, 2022
342b3e5
Facepalm**2: fix array-read-slice, like actually..
goodboy Dec 2, 2022
7a71282
Delegate formatter `.index_field` to the parent `Viz`
goodboy Dec 3, 2022
a4eb2d0
Drop `index_field` input to renders, add `.read()` profiling
goodboy Dec 3, 2022
0dbfa2f
Move `Flume.slice_from_time()` to `.data._pathops` mod func
goodboy Dec 3, 2022
3d16261
Use step size to determine last datum bar gap
goodboy Dec 3, 2022
81b7515
Use step size to determine bar gaps
goodboy Dec 3, 2022
84b6ec0
Use index (time) step to calc OHLC bar/line uppx threshold
goodboy Dec 3, 2022
7e7748c
Rewrite `slice_from_time()` using `numba`
goodboy Dec 3, 2022
0dc73ee
Adjust all `slice_from_time()` calls to not expect mask
goodboy Dec 3, 2022
a893178
Flip over to epoch-time based x-domain indexing
goodboy Dec 4, 2022
32bac4f
Make `.default_view()` time step aware
goodboy Dec 5, 2022
90ac9a8
Use uniform step arithmetic in `slice_from_time()`
goodboy Dec 6, 2022
c74fc88
Drop `_slice_from_time()`
goodboy Dec 6, 2022
a8f7f82
Drop old breakpoint
goodboy Dec 6, 2022
37df429
Drop `Flume.view_data()`
goodboy Dec 6, 2022
59f85d2
Add `.x_last()` meth to flow graphics
goodboy Dec 7, 2022
d16290c
Add gap detection for `stop_t`, though only report atm
goodboy Dec 7, 2022
bc5fefe
Re-implement `.default_view()` on `Viz`
goodboy Dec 7, 2022
97bbdd2
Delegate to `Viz.default_view()` on chart
goodboy Dec 7, 2022
4ad9d52
Use `Curve.x_last()` for zoom focal point
goodboy Dec 7, 2022
163d41e
Draw last datums on boot
goodboy Dec 7, 2022
3cccb65
Implement `stop_t` gap adjustments; the good lord said it is the problem
goodboy Dec 8, 2022
8f40ea3
Block out `do_print` stuff inside `Viz.maxmin()`
goodboy Dec 8, 2022
234864b
Add back `.default_view()` slice logic for `int` indexing
goodboy Dec 8, 2022
45463fd
Drop passing `render_data` to `Curve.draw_last_datum()`
goodboy Dec 8, 2022
a1ae051
Slicec to an extra index around each timestamp input
goodboy Dec 8, 2022
1f8a365
Add some commented debug prints for default fmtr
goodboy Dec 8, 2022
7aaa782
Restore coord-cache resetting
goodboy Dec 8, 2022
ecf7898
Handle time-indexing for fill arrows
goodboy Dec 9, 2022
e733afc
Fix formatter xy ndarray first prepend case
goodboy Dec 13, 2022
d69a105
Right, do index lookup for int-index as well..
goodboy Dec 13, 2022
fc226ae
Drop unused `read_src_from_key: bool` to `.format_to_1d()`
goodboy Dec 13, 2022
36e17be
Fix line -> bars on 6x UPPX
goodboy Dec 14, 2022
66cfaa9
Move `Viz` layer to new `.ui` mod
goodboy Dec 14, 2022
4caf121
Move `DisplayState.incr_info()` -> `Viz`
goodboy Dec 14, 2022
08c288c
Add global `i_step` per overlay to `DisplayState`
goodboy Dec 14, 2022
4214270
Make `LinearRegion` link using epoch-time index
goodboy Dec 15, 2022
ecb60c9
Ugh, use `bool` flag to determine index field..
goodboy Dec 15, 2022
4797b91
Set `path_arrays_from_ohlc(use_time_index=True)` on epoch indexing
goodboy Dec 16, 2022
7a2bdfb
`Viz._index_field` a `typing.Literal[str]`
goodboy Dec 16, 2022
0d10ad6
Adjust OHLC bar x-offsets to be time span matched
goodboy Dec 16, 2022
4941130
Add `IncrementalFormatter.x_offset: np.ndarray`
goodboy Dec 16, 2022
5146d37
Align step curves the same as OHLC bars
goodboy Dec 16, 2022
9e3f59c
Use array-`int`-indexing on single feed
goodboy Dec 16, 2022
a0156f0
Make `Viz.incr_info()` sample rate agnostic
goodboy Dec 17, 2022
0d31f52
Add `ChartPlotWidget.main_viz: Viz` convenience `@property`
goodboy Dec 17, 2022
44e7170
Drop coordinate cacheing from `BarItems`, causes weird jitter on pan
goodboy Dec 19, 2022
747dee2
Add type annots to vars inside `Render.render()`
goodboy Dec 19, 2022
f691bf3
Fix gap detection on RHS; always bin-search on overshot time range
goodboy Dec 19, 2022
5e75b46
Rename `reset` -> `reset_cache`
goodboy Dec 19, 2022
6da6881
Make `Viz.incr_info()` do treading with time-index, and appending wit…
goodboy Dec 19, 2022
3f24805
Make `.increment_view()` take in a `datums: int` and always scale it …
goodboy Dec 19, 2022
4dc8051
Fix overlayed slow chart "treading"
goodboy Dec 19, 2022
6cd61c3
Enable the experimental `QPrivatePath` functionality from latest `pyq…
goodboy Dec 19, 2022
7455fac
Use `np.diff()` on last 16 samples instead of only last datum pair
goodboy Dec 21, 2022
cca3162
Add commented append slice-len sanity check
goodboy Dec 22, 2022
83cc1d2
Fix x-axis labelling when using an epoch domain
goodboy Dec 23, 2022
3948099
Simplify L1 labels for multicharts
goodboy Dec 23, 2022
2de8209
Don't set y-axis label colors to curve's, use the default from global…
goodboy Dec 23, 2022
aa67bcc
Set cursor label color to "bracket"
goodboy Dec 23, 2022
617baab
TOSQUASH: 84f19308 (l1 rework)
goodboy Dec 23, 2022
d437cf5
Handle empty `indexes` input edge case..
goodboy Dec 23, 2022
e2ada36
Drop l1 labels attr from chart widget
goodboy Dec 23, 2022
d9df39c
Just-offset-from-arrow-marker on slow chart
goodboy Dec 24, 2022
ccb13bc
Add a parent-type for graphics: `FlowGraphic`
goodboy Dec 26, 2022
ce07454
Use static `L1Label._x_br_offset` as l1 label length
goodboy Dec 27, 2022
a7aba17
Use left-style index search on RHS scan as well
goodboy Dec 27, 2022
e3d8c19
Drop edge case from `slice_from_time()`
goodboy Dec 28, 2022
76a50ac
Make `FlowGraphic.x_last()` be optionally `None`
goodboy Dec 28, 2022
6796021
Further fixes `Viz.default_view()` and `.index_step()`
goodboy Dec 28, 2022
3c885a0
Drop `._index_step` from formatters and instead defer to `Viz.index_s…
goodboy Dec 28, 2022
01222a4
Modernize optional path variable type annots
goodboy Dec 28, 2022
75bb065
Mouse interaction tweaks
goodboy Dec 28, 2022
04b4750
Repair auto-y-ranging to always include L1 spread
goodboy Jan 2, 2023
84e2e88
Better index step value scanning by checking with our expected set
goodboy Jan 2, 2023
7f997ef
Move $vlm y-axis to LHS
goodboy Jan 2, 2023
afda4bd
Correctly load order mode for first fqsn in overlay set
goodboy Jan 2, 2023
fca1272
Make $vlm axis color same as clears
goodboy Jan 2, 2023
fff436d
Fix indent level
goodboy Jan 3, 2023
c6367e1
Do full marker width after line
goodboy Jan 3, 2023
d2066ac
Always zero-on-step $vlm
goodboy Jan 3, 2023
1c54ba4
Add back another panes resize during startup
goodboy Jan 3, 2023
33049ba
Drop `Flume.index_stream()`, `._sampling.open_sample_stream()` replac…
goodboy Jan 5, 2023
1fb2ac0
Use `open_sample_stream()` in display loop
goodboy Jan 5, 2023
7a259b0
Fix query-mode cursor labels to work with epoch-indexing
goodboy Jan 5, 2023
37ac1d0
Drop bp blocks from formatters mod
goodboy Jan 5, 2023
ed91432
Handle last-in-view time slicing edge case
goodboy Jan 5, 2023
c8209dc
Clean a buncha cruft from render mod
goodboy Jan 5, 2023
63d773d
Take outer-interval values in `Viz.datums_range()`
goodboy Jan 6, 2023
7ccca1d
Make (cache) search-results a `set` and avoid overlay duplicate entries
goodboy Jan 6, 2023
20bf596
Lol, pull hist chart from the display state
goodboy Jan 6, 2023
5779359
Attempt to keep selected item highlighted
goodboy Jan 9, 2023
a4e6014
Round spread (slap) offset to min tick digits
goodboy Jan 12, 2023
f1adad9
Downthrottle to 16Hz on multi-feed charts
goodboy Jan 12, 2023
edca7b2
Breakpoint bad (-ve or too large) x-ranges to m4
goodboy Jan 12, 2023
c963093
Provide `datetime`-sorted clears table iteration
goodboy Jan 12, 2023
6e87ad9
Comment bad x-range bp for now
goodboy Jan 13, 2023
35032b4
Fix history array name
goodboy Jan 13, 2023
664a15e
Fix `open_trade_ledger()` enter value type annot
goodboy Jan 13, 2023
23e1ecb
Passthrough `tractor` kwargs directly
goodboy Jan 13, 2023
e57a264
Only handle hist discrepancies when market is open
goodboy Jan 13, 2023
53c9332
Drop multi mxmn from display mod
goodboy Jan 14, 2023
9d3de6e
Drop x-range query from `ChartPlotWidget.maxmin()`
goodboy Jan 14, 2023
4568be8
Use (modern) literal type annots in view code
goodboy Jan 14, 2023
4efe875
Add back coord-caching to ohlc graphic
goodboy Jan 15, 2023
eba8488
Add first-draft `PlotItemOverlay.group_maxmin()`
goodboy Jan 15, 2023
9826dda
Always cache `read_slc` alongside y-mnmx values
goodboy Jan 16, 2023
760c752
Set a `PlotItem.viz` for interaction lookup
goodboy Jan 16, 2023
d5950a9
Use `Viz` over charts where possible in display loop
goodboy Jan 16, 2023
fe3aab9
Use latest `asks`
goodboy Jan 16, 2023
2791af9
`kraken`: catch value error not index on missing `src_fiat` in pair
goodboy Jan 16, 2023
bd96fef
Use `Viz.update_graphics()` throughout remainder of graphics loop whe…
goodboy Jan 17, 2023
0f2d5c8
Ensure full hist OHLC path is drawn on tread
goodboy Jan 17, 2023
9e84d71
Only update last datum graphic(s) on clear ticks
goodboy Jan 17, 2023
e2b02ce
Only draw up to 2nd last datum for OHLC bars paths
goodboy Jan 17, 2023
fbc25bb
Add cached refs to last 1d xy outputs
goodboy Jan 17, 2023
4ab4815
Use `Viz.draw_last()` inside `.update_graphics()`
goodboy Jan 17, 2023
182e461
More thoroughly profile the display loop
goodboy Jan 17, 2023
c5efdac
Drop `ChartView._maxmin()` idea, use `Viz.maxmin()`
goodboy Jan 18, 2023
8aaee10
Drop `ChartView._maxmin()` usage in `.ui._fsp`
goodboy Jan 18, 2023
01025e1
Backlink subchart views to "main chart" in `.add_plot()`
goodboy Jan 18, 2023
c5d2a68
Support read-slice input to `Viz.maxmin()`
goodboy Jan 18, 2023
39aeca9
Adjust vlm fsp code to new `Viz.update_graphics()` output sig
goodboy Jan 18, 2023
1782bb7
Drop Qt interaction signal usage
goodboy Jan 18, 2023
2cf3d0f
Rework display loop maxmin-ing with `Viz` pipelining
goodboy Jan 18, 2023
382c53b
Document `Viz.incr_info()` outputs
goodboy Jan 18, 2023
b5b0b2a
Right, handle y-ranging multiple paths per plot
goodboy Jan 19, 2023
b10adc1
`binance`: same thing, only unsub when connected
goodboy Jan 19, 2023
c146aaf
Drop masked `._maxmin()` override code from fsp stuff
goodboy Jan 19, 2023
6e067cd
Fix `Viz.draw_last()` to divide by `.flat_index_ratio` for uppx index…
goodboy Jan 19, 2023
9a93a1c
Disable coordinate caching on OHLC ds curves to avoid smearing
goodboy Jan 19, 2023
96355ce
Rename `.maybe_downsample_graphics()` -> `.interact_graphics_cycle()`
goodboy Jan 19, 2023
9b88254
Fix profiler f-strings
goodboy Jan 19, 2023
cdaa0e4
First draft, group y-minmax transform algo
goodboy Jan 19, 2023
c760527
2nd try: dispersion normalize y-ranges around median
goodboy Jan 20, 2023
03ab5f5
3rdz the charm: log-linearize minor y-ranges to a major
goodboy Jan 20, 2023
e047fbb
Clean up cross-curve intersect point indexing
goodboy Jan 21, 2023
5aac4ea
Drop `.group_maxmin()`
goodboy Jan 21, 2023
6837192
Only remove axis from scene when in one
goodboy Jan 21, 2023
1e36815
Move axis hiding into `.overlay_plotitem()`
goodboy Jan 21, 2023
2ad1dcd
Only set the major curve's range once (per render cycle)
goodboy Jan 22, 2023
7e11f8c
Just warn log on bad intersect indexing errors (for now)
goodboy Jan 22, 2023
43f5de9
Drop `update_graphics_from_flow()`
goodboy Jan 22, 2023
8b533d6
Return `in_view: bool` from `Viz.update_graphics()`
goodboy Jan 22, 2023
4f7252c
When only one curve is in view, skip group ranging
goodboy Jan 22, 2023
a3a0e16
Factor curve-dispersion sorting into primary loop
goodboy Jan 22, 2023
5a43a2f
Fix intersect detection using time indexing
goodboy Jan 23, 2023
2c70a63
Factor color and cache mode settings into `FlowGraphics`
goodboy Jan 23, 2023
a670eb2
Add back `.prepareGeometryChange()`, seems faster?
goodboy Jan 23, 2023
ad092db
Make profiler work when nested and not?
goodboy Jan 23, 2023
4b2f38f
Add full profiling to `.interact_graphics_cycle()`
goodboy Jan 24, 2023
b1bea0b
Use normal pen when last-datum color not provided
goodboy Jan 24, 2023
d9e45f6
Support chart draw-api-kwargs-passthrough in lined plot meths
goodboy Jan 24, 2023
a94a498
Speed up ranging in display loop
goodboy Jan 24, 2023
65aba56
Add `Viz.median_from_range()`
goodboy Jan 24, 2023
2663ced
Use new cached median method in overlay scaling
goodboy Jan 24, 2023
07a81d6
Fix `do_px_step` output for epoch step sizing
goodboy Jan 24, 2023
552c7c3
Add linked charts guard-flag for use in display loop
goodboy Jan 24, 2023
aea2d58
Don't skip overlay scaling in disp-loop for now
goodboy Jan 24, 2023
7093248
Don't scale overlays on linked from display loop
goodboy Jan 24, 2023
2391881
Fix return type annot for `slice_from_time()`
goodboy Jan 24, 2023
afe9837
Use `._pathops.slice_from_time()` for overlay intersects
goodboy Jan 24, 2023
100e58d
Yield services (manager) from `maybe_open_pikerd()`
goodboy Jan 24, 2023
f1e4b97
Fix clearing endpoint type annots, export `open_ems()`
goodboy Jan 24, 2023
a583220
Yield `Services` in `open_test_pikerd()` fixture
goodboy Jan 24, 2023
bc28b62
Add service tree tests for data-feeds and the EMS
goodboy Jan 24, 2023
e0b4e5b
Return fast on bad range in `.default_view()`
goodboy Jan 24, 2023
71a250c
Lul, actually scaled main chart from linked set
goodboy Jan 24, 2023
534f96e
Comment out all median usage, turns out it's uneeded..
goodboy Jan 24, 2023
516d6c0
Drop old loop and wait on fsp engine tasks startups
goodboy Jan 24, 2023
879de7e
Better handle dynamic registry sampler broadcasts
goodboy Jan 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions piker/_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import os
from typing import (
Optional,
Union,
Callable,
Any,
ClassVar,
)
from contextlib import (
asynccontextmanager as acm,
Expand Down Expand Up @@ -257,7 +257,7 @@ async def open_piker_runtime(
# and spawn the service tree distributed per that.
start_method: str = 'trio',

tractor_kwargs: dict = {},
**tractor_kwargs,

) -> tuple[
tractor.Actor,
Expand Down Expand Up @@ -393,7 +393,7 @@ async def maybe_open_pikerd(

**kwargs,

) -> Union[tractor._portal.Portal, Services]:
) -> tractor._portal.Portal | ClassVar[Services]:
'''
If no ``pikerd`` daemon-root-actor can be found start it and
yield up (we should probably figure out returning a portal to self
Expand Down Expand Up @@ -445,7 +445,7 @@ async def maybe_open_pikerd(
# tractor-piker runtime stack in **this** process
# we return no portal to self.
assert service_manager
yield None
yield service_manager


# `brokerd` enabled modules
Expand Down
13 changes: 11 additions & 2 deletions piker/_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,14 @@ def __new__(
# don't do anything
return cls._disabledProfiler

# create an actual profiling object
cls._depth += 1
obj = super(Profiler, cls).__new__(cls)
obj._msgs = []

# create an actual profiling object
if cls._depth < 1:
cls._msgs = []

obj._name = msg or func_qualname
obj._delayed = delayed
obj._markCount = 0
Expand All @@ -174,8 +179,12 @@ def __call__(self, msg=None):

self._markCount += 1
newTime = perf_counter()
tot_ms = (newTime - self._firstTime) * 1000
ms = (newTime - self._lastTime) * 1000
self._newMsg(" %s: %0.4f ms", msg, ms)
self._newMsg(
f" {msg}: {ms:0.4f}, tot:{tot_ms:0.4f}"
)

self._lastTime = newTime

def mark(self, msg=None):
Expand Down
17 changes: 9 additions & 8 deletions piker/brokers/binance.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,14 +519,15 @@ async def subscribe(ws: wsproto.WSConnection):
subs.append("{sym}@bookTicker")

# unsub from all pairs on teardown
await ws.send_msg({
"method": "UNSUBSCRIBE",
"params": subs,
"id": uid,
})

# XXX: do we need to ack the unsub?
# await ws.recv_msg()
if ws.connected():
await ws.send_msg({
"method": "UNSUBSCRIBE",
"params": subs,
"id": uid,
})

# XXX: do we need to ack the unsub?
# await ws.recv_msg()

async with open_autorecon_ws(
'wss://stream.binance.com/ws',
Expand Down
4 changes: 3 additions & 1 deletion piker/brokers/kraken/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,9 @@ def has_pp(
for bsuid in table.pps:
try:
dst_name_start = bsuid.rindex(src_fiat)
except IndexError:
except (
ValueError, # substr not found
):
# TODO: handle nested positions..(i.e.
# positions where the src fiat was used to
# buy some other dst which was furhter used
Expand Down
6 changes: 6 additions & 0 deletions piker/clearing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
Market machinery for order executions, book, management.

"""
from ._client import open_ems


__all__ = [
'open_ems',
]
30 changes: 23 additions & 7 deletions piker/clearing/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@
Orders and execution client API.

"""
from __future__ import annotations
from contextlib import asynccontextmanager as acm
from pprint import pformat
from typing import TYPE_CHECKING

import trio
import tractor
from tractor.trionics import broadcast_receiver

from ..log import get_logger
from ..data.types import Struct
from ._ems import _emsd_main
from .._daemon import maybe_open_emsd
from ._messages import Order, Cancel
from ..brokers import get_brokermod

if TYPE_CHECKING:
from ._messages import (
BrokerdPosition,
Status,
)


log = get_logger(__name__)

Expand Down Expand Up @@ -167,12 +174,19 @@ async def relay_order_cmds_from_sync_code(
@acm
async def open_ems(
fqsn: str,
mode: str = 'live',

) -> (
) -> tuple[
OrderBook,
tractor.MsgStream,
dict,
):
dict[
# brokername, acctid
tuple[str, str],
list[BrokerdPosition],
],
list[str],
dict[str, Status],
]:
'''
Spawn an EMS daemon and begin sending orders and receiving
alerts.
Expand Down Expand Up @@ -213,14 +227,16 @@ async def open_ems(
from ..data._source import unpack_fqsn
broker, symbol, suffix = unpack_fqsn(fqsn)

mode: str = 'live'

async with maybe_open_emsd(broker) as portal:

mod = get_brokermod(broker)
if not getattr(mod, 'trades_dialogue', None):
if (
not getattr(mod, 'trades_dialogue', None)
or mode == 'paper'
):
mode = 'paper'

from ._ems import _emsd_main
async with (
# connect to emsd
portal.open_context(
Expand Down
24 changes: 20 additions & 4 deletions piker/clearing/_ems.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from ..data._source import (
unpack_fqsn,
mk_fqsn,
float_digits,
)
from ..data.feed import (
Feed,
Expand Down Expand Up @@ -418,7 +419,7 @@ async def maybe_open_brokerd_dialog(

# load the paper trading engine
exec_mode = 'paper'
log.warning(f'Entering paper trading mode for {broker}')
log.info(f'{broker}: Entering `paper` trading mode')

# load the paper trading engine as a subactor of this emsd
# actor to simulate the real IPC load it'll have when also
Expand Down Expand Up @@ -1250,6 +1251,7 @@ async def process_client_order_cmds(

spread_slap: float = 5
min_tick = flume.symbol.tick_size
min_tick_digits = float_digits(min_tick)

if action == 'buy':
tickfilter = ('ask', 'last', 'trade')
Expand All @@ -1258,12 +1260,18 @@ async def process_client_order_cmds(
# TODO: we probably need to scale this based
# on some near term historical spread
# measure?
abs_diff_away = spread_slap * min_tick
abs_diff_away = round(
spread_slap * min_tick,
ndigits=min_tick_digits,
)

elif action == 'sell':
tickfilter = ('bid', 'last', 'trade')
percent_away = -0.005
abs_diff_away = -spread_slap * min_tick
abs_diff_away = round(
-spread_slap * min_tick,
ndigits=min_tick_digits,
)

else: # alert
tickfilter = ('trade', 'utrade', 'last')
Expand Down Expand Up @@ -1367,7 +1375,15 @@ async def _emsd_main(
exec_mode: str, # ('paper', 'live')
loglevel: str = 'info',

) -> None:
) -> tuple[
dict[
# brokername, acctid
tuple[str, str],
list[BrokerdPosition],
],
list[str],
dict[str, Status],
]:
'''
EMS (sub)actor entrypoint providing the execution management
(micro)service which conducts broker order clearing control on
Expand Down
Loading