Commit Graph

810 Commits (3ebb7ab6b16e6a48e370a50587ebdcab999ce383)

Author SHA1 Message Date
Tyler Goodlet 18dc809acb Add naive digits count routine 2020-10-22 14:05:35 -04:00
Tyler Goodlet f2c4a46c94 Center bars around index, adjust curves back to match... 2020-10-21 11:19:41 -04:00
Tyler Goodlet cd828db9e9 Show 24 bars to left on startup 2020-10-21 10:51:54 -04:00
Tyler Goodlet 875bc8be24 Add line dots cursors to curves by default 2020-10-21 10:46:56 -04:00
Tyler Goodlet 1f6b5da17e Add support for curve "cursors" using a filled dot
Add a new graphic `LineDot` which is a `pg.CurvePoint` that draws
a simple filled dot over a curve at the specified index.

Add support for adding these cursor-dots to the crosshair/mouse through
a new `CrossHair.add_curve_cursor()`. Discretized the vertical line
updates on the crosshair such that it's only drawn in the middle of
the current bar in the main chart.
2020-10-21 10:40:51 -04:00
Tyler Goodlet 88583d999a Add "follow mode"
Makes the chart act like tws where each new time step increment the
chart shifts to the right so that the last bar stays in place. This
gets things looking like a proper auto-trading UX.

Added a couple methods to ``ChartPlotWidget`` to make this work:
- ``.default_view()`` to set the preferred view based on user settings
- ``.increment_view()`` to shift the view one time frame right

Also, split up the `.update_from_array()` method to be curve/ohlc
specific allowing for passing in a struct array with a named field
containing curve data more straightforwardly. This also simplifies the
contest label update functions.
2020-10-20 09:13:27 -04:00
Tyler Goodlet 1902507703 Change scroll "center" to rightmost bar on screen 2020-10-19 21:32:50 -04:00
Tyler Goodlet c57f678295 Fix contents labels issues
Lookup overlay contents from the OHLC struct array (for now / to make
things work) and fix anchoring logic with better offsets to keep
contents labels super tight to the edge of the view box. Unfortunately,
had to hack the label-height-calc thing for avoiding overlap of graphics
with the label; haven't found a better solution yet and pyqtgraph seems
to require more rabbit holing to figure out something better. Slap in
some inf lines for over[sold/bought] rsi conditions thresholding.
2020-10-19 14:18:06 -04:00
Tyler Goodlet 851104dd31 Add an inf horizontal line helper 2020-10-19 14:01:57 -04:00
Tyler Goodlet 1706b67e00 Note the issues with the shared fsp array index.. 2020-10-19 14:01:25 -04:00
Tyler Goodlet 32974a118c Add hidpi comments, 300 bars in view at startup 2020-10-19 11:37:50 -04:00
Tyler Goodlet d3dc8fb219 Differentiate array schema by close field 2020-10-19 11:37:28 -04:00
Tyler Goodlet c7d5ea6e15 Fix static yrange and last bar double draw issues 2020-10-16 12:18:14 -04:00
Tyler Goodlet fc23b2180d Pass through fonts to axes 2020-10-16 12:15:33 -04:00
Tyler Goodlet 58d3234f74 Drop lingering print 2020-10-16 12:15:07 -04:00
Tyler Goodlet f4c38621d5 Add a default "bars from right" style setting 2020-10-15 15:08:56 -04:00
Tyler Goodlet 6f429b1104 These seem to be "faster" crosshair settings? 2020-10-15 15:08:16 -04:00
Tyler Goodlet cb72662350 Add warnings for shm cache misses 2020-10-15 15:07:56 -04:00
Tyler Goodlet 454b445b4b Add better shared mem writer task checking
If you have a common broker feed daemon then likely you don't want to
create superfluous shared mem buffers for the same symbol. This adds an
ad hoc little context manger which keeps a bool state of whether
a buffer writer task currently is running in this process. Before we
were checking the shared array token cache and **not** clearing it when
the writer task exited, resulting in incorrect writer/loader logic on
the next entry..

Really, we need a better set of SC semantics around the shared mem stuff
presuming there's only ever one writer per shared buffer at given time.
Hopefully that will come soon!
2020-10-15 15:02:42 -04:00
Tyler Goodlet db273e1cd7 Up the mouse re-draw rate limit 2020-10-12 09:36:46 -04:00
Tyler Goodlet 18097fc33b Scale for hidpi pixmaps too 2020-10-02 12:13:50 -04:00
Tyler Goodlet 2302e59f1d 3k bars for now, ignore rtTime 2020-10-02 12:13:50 -04:00
Tyler Goodlet 8d9a6845c6 Add a naive maxmin calc to avoid frequent resizes
If we know the max and min in view then on datum updates we can avoid
resizing the y-range when a new max/min has not yet arrived.

This adds a very naive numpy calc in the drawing thread which we can
likely improve with a more efficient streaming alternative which can
also likely be run in a fsp subactor. Also, since this same calc is
essentially done inside `._set_yrange()` we will likely want to allow
passing the result into the method to avoid duplicate work.
2020-10-02 12:13:50 -04:00
Tyler Goodlet 6d5ccc6c3f Specify font size in pixels 2020-10-02 12:13:50 -04:00
Tyler Goodlet 8276b02f92 Further label and axis sizing tweaks for hidpi 2020-10-02 12:13:50 -04:00
Tyler Goodlet e524ee9045 Resize everything with HiDPI scaling on 2020-10-02 12:13:50 -04:00
Tyler Goodlet bceeaa56ff Drop ringbuf, didn't end up using 2020-10-02 12:13:50 -04:00
Tyler Goodlet acc8dd66f5 Add data._normalize.py ... 2020-10-02 12:13:50 -04:00
Tyler Goodlet bc65040601 Add shm support to kraken backend 2020-10-02 12:13:50 -04:00
Tyler Goodlet d4eb5ccca4 Handle vwap overlay with shm 2020-10-02 12:13:50 -04:00
Tyler Goodlet 8a4528c006 Always ask backend for ohlc dtype 2020-10-02 12:13:50 -04:00
Tyler Goodlet 47d4ec5985 Move _source under data package 2020-10-02 12:13:50 -04:00
Tyler Goodlet 8e2e695ba8 Revert project name removal; breaks shit elsewhere somehow.. 2020-10-02 12:13:50 -04:00
Tyler Goodlet 155c3eef2a Convert timeit thing to use print() 2020-10-02 12:13:50 -04:00
Tyler Goodlet 8832804bab Sub each new symbol to shm incrementing 2020-10-02 12:13:50 -04:00
Tyler Goodlet e3e219aa4b Add multi-symbol-buffer increment support 2020-10-02 12:13:50 -04:00
Tyler Goodlet 41e85ccaa9 Break wma calc into sync func 2020-10-02 12:13:50 -04:00
Tyler Goodlet 3f0e175011 Get bar oriented RSI working correctly 2020-10-02 12:13:50 -04:00
Tyler Goodlet 268e748417 Drop extra prefix in logs 2020-10-02 12:13:50 -04:00
Tyler Goodlet bfa7839370 Adopt official color 2020-10-02 12:13:50 -04:00
Tyler Goodlet 2fcbefa6e1 Use shm in fsp cascading
This kicks off what will be the beginning of hopefully a very nice
(soft) real-time financial signal processing system. We're keeping the
hack to "time align" curves (for now) with the bars for now by slapping
in an extra datum at index 0.
2020-10-02 12:13:50 -04:00
Tyler Goodlet 4383579cd0 Use shm array in chart-fsp task
Just like for the source OHLC, we now have the chart parent actor create
an fsp shm array and use it to read back signal data for plotting.
Some tweaks to get the price chart (and sub-charts) to load historical
datums immediately instead of waiting on an initial quote.
2020-10-02 12:13:50 -04:00
Tyler Goodlet ba4261f974 Add timeit prints 2020-10-02 12:13:50 -04:00
Tyler Goodlet 561cafbe55 Another black 2020-10-02 12:13:50 -04:00
Tyler Goodlet efb52f2292 Make shared array buffer incrementer a message pub
Drop ctx manager api and use `tractor.msg.pub`.
2020-10-02 12:13:50 -04:00
Tyler Goodlet 373ff90229 Only need UTC offset hacking if time w broker is messed.. 2020-10-02 12:13:50 -04:00
Tyler Goodlet d93ce84a99 Variety of IB backend improvements
- Move to new shared mem system only writing on the first (by process)
  entry to `stream_quotes()`.
