Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start piker.storage subsys: cross-(ts)db middlewares #486

Open
wants to merge 85 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
29211b2
Start `piker.storage` subsys: cross-(ts)db middlewares
goodboy Mar 9, 2023
7ab97fb
Add marketstore client as storage-backend module
goodboy May 29, 2023
1ec9b05
Move `.data.cli` to `.storage.cli`
goodboy May 29, 2023
cb774e5
Re-implement `piker store` CLI with `typer`
goodboy May 29, 2023
33c4645
Lower the paper engine order-cancel latency
goodboy May 29, 2023
e83de29
Relegate old marketstore cli eps to masked module
goodboy May 30, 2023
8ccb8b0
kucoin: drop shm-array `numpy` dtype def, our default is the same
goodboy May 31, 2023
e82538e
.data: export ohlc dtypes at top level
goodboy May 31, 2023
8485774
Add public config dir getter
goodboy May 31, 2023
bf21d2e
Rename default OHLCV `np.dtype` descriptions
goodboy May 31, 2023
af64152
.data.history: update to new naming
goodboy May 31, 2023
9859f60
Invert data provider's OHLCV field defs
goodboy May 31, 2023
7d1cc47
ROFL, even using `pymarketstore`'s json-RPC it's borked..
goodboy May 31, 2023
94733c4
A PoC tsdb prototype: `parqdb` using `polars`
goodboy May 31, 2023
8de9217
kucoin: fix missing default fields def import
goodboy Jun 1, 2023
7b4f4bf
First draft `.storage.nativedb.` using parquet files
goodboy Jun 2, 2023
0ba3c79
Drop `bar_wap` from default ohlc field set
goodboy Jun 2, 2023
c52e889
First draft history loading rework
goodboy Jun 2, 2023
c020ab7
Clean out marketstore specifics
goodboy Jun 2, 2023
d2accda
Drop remaining mkts nonsense from `store delete`
goodboy Jun 2, 2023
106ebe9
Drop marketstore and tina install from readme, add polars and apache!
goodboy Jun 2, 2023
d027ad5
Whenever there is overlays, set a title on main chart price-y axis!
goodboy Jun 2, 2023
9fd412f
Add basic time-sampling gap detection via `polars`
goodboy Jun 6, 2023
1e683a4
Another guard around sampling subscriber popped race..
goodboy Jun 6, 2023
4f4860c
Update shm.push() type sig style
goodboy Jun 6, 2023
6dc3ed8
Expose a `force_reformat: bool` up through graphics stack
goodboy Jun 6, 2023
f125298
kucoin: support start and end dt based bars queries
goodboy Jun 6, 2023
7a5c43d
Support injecting a `info: dict` to `Sampler.broadcast_all()` calls
goodboy Jun 6, 2023
0dcfcea
Finally get partial backfills after tsdb load workinnn
goodboy Jun 7, 2023
2dbcecd
Generalize time-gap detector to accept unit and threshold
goodboy Jun 8, 2023
54f8a61
Use `code.interact()` in anal subcmd for now
goodboy Jun 8, 2023
f25248c
Add `.data._timeseries` utility mod
goodboy Jun 8, 2023
8233d12
Detect and fill time gaps in tsdb history
goodboy Jun 8, 2023
fda7111
Import from new `.data._timeseries` mod for anal
goodboy Jun 8, 2023
34dd6ff
Add a configurable timeout around backend live feed startup
goodboy Jun 8, 2023
a575e67
Go back to just opening sampler stream inside history update task?
goodboy Jun 8, 2023
c1201c1
Parametrize index margin around gap detection segment
goodboy Jun 8, 2023
f8ab3bd
Allow sampler step events to overrun; only 1s period
goodboy Jun 8, 2023
c1546eb
Add note about appending parquet files on write
goodboy Jun 8, 2023
c8f8724
Mask out all the duplicate frame detection
goodboy Jun 8, 2023
75ff392
ib: fix mega borked hist queries on gappy assets
goodboy Jun 8, 2023
937d8c4
binance: add futes API link, freeze the agg tradez struct
goodboy Jun 8, 2023
5251561
TOCHERRY: into #486, add polars/apache deps for nix
goodboy Jun 13, 2023
0484e97
Try to not overrun shm during gap backfilling..
goodboy Jun 14, 2023
8947932
Use last 16 steps in period detection, not first 16..
goodboy Jun 14, 2023
2a18358
Drop `wap_in_history` stuff from display loop
goodboy Jun 14, 2023
dd3e4b5
Emit backfill details in broadcasts
goodboy Jun 15, 2023
e1be098
Only hard re-render `Viz`s matching backfill deats
goodboy Jun 15, 2023
33ec277
Sync shm mod with dev version in `tractor`, drop buffer sizing vars, …
goodboy Jun 15, 2023
9eeea51
Define shm buffer sizing in `.data.history`
goodboy Jun 15, 2023
58c096b
Bleh go back to using pdbp for REPL in anal
goodboy Jun 19, 2023
d704d63
Add `store ldshm` subcmd
goodboy Jun 19, 2023
cc30371
Factor `brokerd` trade dialog init into acm
goodboy Jun 12, 2023
b15e736
Change `piker symbol-info` -> `mkt-info`
goodboy Jun 13, 2023
bb02775
Change `ledger` CLI to use new `open_brokerd_dialog()`
goodboy Jun 13, 2023
ebbfa7f
Passthrough kwargs to `open_cached_client()`
goodboy Jun 13, 2023
90810dc
Right partition the fqme to remove broker part in mkt-info cli
goodboy Jun 13, 2023
c0552fa
Just use brokermods dict directly in chart entrypoint now
goodboy Jun 13, 2023
921e187
Move `._cacheables.open_cached_client()` into `.brokers` pkg mod
goodboy Jun 13, 2023
0f8c685
.clearing._client: return early on cancel-dead-dialog attempts
goodboy Jun 14, 2023
6a1c49b
view_mode: handle duplicate overlay dispersions
goodboy Jun 14, 2023
6b2e85e
Add type-annots to sampler subscription method internals
goodboy Jun 14, 2023
2e878ca
Don't pass loglevel to trade dialog endpoint
goodboy Jun 14, 2023
f81ea64
Drop unused `Union`
goodboy Jun 14, 2023
e7437cb
Facepalm, break on first matching trades ep..
goodboy Jun 15, 2023
a4b8fb2
Woops, drop paper mode detection on client side..
goodboy Jun 15, 2023
81d5ca9
ib: drop `ibis` import and use fq object imports instead
goodboy Jun 16, 2023
f2c1988
Better empty account console msg styling
goodboy Jun 17, 2023
77dfeb4
Update brokerd msgs with modern type annots, add a "closed" status
goodboy Jun 17, 2023
bc58e42
Refine accounting related config loading routine doc strings
goodboy Jun 17, 2023
909f880
ib: prep for passing `Client` to data reset hacker
goodboy Jun 17, 2023
84613cd
clearing._messages: don't require `.symbol` in brokerd side error msgs
goodboy Jun 17, 2023
b28b38a
Fix double cancel bug!
goodboy Jun 17, 2023
a149e71
ib: pull vnc sockaddrs from brokers.toml config if defined
goodboy Jun 19, 2023
80461e1
Use `MktPair.price_tick: Decimal` in dark triggers
goodboy Jun 19, 2023
736bbbf
view_mode: drop rounding dispersions and "debug print"
goodboy Jun 19, 2023
020a395
Always use fully expanded FQME throughout `.clearing`
goodboy Jun 20, 2023
ad31631
Always round order pane $limit to 3 digits
goodboy Jun 20, 2023
6c10c2f
order_mode: add comment around `Order` being a dict bug
goodboy Jun 20, 2023
c57d4b2
ib: map some tick types particulary "volumeRate" to avoid auto-range …
goodboy Jun 20, 2023
d42aa60
Define the flattened "fundamental double auction" emitted tick type set
goodboy Jun 20, 2023
c4277eb
.ui._display: filter y-ranging to `_auction_ticks`
goodboy Jun 20, 2023
a44bc4a
binance: pre-#520 fixes for `open_cached_client()` import and struct-…
goodboy Jun 20, 2023
3535986
.brokers._daemon: add notes around needed brokerd respawn tech
goodboy Jun 20, 2023
27ec461
.nativedb: ignore an `expired/` subdir
goodboy Jul 10, 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
135 changes: 31 additions & 104 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ computational trading targeted at `hardcore Linux users <comp_trader>`_ .
we use as much bleeding edge tech as possible including (but not limited to):

