Commit Graph

2038 Commits (d2c40d887cb35f732a2cc198648a9dd57ee4c959)

Author SHA1 Message Date
Tyler Goodlet d2c40d887c Fix bug where if `yrange` was passed the mxmin callback was still used.. 2022-04-06 17:11:15 -04:00
Tyler Goodlet ba78d563b8 Guard against zero px width 2022-04-06 17:10:19 -04:00
Tyler Goodlet 3a7e00e287 Add `Flow` type with a real chitty mxmn cacheing method
This new type wraps a shm data flow and will eventually include things
like incremental path-graphics updates and serialization + bg downsampling
techniques. The main immediate motivation was to get a cached y-range max/min
calc going since profiling revealed the `numpy` equivalents were
actually quite slow as the data set grows large. Likely we can use all
this to drive a streaming mx/mn routine that's always launched as part
of each on-host flow.

This is our official foray into use of `msgspec.Struct` B) and I have to
say, pretty impressed; we'll likely completely ditch `pydantic` from
here on out.
2022-04-06 17:05:57 -04:00
Tyler Goodlet 008796c69f Loop for first graphic with xvec 2022-04-06 12:13:05 -04:00
Tyler Goodlet c9d42800b4 Only `.maybe_downsample_graphics()` on manual changes
We don't need update graphics on every x-range change since that's what
the display loop does. Instead, only on manual changes do we make manual
calls into `.update_graphics_from_array()` and be sure to iterate all
linked subplots and all their embedded graphics.
2022-04-06 11:11:28 -04:00
Tyler Goodlet f79f0d5a63 Don't return early on ds line render to avoid breaking profiling
The pg profiler seems to have trouble with early `return`s in function
calls (likely muckery with the GC/`.__delete__()`) so let's just try
to avoid it for now until we either fix it (probably by implementing as
a ctx mngr) or use diff one.
2022-04-06 09:12:24 -04:00
Tyler Goodlet 5c7d1a8776 Use HL tracer by default, seems to be faster? 2022-04-05 11:04:45 -04:00
Tyler Goodlet 373dd8eb98 Up the shm size to 10d of 1s ohlc 2022-04-05 09:23:54 -04:00
Tyler Goodlet e9157dd9f3 Allow passing "ms slower then" value on cli to `--profile` 2022-04-05 09:18:19 -04:00
Tyler Goodlet a3fdc5c07b Only bail up pan updates if uppx > 16 2022-04-04 17:29:33 -04:00
Tyler Goodlet fccd17a4e2 Delegate `BarItems.x_uppx()` to internal ds curve 2022-04-04 17:28:56 -04:00
Tyler Goodlet 47621b898f Downsample curves even less frequently 2022-04-04 17:28:29 -04:00
Tyler Goodlet 9de5be5a6d Only pass vr for bars, allow source vb in autorange 2022-04-04 15:58:21 -04:00
Tyler Goodlet 9b0d4b5cd6 Drop the unit-volume chart once $vlm is fully drawn 2022-04-04 14:45:29 -04:00
Tyler Goodlet f9d2e45836 Ensure we update the volume array, not graphics
Ugh, turns out the wacky `ChartView.maxmin` callback stuff we did (for
determining y-range sizings) currently requires that the volume array
has a "bars in view" result.. so let's make that keep working without
rendering the graphics for the curve (since we're disabling them once
$vlm comes up).
2022-04-04 14:43:13 -04:00
Tyler Goodlet 8e6fda0049 Add `.update_graphics_from_array()` flags for setting view-range use and graphics rendering 2022-04-04 13:47:34 -04:00
Tyler Goodlet 596533b403 Guard against zero px width 2022-04-04 10:43:44 -04:00
Tyler Goodlet ca4de3e925 Given in-view rendering, make bars downsample on uppx >= 8 2022-04-04 10:31:01 -04:00
Tyler Goodlet 0cabc613a0 Make `FastAppendCurve` optionally view range aware
As with the `BarItems` graphics, this makes it possible to pass in a "in
view" range of array data that can be *only* rendered improving
performance for large(r) data sets. All the other normal behaviour is
kept (i.e a persistent, (pre/ap)pendable path can still be maintained)
if a ``view_range`` is not provided.

Further updates,
- drop the `.should_ds_or_redraw()` and `.maybe_downsample()` predicates
 instead moving all that logic inside `.update_from_array()`.
- disable the "cache flipping", which doesn't seem to be needed to avoid
  artifacts any more?
- handle all redraw/dowsampling logic in `.update_from_array()`.
- even more profiling.
- drop path `.reserve()` stuff until we better figure out how it's
  supposed to work.