- Deliver bars before first quote arrives so that chart can populate and
  then wait for initial arrival.
- Allow caching clients per actor.
- Load bars using the same (cached) client that starts the quote stream
  thus speeding up initialization.
2020-10-02 12:13:50 -04:00
Tyler Goodlet b1093dc71d Add a `data.Feed` type
Wraps the growing tuple of items being delivered by `open_feed()`.
Add lazy loading of the broker's signal step stream with
a `Feed.index_stream()` method.
2020-10-02 12:13:50 -04:00
Tyler Goodlet 38469bd6ef Slight rework: shm API
Add an internal `_Token` to do interchange (un)packing for passing
"references" to shm blocks between actors.  Part of the token involves
providing the `numpy.dtype` in a cross-actor format.  Add a module
variable for caching "known tokens" per actor.  Drop use of context
managers since they tear down shm blocks too soon in debug mode and
there seems to be no reason to unlink/close shm before the process has
terminated; if code needs it torn down explicitly, it can.
2020-10-02 12:13:50 -04:00
Tyler Goodlet cd540fd07e Cleanups 2020-10-02 12:13:50 -04:00
Tyler Goodlet 6fa4f6e943 Port charts to new shm arrays 2020-10-02 12:13:50 -04:00
Tyler Goodlet f872fbecf8 Hook IB up to shared memory system
Adjust the `data.open_feed()` api to take a shm token so the
broker-daemon can attach a previously created (by the parent actor) mem
buf and push real-time tick data. There's still some sloppiness here in
terms of ensuring only one mem buf per symbol (can be seen in
`stream_quotes()`) which should really managed at the data api level.
Add a bar incrementing stream-task which delivers increment msgs to any
consumers.
2020-10-02 12:13:50 -04:00
Tyler Goodlet 17491ba819 Disconnect stdlib's resource_tracker, fix .push()
Logic in `SharedArray.push()` was totally wrong.
Remove all the `multiprocessing.resource_tracker` crap such that we
aren't loading an extra process at every layer and we don't get tons of
errors when cleaning on in an SC way.
2020-10-02 12:13:50 -04:00
Tyler Goodlet 712e36b9d5 First draft of a shared numpy array sub-system
This adds a shared memory "incrementing array" sub-sys interface
for single writer, multi-reader style data passing. The main motivation
is to avoid multiple copies of the same `numpy` array across actors
(plus now we can start being fancy like ray).

There still seems to be some odd issues with the "resource tracker"
complaining at teardown (likely partially to do with SIGINT stuff) so
some further digging in the stdlib code is likely coming.

Pertains to #107 and #98
2020-10-02 12:13:50 -04:00
Tyler Goodlet 07beec59bf Hopefully fix datum offset on signal sub-plots
Added a comment to clarify, ish.
Add `ChartPlotWidget._overlays` as registry of curves added on top of
main graphics. Hackishly (ad-hoc-ishly?) update the curve assuming the
data resides in the same `._array` for now (which it does for historical
vwap).
2020-10-02 12:13:28 -04:00
Tyler Goodlet 2cc2b32805 Fix dbz with `np.divide()` 2020-10-02 12:13:28 -04:00
Tyler Goodlet eb5d64ceef Add support for overlay curves and fixed y-range
Allow passing a fixed ylow, yhigh tuple to `._set_yrange()` which avoids
recomputing the range from data if desired (eg. rsi-like bounded
signals). Add support for overlay curves to the OHLC chart and add basic
support to brokers which provide a historical 'vwap`. The data array
increment logic had to be tweaked to copy the vwap from the last bar.

Oh, and hack the subchart curves with two extra prepended datums to make
them align "better" with the ohlc main chart; need to talk to
`pyqtgraph` core about how to do this more correctly.
2020-10-02 12:13:28 -04:00
Tyler Goodlet e91ba55d68 Always draw any history bars on update 2020-10-02 12:13:28 -04:00
Tyler Goodlet a4a5bff3fa Yes, even more grays 2020-10-02 12:13:28 -04:00
Tyler Goodlet da2325239c Copy non-base dtype fields on bar increment 2020-10-02 12:13:28 -04:00
Tyler Goodlet 80f191c57d Adjust range logic to avoid overlap with labels
By mapping any in view "contents labels" to the range of the
``ViewBox``'s data we can avoid having graphics overlap with labels.
Take this approach instead of specifying a min y-range using the std
and activate the range compute on resize and mouser scrolling.
Also, add y-sticky update for signal plots.
2020-10-02 12:13:28 -04:00
Tyler Goodlet fc0a03d597 Handle OHLC *and* signal indexing 2020-10-02 12:13:28 -04:00
Tyler Goodlet 9a59f2408d Start fsp subpackage, separate momo stuff 2020-10-02 12:13:28 -04:00
Tyler Goodlet 7d24e8eeb0 First draft of real-time rsi using numba 2020-10-02 12:13:28 -04:00
Tyler Goodlet 9d8a867767 Bar graphics update speed improvements
Use two separate `QPicture` instances:
- one for the 3 lines for the last bar
- one for all the historical bars lines

On price changes update the last bar and only update historical bars
when the current bar's period expires (when a new bar is "added").
Add a flag `just_history` for this  `BarItems.draw_lines()`.
Also, switch the internal lines array/buffer to a 2D numpy array to avoid
the type-cast step and instead just flatten using `numpy.ravel()`.

Overall this should avoid the problem of draws getting slower over time
as new bars are added to the history since price updates only redraw
a single bar to the "last" `QPicture` instance. Ideally in the future we
can make the `history` `QPicture` a `QPixmap` but it looks like this
will require some internal work in `pyqtgraph` to support it.
2020-10-02 12:13:28 -04:00
Tyler Goodlet b1591e3ee1 Start mucking with faster bars updates
Use a ``rec2array`` struct array converter to generate lines sequence
faster. Start looking into using a `QPixmap` to avoid redrawing all
bars every update.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 0e513599eb Info log fsp output for now 2020-10-02 12:13:28 -04:00
Tyler Goodlet f1b72dfd6b Better bg color, tweak margins. 2020-10-02 12:13:28 -04:00
Tyler Goodlet 17d205f773 Add proper x-axis time-stamping 2020-10-02 12:13:28 -04:00
Tyler Goodlet ea2a675adf Use dashed crosshair, simplify x-axis alloc 2020-10-02 12:13:28 -04:00
Tyler Goodlet 387a696232 Even more colors 2020-10-02 12:13:28 -04:00
Tyler Goodlet fca6257152 Use dashed lines for crosshair 2020-10-02 12:13:28 -04:00
Tyler Goodlet 7a245ddda4 Add and update y-sticky labels on new price data 2020-10-02 12:13:28 -04:00
Tyler Goodlet 363d4cf609 Start color map 2020-10-02 12:13:28 -04:00
Tyler Goodlet d7466a58b4 Add updateable y-sticky label 2020-10-02 12:13:28 -04:00
Tyler Goodlet 8d29338174 Cleanup latency tracker 2020-10-02 12:13:28 -04:00
Tyler Goodlet 58b2e7e395 Refer to main chart's data for date axis 2020-10-02 12:13:28 -04:00
Tyler Goodlet f46fa99a6e Add "contents" labels to charts
Add a default "contents label" (eg. OHLC values for bar charts) to each
chart and update on crosshair interaction.

Few technical changes to make this happen:
- adjust bar graphics to have the HL line be in the "middle" of the
  underlying arrays' "index range" in the containing view.
- add a label dict each chart's graphics name to a label + update routine
- use symbol names instead of this "main" identifier crap for referring to
  particular price curves/graphics
2020-10-02 12:13:28 -04:00
Tyler Goodlet 61e460a422 Start brokers.api module 2020-10-02 12:13:28 -04:00
Tyler Goodlet fd21f4b0fe WIP initial draft of FSP subsystem
This is a first attempt at a financial signal processing subsystem which
utilizes async generators for streaming frames of numpy array data
between actors. In this initial attempt the focus is on processing price
data and relaying it to the chart app for real-time display. So far this
seems to work (with decent latency) but much more work is likely needed
around improving the data model for even better latency and less data
duplication.

Surprisingly (or not?) a lot of simplifications to the charting code
came out of this in terms of conducting graphics updates in streaming
tasks instead of hiding them inside the obfuscated mess that is the
Qt-style-inheritance-OO-90s-trash. The goal from here on wards will be
to enforce strict semantics around reading and writing of data such that
state is kept outside "object trees" as much as possible and streaming
function semantics guide our flow model. Unsurprisingly, this reduction
in "instance state" is happening wherever we use `trio` ;)