- latest python for glue_
- trio_ for `structured concurrency`_
- tractor_ for distributed, multi-core, real-time streaming
- marketstore_ for historical and real-time tick data persistence and sharing
- techtonicdb_ for L2 book storage
- trio_ & tractor_ for our distributed, multi-core, real-time streaming
`structured concurrency`_ runtime B)
- Qt_ for pristine high performance UIs
- pyqtgraph_ for real-time charting
- ``numpy`` and ``numba`` for `fast numerics`_
- ``polars`` ``numpy`` and ``numba`` for `fast numerics`_
- `apache arrow and parquet`_ for time series history management
persistence and sharing
- (prototyped) techtonicdb_ for L2 book storage

.. |travis| image:: https://img.shields.io/travis/pikers/piker/master.svg
:target: https://travis-ci.org/pikers/piker
Expand All @@ -31,6 +32,7 @@ we use as much bleeding edge tech as possible including (but not limited to):
.. _Qt: https://www.qt.io/
.. _pyqtgraph: https://github.com/pyqtgraph/pyqtgraph
.. _glue: https://numpy.org/doc/stable/user/c-info.python-as-glue.html#using-python-as-glue
.. _apache arrow and parquet: https://arrow.apache.org/faq/
.. _fast numerics: https://zerowithdot.com/python-numpy-and-pandas-performance/
.. _comp_trader: https://jfaleiro.wordpress.com/2019/10/09/computational-trader/