2022-04-04 10:29:45 -04:00
Tyler Goodlet f7ebade9b5 Fix view range array to include most recent (facepalm) 2022-04-04 10:14:46 -04:00
Tyler Goodlet c9b19e8587 TOQUASH: drop display loop old .update_ohlc_.. 2022-04-04 00:36:05 -04:00
Tyler Goodlet 97beb26a9b Port to new `.update_graphics_from_array()`, pause quote updates on chart interaction 2022-04-04 00:35:53 -04:00
Tyler Goodlet 14d5ca1cc6 Make panning pause feeds, call into update method from downsampler cb loop 2022-04-04 00:35:32 -04:00
Tyler Goodlet 675611dc61 Attempt only rendering ohlc bars in view and ds-ing otherwise 2022-04-04 00:10:13 -04:00
Tyler Goodlet 2fa553f1b7 Unify into a single update method: `.update_graphics_from_array()` 2022-04-03 23:52:09 -04:00
Tyler Goodlet 612813e937 Establish stream before `fsp_compute` so that backfill updates work again.. 2022-04-03 23:39:26 -04:00
Tyler Goodlet 3a3baca9bc Remove units vlm cuve once the $vlm one comes up 2022-04-01 13:51:21 -04:00
Tyler Goodlet 768d2d997f Index must be int bro.. 2022-04-01 13:49:42 -04:00
Tyler Goodlet 98da4342e7 Put back more bars iters in loop to handle no-data in range cases 2022-04-01 13:49:17 -04:00
Tyler Goodlet dd6e2604d3 Move px width log scaling into `ds_m4()` 2022-04-01 13:47:24 -04:00
Tyler Goodlet e2d91f274f Add more frequent ds steps when zooming out; use profiler gt 2022-04-01 13:46:37 -04:00
Tyler Goodlet addb0a4928 Increase shm size to days of 1s steps 2022-04-01 13:45:33 -04:00
Tyler Goodlet 098c4f25fc Make `BarItems` use our line curve for downsampling
Drop all the logic originally in `.update_ds_line()` which is now done
internal to our `FastAppendCurve`. Add incremental update of the
flattened OHLC -> line curve (unfortunately using `np.concatenate()` for
the moment) and maintain a new `._ds_line_xy` arrays tuple which keeps
the internal state. Add `.maybe_downsample()` as per the new interaction
update method requirement. Draft out some fast path curve stuff like in
our line graphic. Short-circuit bars path updates when we downsample to
line. Oh, and add a ton more profiling in prep for getting
all this stuff faf.
2022-04-01 13:44:57 -04:00
Tyler Goodlet 9c88b26d85 Add global profile timeout var 2022-04-01 13:27:07 -04:00
Tyler Goodlet 8686cf99fe Add "native" downsampling to our `FastAppendCurve`
Build out an interface that makes it super easy to downsample curves
using the m4 algorithm while keeping our incremental `QPainterPath`
update feature. A lot of hard work and tinkering went into getting this
working all in-thread correctly and there are quite a few details..

New interface methods:
- `.x_uppx()` which returns the x-axis "view units per pixel"
- `.px_width()` which returns the total (rounded) x-axis pixels spanned
    by the curve in view.
- `.should_ds_or_redraw()` a predicate which checks internal state to
  see if either downsampling of the curve should take place, or the curve
  should have all downsampling removed and be redrawn with source array
  data.
- `.downsample()` the actual ds processing routine which delegates into
  the m4 algo impl.
- `.maybe_downsample()` a simple update method which can be called by
  the view box when the user changes the zoom level.

Implementation details/changes:

- make `.update_from_array()` check for downsample (or revert to source
  aka de-downsample) conditions exist and then downsample and re-draw
  path graphics accordingly.
- in order to even further speed up path appends (since our main
  bottleneck is measured to be `QPainter.drawPath()` calls with large
  paths which are frequently updates), add a secondary path `.fast_path`
  which is the path that is real-time updates by incremental appends and
  which is painted separately for speed in `.pain()`.
- drop all the `QPolyLine` stuff since it was tested to be much slower
  in general and especially so for append-updates.
- stop disabling the cache settings on updates since it doesn't seem to
  be required any more?
- more move toward deprecating and removing all lingering interface
  requirements from `pg.PlotCurveItem` (like `.xData`/`.yData`).
- adjust `.paint()` and `.boundingRect()` to compensate for the new
  `.fast_path`
- add a butt-load of profiling B)
2022-03-31 19:28:35 -04:00
Tyler Goodlet f9ec00e1ae First try, drop `FastAppendCurve` inheritance from `pg.PlotCurveItem` 2022-03-30 15:43:14 -04:00
Tyler Goodlet 25a3a123ec Get sync-to-marketstore-tsdb history retrieval workinnn 2022-03-30 14:11:21 -04:00
Tyler Goodlet 54466db554 Handle "fatal" level log msgs in docker super 2022-03-30 14:10:15 -04:00
Tyler Goodlet 6f06f646cf Get ib data feed hackzorz workin
ib has a throttle limit for "hft" bars but contained in here is some
hackery using ``xdotool`` to reset data farms auto-magically B)