A little summary on the technical changes:
- not going to explain the fsp system yet; it's too nascent and
  probably going to get some heavy editing.
- drop any "update" methods from the `LinkedCharts` type since each
  sub-chart will have it's own update task and thus a separate update
  loop; further individual graphics (per chart) may eventually require
  this same design.
- delete `ChartView`; moved into separate mod.
- add "stream from fsp" task to start our foray into real-time actor
  processed numpy streaming.
2020-10-02 12:13:28 -04:00
Tyler Goodlet edb32e8c2b Drop weird chart type enum 2020-10-02 12:13:28 -04:00
Tyler Goodlet 04e21a96da Use partial, pass kwargs to `tractor._main()` 2020-10-02 12:13:28 -04:00
Tyler Goodlet a29b7d9be5 Start "interaction" module 2020-10-02 12:13:28 -04:00
Tyler Goodlet 8a46f8d6ed Port monitor to normalized streams 2020-10-02 12:13:28 -04:00
Tyler Goodlet 241b2374e8 Port `DataFeed` api to broker specific normalizer routine 2020-10-02 12:13:28 -04:00
Tyler Goodlet 9bbf0e0d7a Add a normalizer routine which emits quote differentials/ticks 2020-10-02 12:13:28 -04:00
Tyler Goodlet 81fb327fe1 Add `services` cmd for monitoring actors 2020-10-02 12:13:28 -04:00
Tyler Goodlet 65fb92eaff Flatten out chart tasks 2020-10-02 12:13:28 -04:00
Tyler Goodlet 6b572eb0ef Add ravel() reference link 2020-10-02 12:13:28 -04:00
Tyler Goodlet 971b871647 Handle "mouse-not-on-plot" edge cases 2020-10-02 12:13:28 -04:00
Tyler Goodlet b2506b04f6 Attempt more reliable chart startup
Wait for a first actual real-time quote before starting graphics update
tasks. Use the new normalized tick format brokers are expected to emit
as a `quotes['ticks']` list. Auto detect time frame from historical
bars.
2020-10-02 12:13:28 -04:00
Tyler Goodlet d81f6620f5 Passthrough loglevel from qtractor 2020-10-02 12:13:28 -04:00
Tyler Goodlet 2eea946e5b Drop forkserver usage.
We've got the sweet and realable `trio` spawner now :)
2020-10-02 12:13:28 -04:00
Tyler Goodlet 1a143f6b16 Pass piker log level through to tractor for chart app 2020-10-02 12:13:28 -04:00
Tyler Goodlet dc919fa676 Set tractor loglevel in cli config 2020-10-02 12:13:28 -04:00
Tyler Goodlet cb8215c203 Also log the payload 2020-10-02 12:13:28 -04:00
Tyler Goodlet 46c804db0b Support the `stream_quotes()` api in questrade backend 2020-10-02 12:13:28 -04:00
Tyler Goodlet ad519c10a9 Always just look up the current plot on mouse handling 2020-10-02 12:13:28 -04:00
Tyler Goodlet bbe02570b3 Allow for dynamically added plots
Add `ChartPlotWidget.add_plot()` to add sub charts for indicators which
can be updated independently. Clean up rt bar update code and drop some
legacy ohlc loading cruft.
2020-10-02 12:13:28 -04:00
Tyler Goodlet b4f1ec7960 Massively simplify the cross-hair monstrosity
Stop with all this "main chart" special treatment.
Manage all lines in the same way across all referenced plots.
Add `CrossHair.add_plot()` for adding new plots dynamically.

Just, smh.
2020-10-02 12:13:28 -04:00
Tyler Goodlet c56aee6347 Use array of names for lookup 2020-10-02 12:13:28 -04:00
Tyler Goodlet 788771bd75 Change name to qtractor 2020-10-02 12:13:28 -04:00
Tyler Goodlet 3aebeb5801 Standardize ohlc dtype 2020-10-02 12:13:28 -04:00
Tyler Goodlet e5bca1e089 Fix import error 2020-10-02 12:13:28 -04:00
Tyler Goodlet 88fb7a8951 Handle overloaded arg 2020-10-02 12:13:28 -04:00
Tyler Goodlet 1a1e768126 Port to new data apis 2020-10-02 12:13:28 -04:00
Tyler Goodlet 6802675637 Add kraken to backend list 2020-10-02 12:13:28 -04:00
Tyler Goodlet f9084b8650 Store lines graphics in struct array to simplify indexing 2020-10-02 12:13:28 -04:00
Tyler Goodlet b9224cd396 Add WIP real-time 5s bar charting 2020-10-02 12:13:28 -04:00
Tyler Goodlet 4c5bc19ec7 Always convert to posix time 2020-10-02 12:13:28 -04:00
Tyler Goodlet 5f89a2bf08 Make run_qtrio invoke tractor at top level 2020-10-02 12:13:28 -04:00
Tyler Goodlet 2dec32e41f Move bar generation into func; support bar appends
There's really nothing coupling it to the graphics class (which frankly
also seems like it doesn't need to be a class.. Qt).