Expand Down Expand Up @@ -58,23 +60,20 @@ building the best looking, most reliable, keyboard friendly trading
platform is the dream; join the cause.


install
*******
``piker`` is currently under heavy pre-alpha development and as such
should be cloned from this repo and hacked on directly.
sane install with `poetry`
**************************
TODO!

for a development install::

git clone git@github.com:pikers/piker.git
cd piker
virtualenv env
source ./env/bin/activate
pip install -r requirements.txt -e .
rigorous install on ``nixos`` using ``poetry2nix``
**************************************************
TODO!

install for nixos
*****************
for users of `NixOS` we offer a development shell envoirment that can be
loaded with::

hacky install on nixos
**********************
`NixOS` is our core devs' distro of choice for which we offer
a stringently defined development shell envoirment that can be loaded with::

nix-shell develop.nix

Expand All @@ -85,91 +84,19 @@ run::

once after loading the shell

install for tinas
*****************
for windows peeps you can start by installing all the prerequisite software:

- install git with all default settings - https://git-scm.com/download/win
- install anaconda all default settings - https://www.anaconda.com/products/individual
- install microsoft build tools (check the box for Desktop development for C++, you might be able to uncheck some optional downloads) - https://visualstudio.microsoft.com/visual-cpp-build-tools/
- install visual studio code default settings - https://code.visualstudio.com/download


then, `crack a conda shell`_ and run the following commands::

mkdir code # create code directory
cd code # change directory to code
git clone https://github.com/pikers/piker.git # downloads piker installation package from github
cd piker # change directory to piker

conda create -n pikonda # creates conda environment named pikonda
conda activate pikonda # activates pikonda

conda install -c conda-forge python-levenshtein # in case it is not already installed
conda install pip # may already be installed
pip # will show if pip is installed

pip install -e . -r requirements.txt # install piker in editable mode

test Piker to see if it is working::

piker -b binance chart btcusdt.binance # formatting for loading a chart
piker -b kraken -b binance chart xbtusdt.kraken
piker -b kraken -b binance -b ib chart qqq.nasdaq.ib
piker -b ib chart tsla.nasdaq.ib