This copies the working script into the ib backend mod as a routine and
now uses `trio.run_process()` and calls into it from the `get_bars()`
history retriever and then waits for "data re-established" events to be
received from the client before making more history queries.

TL;DR summary of changes:
- relay ib's "system status" events (like for data farm statuses)
  as a new "event" msg that can be processed by registers of
  `Client.inline_errors()` (though we should probably make a new
  method for this).
- add `MethodProxy.status_event()` which allows a proxy user to register
  for a particular "system event" (as mentioned above), which puts
  a `trio.Event` entry in a small table can be set by an relay task if
  there are any detected waiters.
- start a "msg relay task" when opening the method proxy which does
  the event setting mentioned above in the background.
- drop the request error handling around the proxy creation, doesn't
  seem necessary any more now that we have better error propagation from
  `asyncio`.
- add event waiting logic around the data feed reset hackzorin.
- change the order relay task to only log system events for now (though
  we need to do some better parsing/logic to get tws-external order
  updates to work again..
2022-03-30 13:49:19 -04:00
Tyler Goodlet 65d4c317c6 Drop commented line from pq method copy/paste 2022-03-29 14:11:31 -04:00
Tyler Goodlet 97439e882c Add basic tsdb history loading
If `marketstore` is detected try to only load most recent missing data
from the data provider (broker) and the rest from the tsdb and push it
all to shm for display in the UI. If the provider/broker doesn't have
the history client endpoint, just use the old one for now so we can
start to incrementally add support. Don't start the ohlc step
incrementer task until the backend signals that the feed is live.
2022-03-29 14:06:28 -04:00
Tyler Goodlet b5d566fed5 Drop `ms-shell`, add `piker storesh` cmd 2022-03-29 13:33:43 -04:00
Tyler Goodlet d3adb6dff7 Add diffing logic to `tsdb_history_update()`
Add some basic `numpy` epoch slice logic to generate append and prepend
arrays to write to the db.

Mooar cool things,
- add a `Storage.delete_ts()` method to wipe a column series from the db
  easily.
- don't attempt to read in any OHLC series by default on client load
- add some `pyqtgraph` profiling and drop manual latency measures
- if no db series for the fqsn exists write the entire shm array
2022-03-29 13:31:31 -04:00
Tyler Goodlet 22c81eb5bf Show baseline bars length on in view read < 6 2022-03-29 13:17:06 -04:00
Tyler Goodlet 41a8c23e44 Bump up resolution log scaling a mag 2022-03-29 13:15:59 -04:00
Tyler Goodlet 6bb1f06813 Drop `pandas` to `numpy` converter 2022-03-29 13:15:23 -04:00
Tyler Goodlet 72de184c08 Always clear previous downsample curve on switch
Pretty sure this was most of the cause of the stale (more downsampled)
curves showing when zooming in and out from bars mode quickly. All this
stuff needs to get factored out into a new abstraction anyway, but
i think this get's mostly correct functionality.

Only draw new ds curve on uppx steps >= 4 and stop adding/removing
graphics objects from the scene; doesn't seem to speed anything up
afaict. Add better reporting of ds scale changes.
2022-03-29 13:13:51 -04:00
Tyler Goodlet 319a6fb66a Fix missing f-str prefix 2022-03-29 12:37:58 -04:00
Tyler Goodlet e7b1d77b08 Drop `pandas` use in ib backend for history
Found an issue (that was predictably brushed aside XD) where the
`ib_insync.util.df()` helper was changing the timestamps on bars data to
be way off (probably a `pandas.Timestamp` timezone thing?).

Anyway, dropped all that (which will hopefully let us drop `pandas` as
a hard dep) and added a buncha timestamp checking as well as start/end
datetime return values using `pendulum` so that consumer code can know
which "slice" is output.

Also added some WIP code to work around "no history found" request
errors where instead now we try to increment backward another 200
seconds - not sure if this actually correct yet.
2022-03-29 10:36:40 -04:00
Tyler Goodlet 3c5a799e97 More IB repairs..
Make the throttle error propagate through to `trio` again by adding
`dict`-msg support between the two loops such that errors can be
re-raised on the `trio` side. This is all integrated into the
`MethoProxy` and accompanying result relay task.

Further fix a longer standing issue where sometimes the `ib_insync`
order entry method will raise a weird assertion error because it detects
some internal order-id state issue.. Just ignore those and make relay
back an error to the ems in such cases.

Add a bunch of notes for todos surrounding data feed reset hackery.
2022-03-25 16:11:59 -04:00