Add support to `.update_from_array()` for diffing with the input array
and creating additional bar-lines where necessary. Note, there are still
issues with the "correctness" here in terms of bucketing open/close
values in the time frame / bar range. Also, this jamming of each bar's 3
lines into a homogeneous array seems like it could be better done with
struct arrays and avoid all this "index + 3" stuff.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 3c55f7c6e2 Use structure array indexing syntax 2020-10-02 12:13:28 -04:00
Tyler Goodlet 9c1d64413e Handle flat bar updates
Flat bars have a rendering issue we work around by hacking values in `QLineF`
but we have to revert those on any last bar that is being updated in
real-time. Comment out candle implementations for now; we can get back
to it if/when the tinas unite. Oh, and make bars have a little space
between them.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 6b1bdbe3ea Docs the ui pkg mod 2020-10-02 12:13:28 -04:00
Tyler Goodlet 013c0fef15 Fix a bunch of scrolling / panning logic
Don't allow zooming to less then a min number of data points. Allow
panning "outside" the data set (i.e. moving one of the sequence "ends"
to the middle of the view. Start adding logging.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 4c753b5ee6 Add ib 2020-10-02 12:13:28 -04:00
Tyler Goodlet ecfa6d33aa Use msgpack-numpy 2020-10-02 12:13:28 -04:00
Tyler Goodlet 16e2e27cb8 Handle high = low bars
For whatever reason if the `QLineF` high/low values are the same a weird
little rectangle is drawn (my guess is a `float` precision error of some
sort). Instead, if they're the same just use one of the values.
Also, store local vars to avoid so many lookups.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 7a660b335d Make search work with ib backend 2020-10-02 12:13:28 -04:00
Tyler Goodlet 99c18abfea Add symbol search to broker api 2020-10-02 12:13:28 -04:00
Tyler Goodlet 2f1fdaf9e5 Rework charting internals for real-time plotting
`pg.PlotCurveItem.setData()` is normally used for real-time updates to
curves and takes in a whole new array of data to graphics.
It makes sense to stick with this interface especially if
the current datum graphic will originally be drawn from tick quotes and
later filled in when bars data is available (eg. IB has this option in
TWS charts for volume). Additionally, having a data feed api where the push
process/task can write to shared memory and the UI task(s) can read from
that space is ideal. It allows for indicator and algo calculations to be
run in parallel (via actors) with initial price draw instructions
such that plotting of downstream metrics can be "pipelined" into the
chart UI's render loop. This essentially makes the chart UI async
programmable from multiple remote processes (or at least that's the
goal).

Some details:
- Only store a single ref to the source array data on the
  `LinkedSplitCharts`.  There should only be one reference since the main
  relation is **that** x-time aligned sequence.
- Add `LinkedSplitCharts.update_from_quote()` which takes in a quote
  dict and updates the OHLC array from it's contents.
- Add `ChartPlotWidget.update_from_array()` method to trigger graphics
  updates per chart with consideration for overlay curves.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 5e8e48c7b7 Support updating bars graphics from array
This makes a OHLC graphics "sequence" update very similar (actually API
compatible) with `pg.PlotCurveItem.setData()`. The difference here is
that only latest OHLC datum is used to update the charts last bar.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 048a13dd0e Drop disk caching of quotes 2020-10-02 12:13:28 -04:00
Tyler Goodlet 6ba0692851 Revert weird bad .time access 2020-10-02 12:13:28 -04:00
Tyler Goodlet d993147f78 Factor signalling api into new module 2020-10-02 12:13:28 -04:00
Tyler Goodlet cc4b51cb17 Rip out all usage of `quantdom.bases.Quotes` smh. 2020-10-02 12:13:28 -04:00
Tyler Goodlet 14bff66ec5 Add a sane pandas.DataFrame to recarray converter 2020-10-02 12:13:28 -04:00
Tyler Goodlet 0b5af4b590 Move all Qt components into top level ui module 2020-10-02 12:13:28 -04:00
Tyler Goodlet 82a5daf91b Move all kivy ui components to subpackage 2020-10-02 12:13:28 -04:00
Tyler Goodlet 9d6dffe5ec Cleanup yrange auto-update callback
This was a mess before with a weird loop using the parent split charts
to update all "indicators". Instead just have each plot do its own
yrange updates since the signals are being handled just fine per plot.
Handle both the OHLC and plane line chart cases with a hacky `try:,
except IndexError:` for now.

Oh, and move the main entry point for the chart app to the relevant
module. I added some WIP bar update code for the moment.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 36ac26cdcf Add zeroed ohlc array constructor 2020-10-02 12:13:28 -04:00
Tyler Goodlet 51f302191a Add update method for last bars graphic 2020-10-02 12:13:28 -04:00
Tyler Goodlet b82587f665 Use a single array for all lines
Speed up the lines array creation using proper slice assignment.
This gives another 10% speedup to the historical price rendering.
Drop ``_tina_mode`` support for now since we're not testing it.
2020-10-02 12:13:28 -04:00
Tyler Goodlet 45906c2729 Render plots from provided input sequence(s)
Previously graphics were loaded and rendered implicitly during the
import and creation of certain objects. Remove all this and instead
expect client code to pass in the OHLC sequence to plot. Speed up
the bars graphics rendering by simplifying to a single iteration of
the input array; gives about a 2x speedup.
2020-10-02 12:13:28 -04:00
Tyler Goodlet f77a39ceb7 Add symbol-info command 2020-10-02 12:13:28 -04:00
Tyler Goodlet 613564b0f5 Add ui package mod 2020-10-02 12:13:28 -04:00
Tyler Goodlet 507368a13a Don't scroll right after max zoom 2020-10-02 12:13:28 -04:00
Tyler Goodlet 6fa173a1c1 Factor components into more suitably named modules 2020-10-02 12:13:28 -04:00
Tyler Goodlet ac389c30d9 Move drawing and resize behavior into chart widget 2020-10-02 12:13:28 -04:00
Tyler Goodlet d8ca799504 Start grouping interactions into a ``ViewBox``
Move chart resize code into our ``ViewBox`` subtype (a ``ChartView``)
in an effort to start organizing interaction behaviour closer to the
appropriate underlying objects. Add some docs for all this and do some
renaming.
2020-10-02 12:13:28 -04:00
Tyler Goodlet fbce0334ad Lol I guess we probably need this 2020-10-02 12:13:28 -04:00
Tyler Goodlet a7fe18cba9 Factor common chart configuration 2020-10-02 12:13:28 -04:00
Tyler Goodlet 730241bb8a Add scrolling from right and cross-hair
Modify the default ``ViewBox`` scroll to zoom behaviour such that
whatever right-most point is visible is used as the "center" for
zooming. Add a "traditional" cross-hair cursor.
2020-10-02 12:13:28 -04:00
Tyler Goodlet c8afdb0adc Styling, start re-org, commenting
- Move out equity plotting to new module.
- Make axis margins and fonts look good on i3.
- Adjust axis labels colors to gray.
- Start commenting a lot of the code after figuring out what it all does
  when cross referencing with ``pyqtgraph``.
- Add option to move date axis to middle.
2020-10-02 12:13:27 -04:00
Tyler Goodlet 2ad3b6f080 Add piker chart command 2020-10-02 12:13:27 -04:00
Tyler Goodlet b670af484c Move UI spawning cmds to new module 2020-10-02 12:13:27 -04:00
Tyler Goodlet eddd8aacab Add charting components from `Quantdom`
Hand select necessary components to get real-time charting with
`pyqtgraph` from the `Quantdom` projects:
https://github.com/constverum/Quantdom

We've offered to collaborate with the author but have received no
response and the project has not been updated in over a year.
Given this, we are moving forward with taking the required components to
make further improvements upon especially since the `pyqtgraph` project
is now being actively maintained again.

If the author comes back we will be more then happy to contribute
modified components upstream:
https://github.com/constverum/Quantdom/issues/18

Relates to #80
2020-10-02 12:13:27 -04:00
Tyler Goodlet 9c84e3c45d Add initial Qt-trio integration
Use the new "guest mode" available on trio master branch.  Add
entrypoint for `pyqtgraph` based charting based on the `Quantdom`
project.
2020-10-02 12:13:27 -04:00
Tyler Goodlet bb81d7881c Use qt5 and trio guest mode 2020-10-02 12:13:27 -04:00
Tyler Goodlet 2774611617 Blind stab at a basic chart 2020-10-02 12:13:27 -04:00
Tyler Goodlet 2f8737af6a Fix PURE contracts lookup... 2020-09-29 17:06:28 -04:00
Tyler Goodlet 5bb11826f3 Drop unmarketable trades for now 2020-09-29 17:06:28 -04:00
Tyler Goodlet aad9cb2dd0 Support forex pair lookup on ib 2020-09-29 17:06:28 -04:00
Tyler Goodlet b499631d62 Drop to 1k bars on init load 2020-09-29 17:06:28 -04:00
Tyler Goodlet ad08cb7a66 Try to find cad stocks 2020-09-29 17:06:28 -04:00
Tyler Goodlet 103014aa58 Properly teardown data feed on cancel 2020-09-29 17:06:28 -04:00
Tyler Goodlet b7c924046a Begin to use `@tractor.msg.pub` throughout streaming API
Since the new FSP system will require time aligned data amongst actors,
it makes sense to share broker data feeds as much as possible on a local
system. There doesn't seem to be downside to this approach either since
if not fanning-out in our code, the broker (server) has to do it anyway
(and who knows how junk their implementation is) though with more
clients, sockets etc. in memory on our end. It also preps the code for
introducing a more "serious" pub-sub systems like zeromq/nanomessage.
2020-09-29 17:06:28 -04:00
Tyler Goodlet 0bf265a96f Future todo 2020-09-29 17:06:28 -04:00
Tyler Goodlet 482dc510fa Add normalization step for ticks
Start a draft normalization format for (sampled) tick data.
Ideally we move toward the dense tick format (DFT) enforced by
techtonicDB, but for now let's just get a dict of something simple
going: `{'type': 'trade', 'price': <price}` kind of thing. This
gets us started being able to real-time chart from all data feed
back-ends. Oh, and hack in support for XAUUSD..and get subactor
logging workin.
2020-09-29 17:06:28 -04:00
Tyler Goodlet aeb58c03e2 Add startup logic to handle market closure 2020-09-29 17:06:28 -04:00
Tyler Goodlet 4ce99e62e0 Override annoying stuff in ib_insync 2020-09-29 17:06:28 -04:00
Tyler Goodlet 41c6517a23 Port to new streaming api, yield whole tickers 2020-09-29 17:06:28 -04:00
Tyler Goodlet 450a39ce1c Add better contract search/lookup
Add a `Client.find_contract()` which internally takes
a <symbol>.<exchange> str as input and uses `IB.qualifyContractsAsync()`
internally to try and validate the most likely contract. Make the module
script call this using `asyncio.run()` for console testing.
2020-09-29 17:06:28 -04:00
Tyler Goodlet b8209cd506 Add a mostly actor aware API to IB backend
Infected `asyncio` support is being added to `tractor` in
goodboy/tractor#121 so delegate to all that new machinery.

Start building out an "actor-aware" api which takes care of all the
`trio`-`asyncio` interaction for data streaming and request handling.
Add a little (shudder) method proxy system which can be used to invoke
client methods from another actor. Start on a streaming api in
preparation for real-time charting.
2020-09-29 17:06:28 -04:00
Tyler Goodlet 1abadeb506 Add initial IB broker backend using ib_insync
Start working towards meeting the backend client api.
Infect `asyncio` using `trio`'s new guest mode and demonstrate
real-time ticker streaming to console.
2020-09-29 17:06:28 -04:00
Tyler Goodlet 14a5d047c3 Copy forward stupid kraken zeroed vwaps 2020-09-29 16:42:28 -04:00
Tyler Goodlet b13da849d0 Include vwap in kraken historical bars 2020-09-29 16:42:06 -04:00
Tyler Goodlet 0b42ac1420 Normalize kraken quotes for latency tracking 2020-09-26 11:31:57 -04:00
Tyler Goodlet ea8205968c Begin to use `@tractor.msg.pub` throughout streaming API
Since the new FSP system will require time aligned data amongst actors,
it makes sense to share broker data feeds as much as possible on a local
system. There doesn't seem to be downside to this approach either since
if not fanning-out in our code, the broker (server) has to do it anyway
(and who knows how junk their implementation is) though with more
clients, sockets etc. in memory on our end. It also preps the code for
introducing a more "serious" pub-sub systems like zeromq/nanomessage.
2020-09-26 11:31:57 -04:00
Tyler Goodlet 44010abf4d Handle (far end forced) disconnects 2020-09-26 11:31:57 -04:00
Tyler Goodlet 03c5c7d2ba Trigger connection reset on slowed heartbeat 2020-09-26 11:31:57 -04:00
Tyler Goodlet e92abd376a Trace log the heartbeat 2020-09-26 11:31:57 -04:00
Tyler Goodlet bf9a0136df Make ws loop restart on connection failures 2020-09-26 11:31:57 -04:00
Tyler Goodlet d976f3d074 Generate tick data correctly using .etime 2020-09-26 11:31:57 -04:00
Tyler Goodlet ad92188703 Support new normalized ticks format with kraken
Generate tick datums in a list under a `ticks` field in each quote
kinda like how IB does it.
2020-09-26 11:31:57 -04:00
Tyler Goodlet 9976bc3a3b Fix typo 2020-09-26 11:31:57 -04:00
Tyler Goodlet 3655e449d6 Raise errors, fix module script entry 2020-09-26 11:31:57 -04:00
Tyler Goodlet ffe47acf1d Add historical bars retreival 2020-09-26 11:31:57 -04:00
Tyler Goodlet 7bccfc7b10 Convert to stream, parse into dataclass 2020-09-26 11:31:57 -04:00
Tyler Goodlet 2738b54851 Start kraken backend 2020-09-26 11:31:57 -04:00
goodboy 67a75c3080
Merge pull request #114 from pikers/facepalm
Add marketstore cli stuff; not sure how this got missed?!
2020-09-26 11:29:36 -04:00
Tyler Goodlet 53eb564f06 Add marketstore cli stuff; not sure how this got missed?! 2020-09-25 16:08:15 -04:00
Tyler Goodlet 05d2985f5f Clarify some odd spots 2020-09-02 11:32:54 -04:00
Tyler Goodlet 316137fdf2 Begin to wrap marketstore as a data feed
Wrap the sync client in an async interface in anticipation of an actual
async client. This starts support for the `open_fee()`/`stream_quotes()`
api though the tick normalization isn't correct yet.
2020-09-02 00:40:35 -04:00
Tyler Goodlet 702c63f607 Define "packetizer" in specific broker mod
Allows for formatting published quotes using a broker specific
formatting callback.
2020-09-02 00:36:19 -04:00
Tyler Goodlet 312169e790 Support the `stream_quotes()` api in questrade backend 2020-09-01 20:55:24 -04:00
Tyler Goodlet 60b74ad7d1 Use new method name 2020-09-01 20:53:45 -04:00
Tyler Goodlet a6de623147 Add search command to cli 2020-09-01 20:53:27 -04:00
Tyler Goodlet 75f98276cc Add symbol search to broker api 2020-09-01 20:53:04 -04:00
Tyler Goodlet 519712e128 Add stocks search to qt client 2020-09-01 20:52:01 -04:00
Tyler Goodlet 934108a024 Add symbol-info command 2020-09-01 20:51:09 -04:00
Tyler Goodlet dcb0a30ad6 Move UI spawning cmds to new module 2020-09-01 20:47:24 -04:00
Tyler Goodlet 3c4699abef Pass broker name 2020-09-01 18:31:52 -04:00
Tyler Goodlet 78784a4bf3 Port to new data apis 2020-09-01 18:30:55 -04:00
Tyler Goodlet 57a8db8cba Start enforcing a common stream setup api
Add routines for brokerd spawning and quote stream creation.
2020-09-01 18:18:48 -04:00
Tyler Goodlet f6f6d98a95 Allow passing in tbk keys to query 2020-09-01 18:14:11 -04:00
Tyler Goodlet bc9af977a4 Update quote cache on each loop 2020-09-01 13:25:41 -04:00
Tyler Goodlet 436e4d2df4 Add tbk tick streaming with trio-websocket 2020-09-01 13:25:41 -04:00
Tyler Goodlet acd32341e2 Fix assignment out of order 2020-09-01 13:25:41 -04:00
Tyler Goodlet 3cfb15ed6e Make monitor handle non-full quote messages 2020-09-01 13:25:41 -04:00
Tyler Goodlet d66cfb8fa0 Push only new key value pairs over quote streams
This is something I've been meaning to try for a while and will likely
make writing tick data to a db more straight forward (filling in NaN
values is more matter of fact) plus it should minimize bandwidth usage.
Note, it'll require stream consumers to be considerate of non-full
quotes arriving and thus using the first "full" quote message to fill
out dynamically formatted systems or displays.
2020-09-01 13:25:41 -04:00
Tyler Goodlet 335cee63b2 Make stock quote formatter work with diff streams 2020-09-01 13:25:41 -04:00
Tyler Goodlet a6c692fb8b Add support for TICK ingest to marketstore 2020-09-01 13:25:09 -04:00
Tyler Goodlet b58820e297 Relicense to AGPLv3 2020-06-16 00:12:19 -04:00
Tyler Goodlet 2c93bb0302 Drop use of deprecated `trio.Event.clear()` 2020-06-02 10:33:57 -04:00
Tyler Goodlet 882f4a28d1 Add privacy note 2020-06-01 14:43:39 -04:00
Tyler Goodlet 64993666fa Pull 100 bars by default 2020-05-26 14:49:50 -04:00
Tyler Goodlet 5f200b8db1 Always delay bars 15m; rename to volume 2020-05-26 14:49:50 -04:00
Tyler Goodlet a7f7de32b4 Docstring tweaks 2020-05-26 14:49:50 -04:00
Tyler Goodlet ffd8bdac5f Fix imports 2020-05-26 14:49:50 -04:00
Tyler Goodlet 9b91ecd408 Pass confdir and watchlist path to cli 2020-05-26 14:49:50 -04:00
Tyler Goodlet 057086efdb Pass through test file to monitor 2020-05-26 14:49:50 -04:00
Tyler Goodlet f798d13038 Reord watchlist cmds into new package 2020-05-26 14:49:50 -04:00
Tyler Goodlet ff843372a1 Add `piker bars` command
For easy testing of questrade historical data from cli.
Re-org the common cli components into a new package to avoid having all
commands defined in a top-level module.
2020-05-26 14:49:50 -04:00
Tyler Goodlet c11946988e Implement candles retrieval from Questrade
There's some expected limitations with the number of sticks allowed in
a single query (they say 2k but I've been able to pull 20k). Also note
without a paid data sub there's a 15m delay on 1m sticks (we'll hack
around that shortly, don't worry).
2020-05-26 14:49:50 -04:00
Tyler Goodlet 595f79c632 Add symbol not found 2020-05-26 14:49:50 -04:00
Tyler Goodlet 732638ae2d Delegate logging to `tractor`
Gives us PIDs and task ids in logs which is much more sane for
debugging and cuts down on superfluous code.
2020-02-29 12:29:20 -05:00
Tyler Goodlet 837e30ff68 use >1 asks session connections
Gets us better throughput when polling multiple endpoints (eg. option
and stock quotes simultaneously) since slower round trip request won't
block faster ones when using multiple connections.
2020-02-18 16:13:20 -05:00
Tyler Goodlet a2e5d07b2c Port to mainline kivy and Python 3.8
This required some copy-paste of code from @matham's branch:
https://github.com/kivy/kivy/pull/5241

namely, the stuff in the `utils_async.py` module. I've added all that as
a standalone file for now.

Update the pipfile to use `kivy`'s master branch (since there seems to
be some lingering cython issues in the current release wheels).
2019-11-21 10:21:43 -05:00
Tyler Goodlet 49d612de49 Port to new @tractor.stream API 2019-04-26 00:27:01 -04:00
Tyler Goodlet 1cc33abca0 Don't bail when a sub-optschain crashes 2019-03-24 12:09:17 -04:00
Tyler Goodlet b2252e5762 Fix bad import 2019-03-21 22:18:09 -04:00
Tyler Goodlet 8bf82a2f76 Allow spawning an optschain UI from monitor using the `o` keybinding 2019-03-21 22:15:08 -04:00
Tyler Goodlet d59283d36d Update optschain cli entrypoint to pass primitive arg types 2019-03-21 22:14:22 -04:00
Tyler Goodlet 884fcaa88e A slew of tiny pager improvements
- stop displaying search bar widget on <ctrl-c>
- if there's existing search bar content highlight it automatically
  to allow user to start typing new content right away
- when activated allow search bar to insert its own set of keybinding
  controls; restore prior bindings on exit
2019-03-21 22:01:50 -04:00
Tyler Goodlet 3bbb1db2b4 Make option chain spawnable as a subactor
Look up the broker module and set up the loglevel locally.
Ask the arbiter for a portal to the data daemon since we can't
pass one to a subactor by reference.
2019-03-21 21:50:55 -04:00
Tyler Goodlet fc1e63b2c1 Spawn keyboard functions in new tasks 2019-03-18 22:39:21 -04:00
Tyler Goodlet c8da096126 Track table's last clicked row 2019-03-18 22:38:32 -04:00
Tyler Goodlet 3a439fc99d Fix ask use logic for testing/CI 2019-03-17 23:03:45 -04:00
Tyler Goodlet 6a50049af7 Use toml instead of ini for broker config 2019-03-15 19:37:04 -04:00
Tyler Goodlet 5e9c38039c Move brokerd spawner to `brokers.core` 2019-02-25 22:29:48 -05:00
Tyler Goodlet d3fae00e74 Add a `configdir` cli option 2019-02-25 20:22:29 -05:00
Tyler Goodlet 747d703d92 Add hack-fix to avoid leaking cmdline flags to kivy 2019-02-25 20:14:36 -05:00
Tyler Goodlet 77548d2ee6 Add token-from-user toggles to token auth methods 2019-02-25 20:11:45 -05:00
Tyler Goodlet 130553b8df Accept a path arg to `write()` 2019-02-25 19:29:54 -05:00
Tyler Goodlet 295ccbbe64 Name the data what it is 2019-02-24 10:55:52 -05:00
Tyler Goodlet c1a398d826 Use click context to factor cmd options 2019-02-23 16:13:04 -05:00
Tyler Goodlet 7ee731faac Use trio memory channels throughout UIs 2019-02-21 23:09:19 -05:00
Tyler Goodlet cbb973ae9d Drop internal nursery from option chain 2019-02-21 23:07:44 -05:00
Tyler Goodlet 462c419970 Add basic practice account support 2019-02-21 17:24:50 -05:00
Tyler Goodlet 435b2a56e8 Remove stream opening lock on `DataFeed`
Fixes to `tractor` that resolve issues with async generators being
non-task safe make the need for the mutex lock in
`DataFeed.open_stream()` unnecessary. Also, don't bother pushing empty
quotes from the publisher; avoids hitting the network when possible.
2019-02-20 21:39:57 -05:00
Tyler Goodlet 3a6efd451d Don't bother ensuring all symbols in data 2019-02-10 19:09:54 -05:00
Tyler Goodlet 3ab9e28ddb Use brokerd's client to get all contracts 2019-02-09 21:58:27 -05:00
Tyler Goodlet 395f0c8e4a Synchronize Questrade token refreshing per client
Questrade's API is half baked and can't handle concurrency.
It allows multiple concurrent requests to most endpoints *except*
for the auth endpoint used to refresh tokens:

    https://www.questrade.com/api/documentation/security

I've gone through extensive dialogue with their API team and despite
making what I think are very good arguments for doing the request
serialization on the server side, they decided that I should instead
do the "locking" on the client side. Frankly it doesn't seem like they
have that competent an engineering department as it took me a long time
to explain the issue even though it's rather trivial and probably not
that hard to fix; maybe it's better this way.

This adds a few things to ensure more reliable token refreshes on
expiry:

- add a `@refresh_token_on_err` decorator which can be used on `_API`
  methods that should refresh tokens on failure
- decorate most endpoints with this *except* for the auth ep
- add locking logic for the troublesome scenario as follows:
  * every time a request is sent out set a "request in progress" event
    variable that can be used to determine when no requests are currently
    outstanding
  * every time the auth end point is hit in order to refresh tokens set
    an event that locks out other tasks from making requests
  * only allow hitting the auth endpoint when there are no "requests in
    progress" using the first event
  * mutex all auth endpoint requests; there can only be one outstanding

- don't hit the accounts endpoint at client startup; we want to
  eventually support keys from multiple accounts and you can disable
  account info per key and just share the market data function
2019-02-09 21:39:22 -05:00
Tyler Goodlet f6230dd6df Add a `DataFeed.call_client()` method
Allows for calling an actor local broker client's methods from a remote
actor.
2019-02-09 21:38:00 -05:00
Tyler Goodlet 026b015627 Allow passing a config path for broker testing in CI 2019-02-04 00:17:11 -05:00
Tyler Goodlet 5dac8fa44d Note the RH auth/account requirements for usage 2019-02-04 00:15:10 -05:00
Tyler Goodlet e91a50a1ba Make `get_cached_feed()` an asynccontextmanager
Adjust feed locking around internal manager `yields` to make this work.

Also, change quote publisher to deliver a list of quotes for each
retrieved batch. This was actually broken for option streaming since
each quote was being overwritten due to a common `key` value for all
expiries. Asjust the `packetizer` function accordingly to work for
both options and stocks.
2019-02-03 23:40:51 -05:00
Tyler Goodlet 2514843fc1 Port to the new `@tractor.msg.pub` decorator API
The pub-sub data feed system was factored into `tractor` as an
experimental api / subsystem. Move to using that which greatly
simplifies the data feed architecture.
2019-01-27 14:50:04 -05:00
Tyler Goodlet 22670afe58 Generalize the publisher/fan-out system
Start working toward a more general (on-demand) pub-sub system which
can be brought into ``tractor``. Right now this just means making
the code in the `fan_out_to_ctxs()` less specific but, eventually
I think this function should be coupled with a decorator and shipped
as a standard "message pattern".

Additionally,
- try out making `BrokerFeed` a `@dataclass`
- strip out all the `trio.Event` / uneeded nursery / extra task crap
  from `start_quote_stream()`
2019-01-14 21:23:49 -05:00
Tyler Goodlet c94ce47aa6 Always set contract sub state 2019-01-14 21:13:22 -05:00
Tyler Goodlet 4753dc2db8 Alway teardown quote gen on exit 2019-01-14 21:12:35 -05:00
Tyler Goodlet 36d0c2ed68 Port monitor app to `DataFeed` api 2019-01-05 19:08:31 -05:00
Tyler Goodlet a4501bb0e0 Factor `DataFeed` client API into `brokers.data` 2019-01-05 19:08:27 -05:00
Tyler Goodlet 7f8c88be0c Drop open/close prices for now; never really use them 2019-01-02 21:24:42 -05:00
Tyler Goodlet fa6bae1f5c Reorg table widgets into a new module 2019-01-02 21:12:42 -05:00
Tyler Goodlet 4895690642 Display a message when no contracts exist 2019-01-01 23:42:49 -05:00
Tyler Goodlet 0cffa4b97a Font size shrinks 2019-01-01 23:36:46 -05:00
Tyler Goodlet 32a7f4cbd3 Right, gotta expose widgets to other actors 2018-12-31 11:51:04 -05:00
Tyler Goodlet 72f417b9c2 Support monitor linked symbol selection
This allows for using a monitor to select the current option chain
symbol!

The deats:
- start a bg task which streams the monitor selected symbol
- dynamically repopulate expiry buttons on a newly published symbol
- move static widget creation into a chain method to avoid multiple
  quotes requests at startup
- rename a bunch of methods
2018-12-30 15:00:46 -05:00
Tyler Goodlet 152062ba8a Support pub-sub of monitor's symbol selection 2018-12-30 14:59:54 -05:00
Tyler Goodlet 3ed750d324 Add contract table type headers 2018-12-29 16:01:07 -05:00
Tyler Goodlet b4fad3f6a9 Logic factoring 2018-12-29 16:00:18 -05:00
Tyler Goodlet 1866dd1812 Fix for adjusted contracts subscription bug
If quotes are pushed using the adjusted contract symbol (i.e. with
trailing '-1' suffix) the subscriber won't receive them under the
normal symbol. The logic was wrong for determining whether to add
a suffix (was failing for any symbol with an exchange suffix)
which was causing normal data feed subscriptions to fail to match
in every case.

I did some testing of the `optionsIds` parameter to the option quote
endpoint and found that it limits you to 100 symbols so it's not
practical for real-time "all-strike"" chain updating; we have to stick
to filters for now. The only real downside of this is that it seems
multiple filters across multiple symbols is quite latent. I need to
toy with it more to be sure it's not something slow on the client side.
Oh, and store option contract to ids in a `dict` for now as we may want
to try the `optionsIds` thing again down the road as I coordinate with
the QT tech team.
2018-12-29 15:44:32 -05:00
Tyler Goodlet dc581d0bdc Handle "adjusted contract" chains per root 2018-12-26 13:30:50 -05:00
Tyler Goodlet fb876f3770 Drop `OptionChain.start_feed()` 2018-12-25 12:38:04 -05:00
Tyler Goodlet a7fb55179c Handle weekend data from QT yet again 2018-12-23 21:26:57 -05:00
Tyler Goodlet de4fab873b Ids should be allowed without contracts 2018-12-23 21:25:56 -05:00
Tyler Goodlet eb8c9e1a99 Symbol subs must be cid specific 2018-12-23 20:48:06 -05:00
Tyler Goodlet 11222e1176 Only resort when the sort field actually changed 2018-12-18 20:28:26 -05:00
Tyler Goodlet d4e36b1e55 Jeeze, don't overwrite the payload for each channel... 2018-12-17 19:15:29 -05:00
Tyler Goodlet 5af90c044f Drop contracts cache; that wasn't the bottleneck
This also fixes a bug where option subscriptions weren't actually being
changed when a new call was made..
2018-12-16 23:56:03 -05:00
Tyler Goodlet 3fd01c42f2 Define highlight on click logic in `Cell` 2018-12-15 19:42:15 -05:00
Tyler Goodlet 1f608b2498 Even less latent 2018-12-15 19:41:12 -05:00
Tyler Goodlet a13b13e144 Highlight current expiry; mutex data feed access 2018-12-15 19:40:54 -05:00
Tyler Goodlet 7ed409501d Even less bouncy 2018-12-15 16:38:33 -05:00
Tyler Goodlet 07eb8ae5e0 Use binary search (bisection) to sort table rows
This is an optimization to improve performance when the UI is fed real
time data. Instead of resorting all rows on every quote update, only
re-render when the sort key appears in the quote data, and further, only
resort rows which are changed using bisection based widget insertion to
avoid having `kivy` re-add widgets (and thus re-render graphics) more
often than absolutely necessary.
2018-12-15 16:28:28 -05:00
Tyler Goodlet 721e3803b2 Shorter title of IV: implied volatility 2018-12-15 16:27:41 -05:00
Tyler Goodlet 70435e3b15 Always push an option smoke quote for UI init 2018-12-15 16:26:54 -05:00
Tyler Goodlet e3a3a8765c Remove destroyed widgets from mouse over list 2018-12-15 16:26:21 -05:00
Tyler Goodlet 948ee3cadf Cache contracts lookup once at startup 2018-12-13 13:11:07 -05:00
Tyler Goodlet 9e4786e62f Initial dynamic option chain UI draft
There's still a ton to polish (and some bugs to fix) but this is a first
working draft of a real-time option chain!

Insights and todos:
- `kivy` widgets need to be cached and reused (eg. rows, cells, etc.)
  for speed since it seems creating new ones constantly is quite taxing
  on the CPU
- the chain will tear down and re-setup the option data feed stream each
  time a different contract expiry button set is clicked
- there's still some weird bug with row highlighting where it seems rows
  added from a new expiry set (which weren't previously rendered) aren't
  being highlighted reliably
2018-12-13 13:04:05 -05:00
Tyler Goodlet 743ca6bfe3 Log quotes even without caching 2018-12-11 17:09:59 -05:00
Tyler Goodlet 7b5c73bb45 Use pythonic sequence splitting with `zip()` 2018-12-11 17:09:36 -05:00
Tyler Goodlet e1be80e9e0 Subscription teardown is done server side on disconnect now 2018-12-11 15:22:34 -05:00
Tyler Goodlet e7378538f6 Limit option chain to 1 rps 2018-12-11 15:21:45 -05:00
Tyler Goodlet 66ecb4c0cb Use a `trio.Event` to guarantee respawning of data feed task 2018-12-11 15:21:12 -05:00
Tyler Goodlet 01c0551a7f Don't display greeks besides delta for now 2018-12-11 15:20:24 -05:00
Tyler Goodlet 201919eef7 Initial option chain UI
Spin it up with `piker optschain`.
Still lots of polishing and features to add but it's a start!
2018-12-10 02:00:10 -05:00
Tyler Goodlet 8647216b75 Tabular kivy UI improvements
`Row`:
- `no_cell`: support a list of keys for which no cells will be created
- allow passing in a `cell_type` at instantiation

`TickerTable`:
- keep track of rendered rows via a private `_rendered` set
- don't create rows inside `append_row()` expect caller to do it
- never render already rendered widgets in `render_rows()`

Miscellaneous:
- generalize `update_quotes()` to not be tied to specific quote fields
  and allow passing in a quote `formatter()` func
- don't bother creating a nursery block until necessary in main
- more commenting
2018-12-10 01:51:49 -05:00
Tyler Goodlet 20778b02b5 Format numerical option fields 2018-12-10 01:50:00 -05:00
Tyler Goodlet 54261ecc4c Refer to async exit stack via feed 2018-12-10 01:49:19 -05:00
Tyler Goodlet fb47ea2e5a Define option field structure
Add some extra fields to each quote that QT should already be
providing (instead of hiding them in the symbol and request contract
info); namely, the expiry and contact type (i.e. put or call).
Define the base set of fields to be displayed in an option chain
UI and add a quote formatter.
2018-12-09 13:40:26 -05:00
Tyler Goodlet 9c7ca84fef Include strike and expiry in option quotes 2018-12-09 13:40:26 -05:00
Tyler Goodlet 9f3a316ccf Improve CPU usage using a clock trigger and deque
Copy out `kivy.clock.triggered` from version 1.10.1 since it isn't yet
available in the `trio`/async branch and use it to throttle the callback
rate. Use a `collections.deque` to LIFO iterate widgets each call
using the heuristic that it's more likely the mouse is still within the
currently highlighted (or it's adjacent neighbors) widget as opposed
to some far away widget (the case when the mouse is moved very
drastically across the window).
2018-12-09 13:39:38 -05:00
Tyler Goodlet b8815cde4a Set statespace defaults in `get_cached_feed()` 2018-12-09 13:30:34 -05:00
Tyler Goodlet eee19048f0 Support "mouse over" groups
Add a type factory func which returns mixin-able types for creating
mutex highlight-able groups of widgets.
2018-12-01 19:01:36 -05:00
Tyler Goodlet fd94a24d84 Rename to `mouse_over` 2018-12-01 18:43:44 -05:00
Tyler Goodlet 5c070b1c43 Faster highlighting via single loop and callback
Thanks yet again to @tshirtman for suggesting this.

Instead of defining a `on_mouse_pos()` on every widget simply
register and track each widget and loop through them all once (or as much
as is necessary) in a single callback. The assumption here is that we
get a performance boost by looping widgets instead of having `kivy` loop
and call back each widget thus avoiding costly python function calls.
2018-12-01 18:39:01 -05:00
Tyler Goodlet 7378a16b90 s/tickers/symbols 2018-12-01 16:12:46 -05:00
Tyler Goodlet 2915e83324 Warn about missing symbols at CLI level 2018-12-01 16:11:38 -05:00
Tyler Goodlet 61294c6c44 Adhere to the same non-found-symbol behaviour as QT 2018-12-01 16:09:41 -05:00
Tyler Goodlet f35671cc88 Handle bad symbol names 2018-12-01 16:08:03 -05:00
Tyler Goodlet 288ea604af Call start_quote_stream() from monitor main 2018-11-30 08:17:54 -05:00
Tyler Goodlet c2ec4800d6 Port cli to new options api 2018-11-30 08:16:31 -05:00
Tyler Goodlet cabc616b85 Port option api to new backend broker api 2018-11-30 08:14:36 -05:00
Tyler Goodlet c7cf0cde9c Add options streaming
Well that was a doozy; had to rejig pretty much all of it.

The deats:
- Track broker components in a new `DataFeed` namedtuple
- port to new list based batch quotes (not dicts any more)
- lock access to cached broker-client / data-feed instantiation
- respawn tasks that fail due to the network
2018-11-30 08:13:30 -05:00
Tyler Goodlet cd7d8d024d Add option quoter support for streaming
So much changed to get this working for both stocks and options:
- Index contracts by a new `ContractsKey` named tuple
- Move to pushing lists of quotes instead of dicts since option
  subscriptions are often not identified by their "symbol" key and
  this makes it difficult at fan out time to know how a quote should
  be indexed and delivered. Instead add a special `key` entry to each
  quote dict which is the quote's subscription key.
2018-11-30 00:33:40 -05:00
Tyler Goodlet 75d22c6058 An explicit name is prolly better 2018-11-25 19:23:07 -05:00
Tyler Goodlet 714c203c3e Cache symbol ids where possible
Cache both in the client and at the function call level inside the
quoter context using a `@afifo_cache`.
2018-11-25 15:00:08 -05:00
Tyler Goodlet af464b45ff Add an async function cache with a LIFO policy
Relates to #59
2018-11-25 14:55:55 -05:00
Tyler Goodlet a8a5e836b9 Use static instruction for highlighted row
Instead of all this adding/removing of canvas instructions nonsense
simple add a static "highlighted" rectangle to each row and make its
size very small when there's no mouse over.

Mad props to @tshirtman for showing me the light :D
2018-11-24 16:17:06 -05:00
Tyler Goodlet 488bdb34be Add mouse-over row highlighting 2018-11-23 22:21:53 -05:00
Tyler Goodlet a7f3008d34 Match the author's general apparel
It's still a bit of a shit show, and I've left a lot of commented tweaks
that need to be further played with, but I think this is a much
better look for what I'm considering to be one of the main "entry point"
apps for `piker`. To get any more serious fine tuning the way I want
I may have to talk to some kivy experts as I'm having some headaches
with button borders, padding, and the header row height..

Some of the new changes include:
- port to the new `brokers.data` module
- much darker theme with a stronger terminal vibe
- last trade price and volume amount flash on each trade
- fixed the symbol search bar to be a static height; before it was
  getting squashed oddly when using stacked windows
- make all the cells transparent (for now) such that I can just use
  a row color (relates to cell padding/spacing - can't seem to ditch it)
- start adding type annotations
2018-11-23 10:50:40 -05:00
Tyler Goodlet 0f3faec35d Reduce the scroll boundary bounce 2018-11-22 19:39:40 -05:00
Tyler Goodlet d102b82566 Don't add more then one stderr handler 2018-11-22 16:31:01 -05:00
Tyler Goodlet b9a9b7a9a3 Add options query and data feed recording commands
Add `contracts` and `optsquote` commands for querying option contracts
info and market quotes respectively. Add a `record` command for
streaming real-time data feed quotes to disk. Port `monitor` to the
new `piker.brokers.data` module. Forward loglevel flags through to
`tractor` for relevant commands.
2018-11-22 16:21:15 -05:00
Tyler Goodlet c23982393d Allow recording data feeds to disk
Add a couple functions for storing and retrieving live json data feed
recordings to disk using a very rudimentary character + newline delimited
format.

Also, split out the pub-sub logic from `stream_quotes()` into a new
func, `fan_out_to_chans()`. Eventually I want to formalize this pattern
into a decorator exposed through `tractor`.
2018-11-22 15:56:02 -05:00
Tyler Goodlet f038fdd42f Add a `contracts()` query
Makes it easy to request all the option contracts for a particular symbol.
Also, let `option_chain()` accept a `date` arg which can be used to only
retrieve quotes for a single expiry date (much faster then getting all
of them).
2018-11-22 15:53:00 -05:00
Tyler Goodlet 247bcb48c0 Tweak options query API method names 2018-11-22 09:19:04 -05:00
Tyler Goodlet 8fe0c40dde Move data feed machinery to separate module 2018-11-14 22:58:12 -05:00
Tyler Goodlet 31c69a5fae Allow specifying number of displayed digits 2018-11-13 18:42:34 -05:00
Tyler Goodlet 0c3bfb9e9e Stack the mktcap + volumes 2018-11-13 18:41:58 -05:00
Tyler Goodlet 6a66b056c8 Compact the look a bit 2018-11-13 18:41:40 -05:00
Tyler Goodlet 19ea7bd7aa Add option-chain cmd 2018-11-13 12:58:05 -05:00
Tyler Goodlet d145a5a219 Rejig option chain schema to capture all contracts 2018-11-13 12:57:21 -05:00
Tyler Goodlet f8d619b183 Go GPLv3 2018-11-12 00:29:43 -05:00
Tyler Goodlet 2b1818ba33 Drop old stream test, rename stock quote func 2018-11-11 21:45:11 -05:00
Tyler Goodlet a5afa0f1c3 Fix typo 2018-11-11 21:06:25 -05:00
Tyler Goodlet f9d9d7c1ba Add option chain quote support! 2018-11-11 21:05:30 -05:00
Tyler Goodlet 82c8fca983 Use tractor.run_daemon() for pikerd 2018-10-18 13:49:20 -04:00
Tyler Goodlet e108bc4521 Must pass a main async func to tractor 2018-09-05 18:31:10 -04:00
Tyler Goodlet 2349de8314 Rename watchlist app to 'monitor' 2018-08-23 23:12:39 -04:00
Tyler Goodlet 421cc4731f Face palm - fix mktcap sorting
Yuh think maybe the default "null" value shouldn't be a string...?

Fixes #46
2018-08-22 23:02:08 -04:00
Tyler Goodlet b2acfdaf42 Fix `pairs` type annotation 2018-08-22 23:01:34 -04:00
Tyler Goodlet 96b17e16ac Handle stale token case on network outage reconnect 2018-08-22 23:01:14 -04:00
Tyler Goodlet f3ac5e3c5f Port to latest tractor api 2018-08-09 21:54:02 -04:00
Tyler Goodlet 3efc7a4f77 Pass through loglevel to tractor 2018-07-06 17:26:45 -04:00
Tyler Goodlet 4427e2869c Cancel symbol unsub if brokerd is already down 2018-07-06 17:26:24 -04:00
Tyler Goodlet 6c977cfb7b Port broker core to tractor; fix chan unsub bug 2018-07-06 17:25:40 -04:00
Tyler Goodlet 31b8277f08 Drop tractor modules 2018-07-06 17:19:25 -04:00
goodboy 6ff871ff7d
Merge pull request #50 from pikers/tractor_draft
Introducing "tractor"
2018-07-05 15:52:53 -04:00
Tyler Goodlet f4a91a4975 Always do symbol unsubscribe on teardown 2018-07-05 15:31:52 -04:00
Tyler Goodlet 73eedfd7b3 Set tractor actor name at startup 2018-07-05 15:31:21 -04:00
Tyler Goodlet aa259433f5 Don't bother unsetting the squeue; let errors propogate up 2018-07-05 15:30:31 -04:00
Tyler Goodlet 0ac564dbf3 Only cancel channel spawned rpc tasks when explicitly notified 2018-07-05 15:27:02 -04:00
Tyler Goodlet e395845ddb Every ticker-chan subscription must include a caller id 2018-07-05 15:23:38 -04:00
Tyler Goodlet 5383dd6446 Add a working arbiter registry system
Every actor now registers (and unregisters) with the arbiter at
startup/teardown. For now the registry is stored in a plain `dict` in
the arbiter's memory. This makes it possible to easily coordinate actors
started as plain Python processes or via `multiprocessing`.

A whole smörgåsbord of changes was required to accomplish this:
- factor handshake steps into a func
- track *every* channel connected to an actor including multiples to the
  same remote peer (may want to optimize this later)
- handle `trio.ClosedStreamError` gracefully in the message loop
- add an `open_portal` asynccontextmanager which handles channel
  creation, handshaking, and spawning a bg task for msg processing
- add a `start_actor()` for starting in-process actors directly
- add working `get_arbiter()` and `find_actor()` public routines
- `_main` now tries an anonymous channel connect to the stated
  arbiter sockaddr and uses that to determine whether to crown itself
2018-07-04 14:34:25 -04:00
Tyler Goodlet 1d3fde4a4d Add StreamQueue.connected() 2018-07-04 03:16:00 -04:00