potential error::

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Roaming\\piker\\brokers.toml'

solution:

- navigate to file directory above (may be different on your machine, location should be listed in the error code)
- copy and paste file from 'C:\\Users\\user\\code\\data/brokers.toml' or create a blank file using notepad at the location above

Visual Studio Code setup:

- now that piker is installed we can set up vscode as the default terminal for running piker and editing the code
- open Visual Studio Code
- file --> Add Folder to Workspace --> C:\Users\user\code\piker (adds piker directory where all piker files are located)
- file --> Save Workspace As --> save it wherever you want and call it whatever you want, this is going to be your default workspace for running and editing piker code
- ctrl + shift + p --> start typing Python: Select Interpetter --> when the option comes up select it --> Select at the workspace level --> select the one that shows ('pikonda')
- change the default terminal to cmd.exe instead of powershell (default)
- now when you create a new terminal VScode should automatically activate you conda env so that piker can be run as the first command after a new terminal is created

also, try out fancyzones as part of powertoyz for a decent tiling windows manager to manage all the cool new software you are going to be running.

.. _conda installed: https://
.. _C++ build toolz: https://
.. _crack a conda shell: https://
.. _vscode: https://

.. link to the tina guide
.. _setup a coolio tiled wm console: https://

provider support
****************
for live data feeds the in-progress set of supported brokers is:

- IB_ via ``ib_insync``, also see our `container docs`_
- binance_ and kraken_ for crypto over their public websocket API
- questrade_ (ish) which comes with effectively free L1

coming soon...

- webull_ via the reverse engineered public API
- yahoo via yliveticker_

if you want your broker supported and they have an API let us know.

.. _IB: https://interactivebrokers.github.io/tws-api/index.html
.. _container docs: https://github.com/pikers/piker/tree/master/dockering/ib
.. _questrade: https://www.questrade.com/api/documentation
.. _kraken: https://www.kraken.com/features/api#public-market-data
.. _binance: https://github.com/pikers/piker/pull/182
.. _webull: https://github.com/tedchou12/webull
.. _yliveticker: https://github.com/yahoofinancelive/yliveticker
.. _coinbase: https://docs.pro.coinbase.com/#websocket-feed

install wild-west style via `pip`
*********************************
``piker`` is currently under heavy pre-alpha development and as such
should be cloned from this repo and hacked on directly.

for a development install::

git clone git@github.com:pikers/piker.git
cd piker
virtualenv env
source ./env/bin/activate
pip install -r requirements.txt -e .


check out our charts
Expand Down
16 changes: 13 additions & 3 deletions develop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ stdenv.mkDerivation {
# System requirements.
readline

# Python requirements (enough to get a virtualenv going).
python310Full
# TODO: hacky non-poetry install stuff we need to get rid of!!
virtualenv
setuptools
pyqt5
pip

# obviously, and see below for hacked linking
pyqt5

# Python requirements (enough to get a virtualenv going).
python310Full

# numerics deps
python310Packages.python-Levenshtein
python310Packages.fastparquet
python310Packages.polars

];
src = null;
shellHook = ''
Expand Down
91 changes: 91 additions & 0 deletions docs/tina_readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
### NOTE this is likely out of date given it was written some
(years) time ago by a user that has since not really partaken in
contributing since.

install for tinas
*****************
for windows peeps you can start by installing all the prerequisite software:

- install git with all default settings - https://git-scm.com/download/win
- install anaconda all default settings - https://www.anaconda.com/products/individual
- install microsoft build tools (check the box for Desktop development for C++, you might be able to uncheck some optional downloads) - https://visualstudio.microsoft.com/visual-cpp-build-tools/
- install visual studio code default settings - https://code.visualstudio.com/download


then, `crack a conda shell`_ and run the following commands::

mkdir code # create code directory
cd code # change directory to code
git clone https://github.com/pikers/piker.git # downloads piker installation package from github
cd piker # change directory to piker

conda create -n pikonda # creates conda environment named pikonda
conda activate pikonda # activates pikonda

conda install -c conda-forge python-levenshtein # in case it is not already installed
conda install pip # may already be installed
pip # will show if pip is installed

pip install -e . -r requirements.txt # install piker in editable mode

test Piker to see if it is working::

piker -b binance chart btcusdt.binance # formatting for loading a chart
piker -b kraken -b binance chart xbtusdt.kraken
piker -b kraken -b binance -b ib chart qqq.nasdaq.ib
piker -b ib chart tsla.nasdaq.ib

potential error::

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\user\\AppData\\Roaming\\piker\\brokers.toml'

solution:

- navigate to file directory above (may be different on your machine, location should be listed in the error code)
- copy and paste file from 'C:\\Users\\user\\code\\data/brokers.toml' or create a blank file using notepad at the location above

Visual Studio Code setup:

- now that piker is installed we can set up vscode as the default terminal for running piker and editing the code
- open Visual Studio Code
- file --> Add Folder to Workspace --> C:\Users\user\code\piker (adds piker directory where all piker files are located)
- file --> Save Workspace As --> save it wherever you want and call it whatever you want, this is going to be your default workspace for running and editing piker code
- ctrl + shift + p --> start typing Python: Select Interpetter --> when the option comes up select it --> Select at the workspace level --> select the one that shows ('pikonda')
- change the default terminal to cmd.exe instead of powershell (default)
- now when you create a new terminal VScode should automatically activate you conda env so that piker can be run as the first command after a new terminal is created

also, try out fancyzones as part of powertoyz for a decent tiling windows manager to manage all the cool new software you are going to be running.

.. _conda installed: https://
.. _C++ build toolz: https://
.. _crack a conda shell: https://
.. _vscode: https://

.. link to the tina guide
.. _setup a coolio tiled wm console: https://

provider support
****************
for live data feeds the in-progress set of supported brokers is:

- IB_ via ``ib_insync``, also see our `container docs`_
- binance_ and kraken_ for crypto over their public websocket API
- questrade_ (ish) which comes with effectively free L1

coming soon...

- webull_ via the reverse engineered public API
- yahoo via yliveticker_

if you want your broker supported and they have an API let us know.

.. _IB: https://interactivebrokers.github.io/tws-api/index.html
.. _container docs: https://github.com/pikers/piker/tree/master/dockering/ib
.. _questrade: https://www.questrade.com/api/documentation
.. _kraken: https://www.kraken.com/features/api#public-market-data
.. _binance: https://github.com/pikers/piker/pull/182
.. _webull: https://github.com/tedchou12/webull
.. _yliveticker: https://github.com/yahoofinancelive/yliveticker
.. _coinbase: https://docs.pro.coinbase.com/#websocket-feed


25 changes: 0 additions & 25 deletions piker/_cacheables.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,15 @@
'''

from collections import OrderedDict
from contextlib import (
asynccontextmanager as acm,
)
from typing import (
Awaitable,
Callable,
ParamSpec,
TypeVar,
)

from tractor.trionics import maybe_open_context

from .brokers import get_brokermod
from .log import get_logger


log = get_logger(__name__)

T = TypeVar("T")
Expand Down Expand Up @@ -104,21 +97,3 @@ async def decorated(
return decorated

return decorator


# TODO: move this to `.brokers.utils`..
@acm
async def open_cached_client(
brokername: str,
) -> 'Client': # noqa
'''
Get a cached broker client from the current actor's local vars.

If one has not been setup do it and cache it.

'''
brokermod = get_brokermod(brokername)
async with maybe_open_context(
acm_func=brokermod.get_client,
) as (cache_hit, client):
yield client
2 changes: 1 addition & 1 deletion piker/accounting/_mktinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Asset(Struct, frozen=True):

# NOTE: additional info optionally packed in by the backend, but
# should not be explicitly required in our generic API.
info: dict = {} # make it frozen?
info: dict | None = None

# TODO?
# _to_dict_skip = {'info'}
Expand Down
Loading
Loading