Compare commits
24 Commits
793a454463
...
d3ae2b26f6
| Author | SHA1 | Date |
|---|---|---|
|
|
d3ae2b26f6 | |
|
|
d0328bd640 | |
|
|
3c92b0c255 | |
|
|
bd1fc32368 | |
|
|
d99c55b16f | |
|
|
d0789956d0 | |
|
|
305db791ee | |
|
|
ebc8c70779 | |
|
|
fe9ff1afe4 | |
|
|
e2f95c2bee | |
|
|
d92fcb982c | |
|
|
b61145ec5a | |
|
|
624cca091a | |
|
|
9045e18386 | |
|
|
23ea65e337 | |
|
|
ea2e374101 | |
|
|
f64fcc69ed | |
|
|
f3a20ed77f | |
|
|
95cdaf8114 | |
|
|
39dcaf528a | |
|
|
3f663e0e73 | |
|
|
de542c90fb | |
|
|
41559e6729 | |
|
|
93e22e27b9 |
20
README.rst
20
README.rst
|
|
@ -93,13 +93,13 @@ bc why install with `python` when you can faster with `rust` ::
|
||||||
# ^ astral's docs,
|
# ^ astral's docs,
|
||||||
# https://docs.astral.sh/uv/concepts/projects/sync/
|
# https://docs.astral.sh/uv/concepts/projects/sync/
|
||||||
|
|
||||||
include all GUIs (ex. for charting)::
|
include all GUIs ::
|
||||||
|
|
||||||
uv sync --extra uis
|
uv sync --extra uis
|
||||||
|
|
||||||
AND with all our hacking tools and WIP integrations::
|
AND with all our hacking tools::
|
||||||
|
|
||||||
uv sync --dev --all-extras
|
uv sync --dev --extra uis
|
||||||
|
|
||||||
|
|
||||||
Ensure you can run the root-daemon::
|
Ensure you can run the root-daemon::
|
||||||
|
|
@ -107,21 +107,13 @@ Ensure you can run the root-daemon::
|
||||||
uv run pikerd [-l info --pdb]
|
uv run pikerd [-l info --pdb]
|
||||||
|
|
||||||
|
|
||||||
install on nix(os)
|
hacky install on nixos
|
||||||
******************
|
**********************
|
||||||
``NixOS`` is our core devs' distro of choice for which we offer
|
``NixOS`` is our core devs' distro of choice for which we offer
|
||||||
a stringently defined development shell envoirment that can currently
|
a stringently defined development shell envoirment that can be loaded with::
|
||||||
be applied in one of 2 ways::
|
|
||||||
|
|
||||||
# ONLY if running on X11
|
|
||||||
nix-shell default.nix
|
nix-shell default.nix
|
||||||
|
|
||||||
Or if you prefer flakes style and a modern DE::
|
|
||||||
|
|
||||||
# ONLY if also running on Wayland
|
|
||||||
nix develop # for default bash
|
|
||||||
nix develop -c uv run xonsh # for @goodboy's preferred sh B)
|
|
||||||
|
|
||||||
|
|
||||||
start a chart
|
start a chart
|
||||||
*************
|
*************
|
||||||
|
|
|
||||||
37
default.nix
37
default.nix
|
|
@ -11,12 +11,11 @@ let
|
||||||
libxkbcommonStorePath = lib.getLib libxkbcommon;
|
libxkbcommonStorePath = lib.getLib libxkbcommon;
|
||||||
xcbutilcursorStorePath = lib.getLib xcb-util-cursor;
|
xcbutilcursorStorePath = lib.getLib xcb-util-cursor;
|
||||||
|
|
||||||
pypkgs = python313Packages;
|
qtpyStorePath = lib.getLib python312Packages.qtpy;
|
||||||
qtpyStorePath = lib.getLib pypkgs.qtpy;
|
pyqt6StorePath = lib.getLib python312Packages.pyqt6;
|
||||||
pyqt6StorePath = lib.getLib pypkgs.pyqt6;
|
pyqt6SipStorePath = lib.getLib python312Packages.pyqt6-sip;
|
||||||
pyqt6SipStorePath = lib.getLib pypkgs.pyqt6-sip;
|
rapidfuzzStorePath = lib.getLib python312Packages.rapidfuzz;
|
||||||
rapidfuzzStorePath = lib.getLib pypkgs.rapidfuzz;
|
qdarkstyleStorePath = lib.getLib python312Packages.qdarkstyle;
|
||||||
qdarkstyleStorePath = lib.getLib pypkgs.qdarkstyle;
|
|
||||||
|
|
||||||
xorgLibX11StorePath = lib.getLib xorg.libX11;
|
xorgLibX11StorePath = lib.getLib xorg.libX11;
|
||||||
xorgLibxcbStorePath = lib.getLib xorg.libxcb;
|
xorgLibxcbStorePath = lib.getLib xorg.libxcb;
|
||||||
|
|
@ -52,12 +51,12 @@ stdenv.mkDerivation {
|
||||||
xorg.xcbutilrenderutil
|
xorg.xcbutilrenderutil
|
||||||
|
|
||||||
# Python requirements.
|
# Python requirements.
|
||||||
python313
|
python312Full
|
||||||
uv
|
python312Packages.uv
|
||||||
pypkgs.qdarkstyle
|
python312Packages.qdarkstyle
|
||||||
pypkgs.rapidfuzz
|
python312Packages.rapidfuzz
|
||||||
pypkgs.pyqt6
|
python312Packages.pyqt6
|
||||||
pypkgs.qtpy
|
python312Packages.qtpy
|
||||||
];
|
];
|
||||||
src = null;
|
src = null;
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|
@ -114,11 +113,11 @@ stdenv.mkDerivation {
|
||||||
|
|
||||||
export LD_LIBRARY_PATH
|
export LD_LIBRARY_PATH
|
||||||
|
|
||||||
RPDFUZZ_PATH="${rapidfuzzStorePath}/lib/python3.13/site-packages"
|
RPDFUZZ_PATH="${rapidfuzzStorePath}/lib/python3.12/site-packages"
|
||||||
QDRKSTYLE_PATH="${qdarkstyleStorePath}/lib/python3.13/site-packages"
|
QDRKSTYLE_PATH="${qdarkstyleStorePath}/lib/python3.12/site-packages"
|
||||||
QTPY_PATH="${qtpyStorePath}/lib/python3.13/site-packages"
|
QTPY_PATH="${qtpyStorePath}/lib/python3.12/site-packages"
|
||||||
PYQT6_PATH="${pyqt6StorePath}/lib/python3.13/site-packages"
|
PYQT6_PATH="${pyqt6StorePath}/lib/python3.12/site-packages"
|
||||||
PYQT6_SIP_PATH="${pyqt6SipStorePath}/lib/python3.13/site-packages"
|
PYQT6_SIP_PATH="${pyqt6SipStorePath}/lib/python3.12/site-packages"
|
||||||
|
|
||||||
PATCH="$PATCH:$RPDFUZZ_PATH"
|
PATCH="$PATCH:$RPDFUZZ_PATH"
|
||||||
PATCH="$PATCH:$QDRKSTYLE_PATH"
|
PATCH="$PATCH:$QDRKSTYLE_PATH"
|
||||||
|
|
@ -128,8 +127,8 @@ stdenv.mkDerivation {
|
||||||
|
|
||||||
export PATCH
|
export PATCH
|
||||||
|
|
||||||
# install all dev and extras
|
# Install deps
|
||||||
uv sync --dev --all-extras
|
uv lock
|
||||||
|
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
127
flake.lock
127
flake.lock
|
|
@ -1,24 +1,135 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1765779637,
|
"lastModified": 1689068808,
|
||||||
"narHash": "sha256-KJ2wa/BLSrTqDjbfyNx70ov/HdgNBCBBSQP3BIzKnv4=",
|
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
|
||||||
"owner": "nixos",
|
"owner": "numtide",
|
||||||
"repo": "nixpkgs",
|
"repo": "flake-utils",
|
||||||
"rev": "1306659b587dc277866c7b69eb97e5f07864d8c4",
|
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "nixos",
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils_2": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1689068808,
|
||||||
|
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nix-github-actions": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": [
|
||||||
|
"poetry2nix",
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1688870561,
|
||||||
|
"narHash": "sha256-4UYkifnPEw1nAzqqPOTL2MvWtm3sNGw1UTYTalkTcGY=",
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nix-github-actions",
|
||||||
|
"rev": "165b1650b753316aa7f1787f3005a8d2da0f5301",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-community",
|
||||||
|
"repo": "nix-github-actions",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1692174805,
|
||||||
|
"narHash": "sha256-xmNPFDi/AUMIxwgOH/IVom55Dks34u1g7sFKKebxUm0=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "caac0eb6bdcad0b32cb2522e03e4002c8975c62e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
"ref": "nixos-unstable",
|
"ref": "nixos-unstable",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"poetry2nix": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils_2",
|
||||||
|
"nix-github-actions": "nix-github-actions",
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1692048894,
|
||||||
|
"narHash": "sha256-cDw03rso2V4CDc3Mll0cHN+ztzysAvdI8pJ7ybbz714=",
|
||||||
|
"ref": "refs/heads/pyqt6",
|
||||||
|
"rev": "b059ad4c3051f45d6c912e17747aae37a9ec1544",
|
||||||
|
"revCount": 2276,
|
||||||
|
"type": "git",
|
||||||
|
"url": "file:///home/lord_fomo/repos/poetry2nix"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "file:///home/lord_fomo/repos/poetry2nix"
|
||||||
|
}
|
||||||
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": "nixpkgs"
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"poetry2nix": "poetry2nix"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
251
flake.nix
251
flake.nix
|
|
@ -1,103 +1,180 @@
|
||||||
# An "impure" template thx to `pyproject.nix`,
|
# NOTE: to convert to a poetry2nix env like this here are the
|
||||||
# https://pyproject-nix.github.io/pyproject.nix/templates.html#impure
|
# steps:
|
||||||
# https://github.com/pyproject-nix/pyproject.nix/blob/master/templates/impure/flake.nix
|
# - install poetry in your system nix config
|
||||||
{
|
# - convert the repo to use poetry using `poetry init`:
|
||||||
description = "An impure `piker` overlay using `uv` with Nix(OS)";
|
# https://python-poetry.org/docs/basic-usage/#initialising-a-pre-existing-project
|
||||||
|
# - then manually ensuring all deps are converted over:
|
||||||
|
# - add this file to the repo and commit it
|
||||||
|
# -
|
||||||
|
|
||||||
inputs = {
|
# GROKin tips:
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
# - CLI eps are (ostensibly) added via an `entry_points.txt`:
|
||||||
|
# - https://packaging.python.org/en/latest/specifications/entry-points/#file-format
|
||||||
|
# - https://github.com/nix-community/poetry2nix/blob/master/editable.nix#L49
|
||||||
|
{
|
||||||
|
description = "piker: trading gear for hackers (pkged with poetry2nix)";
|
||||||
|
|
||||||
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
|
||||||
|
# see https://github.com/nix-community/poetry2nix/tree/master#api
|
||||||
|
inputs.poetry2nix = {
|
||||||
|
# url = "github:nix-community/poetry2nix";
|
||||||
|
# url = "github:K900/poetry2nix/qt5-explicit-deps";
|
||||||
|
url = "/home/lord_fomo/repos/poetry2nix";
|
||||||
|
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs =
|
outputs = {
|
||||||
{ nixpkgs, ... }:
|
self,
|
||||||
let
|
nixpkgs,
|
||||||
inherit (nixpkgs) lib;
|
flake-utils,
|
||||||
forAllSystems = lib.genAttrs lib.systems.flakeExposed;
|
poetry2nix,
|
||||||
in
|
}:
|
||||||
{
|
# TODO: build cross-OS and use the `${system}` var thingy..
|
||||||
devShells = forAllSystems (
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
system:
|
let
|
||||||
let
|
# use PWD as sources
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
projectDir = ./.;
|
||||||
|
pyproject = ./pyproject.toml;
|
||||||
|
poetrylock = ./poetry.lock;
|
||||||
|
|
||||||
# do store-path extractions
|
# TODO: port to 3.11 and support both versions?
|
||||||
qt6baseStorePath = lib.getLib pkgs.qt6.qtbase;
|
python = "python3.10";
|
||||||
# ?TODO? can remove below since manual linking not needed?
|
|
||||||
# qt6QtWaylandStorePath = lib.getLib pkgs.qt6.qtwayland;
|
|
||||||
|
|
||||||
# XXX NOTE XXX, for now we overlay specific pkgs via
|
# for more functions and examples.
|
||||||
# a major-version-pinned-`cpython`
|
# inherit
|
||||||
cpython = "python313";
|
# (poetry2nix.legacyPackages.${system})
|
||||||
pypkgs = pkgs."${cpython}Packages";
|
# mkPoetryApplication;
|
||||||
in
|
# pkgs = nixpkgs.legacyPackages.${system};
|
||||||
{
|
|
||||||
default = pkgs.mkShell {
|
|
||||||
|
|
||||||
packages = with pkgs; [
|
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||||
# XXX, ensure sh completions active!
|
lib = pkgs.lib;
|
||||||
bashInteractive
|
p2npkgs = poetry2nix.legacyPackages.x86_64-linux;
|
||||||
bash-completion
|
|
||||||
|
|
||||||
# dev utils
|
# define all pkg overrides per dep, see edgecases.md:
|
||||||
ruff
|
# https://github.com/nix-community/poetry2nix/blob/master/docs/edgecases.md
|
||||||
pypkgs.ruff
|
# TODO: add these into the json file:
|
||||||
|
# https://github.com/nix-community/poetry2nix/blob/master/overrides/build-systems.json
|
||||||
|
pypkgs-build-requirements = {
|
||||||
|
asyncvnc = [ "setuptools" ];
|
||||||
|
eventkit = [ "setuptools" ];
|
||||||
|
ib-insync = [ "setuptools" "flake8" ];
|
||||||
|
msgspec = [ "setuptools"];
|
||||||
|
pdbp = [ "setuptools" ];
|
||||||
|
pyqt6-sip = [ "setuptools" ];
|
||||||
|
tabcompleter = [ "setuptools" ];
|
||||||
|
tractor = [ "setuptools" ];
|
||||||
|
tricycle = [ "setuptools" ];
|
||||||
|
trio-typing = [ "setuptools" ];
|
||||||
|
trio-util = [ "setuptools" ];
|
||||||
|
xonsh = [ "setuptools" ];
|
||||||
|
};
|
||||||
|
|
||||||
qt6.qtwayland
|
# auto-generate override entries
|
||||||
qt6.qtbase
|
p2n-overrides = p2npkgs.defaultPoetryOverrides.extend (self: super:
|
||||||
|
builtins.mapAttrs (package: build-requirements:
|
||||||
|
(builtins.getAttr package super).overridePythonAttrs (old: {
|
||||||
|
buildInputs = (
|
||||||
|
old.buildInputs or [ ]
|
||||||
|
) ++ (
|
||||||
|
builtins.map (
|
||||||
|
pkg: if builtins.isString pkg then builtins.getAttr pkg super else pkg
|
||||||
|
) build-requirements
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) pypkgs-build-requirements
|
||||||
|
);
|
||||||
|
|
||||||
uv
|
# override some ahead-of-time compiled extensions
|
||||||
python313 # ?TODO^ how to set from `cpython` above?
|
# to be built with their wheels.
|
||||||
pypkgs.pyqt6
|
ahot_overrides = p2n-overrides.extend(
|
||||||
pypkgs.pyqt6-sip
|
final: prev: {
|
||||||
pypkgs.qtpy
|
|
||||||
pypkgs.qdarkstyle
|
|
||||||
pypkgs.rapidfuzz
|
|
||||||
];
|
|
||||||
|
|
||||||
shellHook = ''
|
# llvmlite = prev.llvmlite.override {
|
||||||
# unmask to debug **this** dev-shell-hook
|
# preferWheel = false;
|
||||||
# set -e
|
# };
|
||||||
|
|
||||||
# set qt-base/plugin path(s)
|
# TODO: get this workin with p2n and nixpkgs..
|
||||||
QTBASE_PATH="${qt6baseStorePath}/lib"
|
# pyqt6 = prev.pyqt6.override {
|
||||||
QT_PLUGIN_PATH="${qt6baseStorePath}/lib/qt-6/plugins"
|
# preferWheel = true;
|
||||||
QT_QPA_PLATFORM_PLUGIN_PATH="$QT_PLUGIN_PATH/platforms"
|
# };
|
||||||
|
|
||||||
# link in Qt cc lib paths from <nixpkgs>
|
# NOTE: this DOESN'T work atm but after a fix
|
||||||
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$QTBASE_PATH"
|
# to poetry2nix, it will and actually this line
|
||||||
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$QT_PLUGIN_PATH"
|
# won't be needed - thanks @k900:
|
||||||
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$QT_QPA_PLATFORM_PLUGIN_PATH"
|
# https://github.com/nix-community/poetry2nix/pull/1257
|
||||||
|
pyqt5 = prev.pyqt5.override {
|
||||||
|
# withWebkit = false;
|
||||||
|
preferWheel = true;
|
||||||
|
};
|
||||||
|
|
||||||
# link-in c++ stdlib for various AOT-ext-pkgs (numpy, etc.)
|
# see PR from @k900:
|
||||||
LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH"
|
# https://github.com/nix-community/poetry2nix/pull/1257
|
||||||
|
# pyqt5-qt5 = prev.pyqt5-qt5.override {
|
||||||
|
# withWebkit = false;
|
||||||
|
# preferWheel = true;
|
||||||
|
# };
|
||||||
|
|
||||||
export LD_LIBRARY_PATH
|
# TODO: patch in an override for polars to build
|
||||||
|
# from src! See the details likely needed from
|
||||||
# RUNTIME-SETTINGS
|
# the cryptography entry:
|
||||||
#
|
# https://github.com/nix-community/poetry2nix/blob/master/overrides/default.nix#L426-L435
|
||||||
# ------ Qt ------
|
polars = prev.polars.override {
|
||||||
# XXX, unmask to debug qt .so linking/loading deats
|
preferWheel = true;
|
||||||
# export QT_DEBUG_PLUGINS=1
|
};
|
||||||
#
|
}
|
||||||
# ALSO, for *modern linux* DEs,
|
|
||||||
# - maybe set wayland-mode (TODO, parametrtize this!)
|
|
||||||
# * a chosen wayland-mode shell-integration
|
|
||||||
export QT_QPA_PLATFORM="wayland"
|
|
||||||
export QT_WAYLAND_SHELL_INTEGRATION="xdg-shell"
|
|
||||||
|
|
||||||
# ------ uv ------
|
|
||||||
# - always use the ./py313/ venv-subdir
|
|
||||||
export UV_PROJECT_ENVIRONMENT="py313"
|
|
||||||
# sync project-env with all extras
|
|
||||||
uv sync --dev --all-extras --no-group lint
|
|
||||||
|
|
||||||
# ------ TIPS ------
|
|
||||||
# NOTE, to launch the py-venv installed `xonsh` (like @goodboy)
|
|
||||||
# run the `nix develop` cmd with,
|
|
||||||
# >> nix develop -c uv run xonsh
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
# WHY!? -> output-attrs that `nix develop` scans for:
|
||||||
|
# https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-develop.html#flake-output-attributes
|
||||||
|
in
|
||||||
|
rec {
|
||||||
|
packages = {
|
||||||
|
# piker = poetry2nix.legacyPackages.x86_64-linux.mkPoetryEditablePackage {
|
||||||
|
# editablePackageSources = { piker = ./piker; };
|
||||||
|
|
||||||
|
piker = p2npkgs.mkPoetryApplication {
|
||||||
|
projectDir = projectDir;
|
||||||
|
|
||||||
|
# SEE ABOVE for auto-genned input set, override
|
||||||
|
# buncha deps with extras.. like `setuptools` mostly.
|
||||||
|
# TODO: maybe propose a patch to p2n to show that you
|
||||||
|
# can even do this in the edgecases docs?
|
||||||
|
overrides = ahot_overrides;
|
||||||
|
|
||||||
|
# XXX: won't work on llvmlite..
|
||||||
|
# preferWheels = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# devShells.default = pkgs.mkShell {
|
||||||
|
# projectDir = projectDir;
|
||||||
|
# python = "python3.10";
|
||||||
|
# overrides = ahot_overrides;
|
||||||
|
# inputsFrom = [ self.packages.x86_64-linux.piker ];
|
||||||
|
# packages = packages;
|
||||||
|
# # packages = [ poetry2nix.packages.${system}.poetry ];
|
||||||
|
# };
|
||||||
|
|
||||||
|
# TODO: grok the difference here..
|
||||||
|
# - avoid re-cloning git repos on every develop entry..
|
||||||
|
# - ideally allow hacking on the src code of some deps
|
||||||
|
# (tractor, pyqtgraph, tomlkit, etc.) WITHOUT having to
|
||||||
|
# re-install them every time a change is made.
|
||||||
|
# - boot a usable xonsh inside the poetry virtualenv when
|
||||||
|
# defined via a custom entry point?
|
||||||
|
devShells.default = p2npkgs.mkPoetryEnv {
|
||||||
|
# env = p2npkgs.mkPoetryEnv {
|
||||||
|
projectDir = projectDir;
|
||||||
|
python = pkgs.python310;
|
||||||
|
overrides = ahot_overrides;
|
||||||
|
editablePackageSources = packages;
|
||||||
|
# piker = "./";
|
||||||
|
# tractor = "../tractor/";
|
||||||
|
# }; # wut?
|
||||||
|
};
|
||||||
|
}
|
||||||
|
); # end of .outputs scope
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ import tomli_w # for fast ledger writing
|
||||||
|
|
||||||
from piker.types import Struct
|
from piker.types import Struct
|
||||||
from piker import config
|
from piker import config
|
||||||
from piker.log import get_logger
|
from ..log import get_logger
|
||||||
from .calc import (
|
from .calc import (
|
||||||
iter_by_dt,
|
iter_by_dt,
|
||||||
)
|
)
|
||||||
|
|
@ -239,9 +239,7 @@ class TransactionLedger(UserDict):
|
||||||
|
|
||||||
symcache: SymbologyCache = self._symcache
|
symcache: SymbologyCache = self._symcache
|
||||||
towrite: dict[str, Any] = {}
|
towrite: dict[str, Any] = {}
|
||||||
for tid, txdict in self.tx_sort(
|
for tid, txdict in self.tx_sort(self.data.copy()):
|
||||||
self.data.copy()
|
|
||||||
):
|
|
||||||
# write blank-str expiry for non-expiring assets
|
# write blank-str expiry for non-expiring assets
|
||||||
if (
|
if (
|
||||||
'expiry' in txdict
|
'expiry' in txdict
|
||||||
|
|
@ -379,7 +377,7 @@ def open_trade_ledger(
|
||||||
account,
|
account,
|
||||||
dirpath=_fp,
|
dirpath=_fp,
|
||||||
)
|
)
|
||||||
cpy: dict = ledger_dict.copy()
|
cpy = ledger_dict.copy()
|
||||||
|
|
||||||
# XXX NOTE: if not provided presume we are being called from
|
# XXX NOTE: if not provided presume we are being called from
|
||||||
# sync code and need to maybe run `trio` to generate..
|
# sync code and need to maybe run `trio` to generate..
|
||||||
|
|
@ -408,13 +406,7 @@ def open_trade_ledger(
|
||||||
account=account,
|
account=account,
|
||||||
mod=mod,
|
mod=mod,
|
||||||
symcache=symcache,
|
symcache=symcache,
|
||||||
|
tx_sort=getattr(mod, 'tx_sort', tx_sort),
|
||||||
# NOTE: allow backends to provide custom ledger sorting
|
|
||||||
tx_sort=getattr(
|
|
||||||
mod,
|
|
||||||
'tx_sort',
|
|
||||||
tx_sort,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
yield ledger
|
yield ledger
|
||||||
|
|
|
||||||
|
|
@ -305,8 +305,8 @@ class MktPair(Struct, frozen=True):
|
||||||
# config right?
|
# config right?
|
||||||
# src_type: AssetTypeName
|
# src_type: AssetTypeName
|
||||||
|
|
||||||
# for derivs, info describing contract, egs. strike price, call
|
# for derivs, info describing contract, egs.
|
||||||
# or put, swap type, exercise model, etc.
|
# strike price, call or put, swap type, exercise model, etc.
|
||||||
contract_info: list[str] | None = None
|
contract_info: list[str] | None = None
|
||||||
|
|
||||||
# TODO: rename to sectype since all of these can
|
# TODO: rename to sectype since all of these can
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@ from types import ModuleType
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Iterator,
|
Iterator,
|
||||||
Generator,
|
Generator
|
||||||
TYPE_CHECKING,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
import pendulum
|
import pendulum
|
||||||
|
|
@ -60,10 +59,8 @@ from ..clearing._messages import (
|
||||||
BrokerdPosition,
|
BrokerdPosition,
|
||||||
)
|
)
|
||||||
from piker.types import Struct
|
from piker.types import Struct
|
||||||
from piker.log import get_logger
|
from piker.data._symcache import SymbologyCache
|
||||||
|
from ..log import get_logger
|
||||||
if TYPE_CHECKING:
|
|
||||||
from piker.data._symcache import SymbologyCache
|
|
||||||
|
|
||||||
log = get_logger(__name__)
|
log = get_logger(__name__)
|
||||||
|
|
||||||
|
|
@ -496,17 +493,6 @@ class Account(Struct):
|
||||||
|
|
||||||
_mktmap_table: dict[str, MktPair] | None = None,
|
_mktmap_table: dict[str, MktPair] | None = None,
|
||||||
|
|
||||||
only_require: list[str]|True = True,
|
|
||||||
# ^list of fqmes that are "required" to be processed from
|
|
||||||
# this ledger pass; we often don't care about others and
|
|
||||||
# definitely shouldn't always error in such cases.
|
|
||||||
# (eg. broker backend loaded that doesn't yet supsport the
|
|
||||||
# symcache but also, inside the paper engine we don't ad-hoc
|
|
||||||
# request `get_mkt_info()` for every symbol in the ledger,
|
|
||||||
# only the one for which we're simulating against).
|
|
||||||
# TODO, not sure if there's a better soln for this, ideally
|
|
||||||
# all backends get symcache support afap i guess..
|
|
||||||
|
|
||||||
) -> dict[str, Position]:
|
) -> dict[str, Position]:
|
||||||
'''
|
'''
|
||||||
Update the internal `.pps[str, Position]` table from input
|
Update the internal `.pps[str, Position]` table from input
|
||||||
|
|
@ -549,32 +535,11 @@ class Account(Struct):
|
||||||
if _mktmap_table is None:
|
if _mktmap_table is None:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
required: bool = (
|
|
||||||
only_require is True
|
|
||||||
or (
|
|
||||||
only_require is not True
|
|
||||||
and
|
|
||||||
fqme in only_require
|
|
||||||
)
|
|
||||||
)
|
|
||||||
# XXX: caller is allowed to provide a fallback
|
# XXX: caller is allowed to provide a fallback
|
||||||
# mktmap table for the case where a new position is
|
# mktmap table for the case where a new position is
|
||||||
# being added and the preloaded symcache didn't
|
# being added and the preloaded symcache didn't
|
||||||
# have this entry prior (eg. with frickin IB..)
|
# have this entry prior (eg. with frickin IB..)
|
||||||
if (
|
mkt = _mktmap_table[fqme]
|
||||||
not (mkt := _mktmap_table.get(fqme))
|
|
||||||
and
|
|
||||||
required
|
|
||||||
):
|
|
||||||
raise
|
|
||||||
|
|
||||||
elif not required:
|
|
||||||
continue
|
|
||||||
|
|
||||||
else:
|
|
||||||
# should be an entry retreived somewhere
|
|
||||||
assert mkt
|
|
||||||
|
|
||||||
|
|
||||||
if not (pos := pps.get(bs_mktid)):
|
if not (pos := pps.get(bs_mktid)):
|
||||||
|
|
||||||
|
|
@ -691,7 +656,7 @@ class Account(Struct):
|
||||||
def write_config(self) -> None:
|
def write_config(self) -> None:
|
||||||
'''
|
'''
|
||||||
Write the current account state to the user's account TOML file, normally
|
Write the current account state to the user's account TOML file, normally
|
||||||
something like `pps.toml`.
|
something like ``pps.toml``.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# TODO: show diff output?
|
# TODO: show diff output?
|
||||||
|
|
|
||||||
|
|
@ -251,16 +251,10 @@ def iter_by_dt(
|
||||||
for k in parsers:
|
for k in parsers:
|
||||||
if (
|
if (
|
||||||
isdict and k in tx
|
isdict and k in tx
|
||||||
or
|
or getattr(tx, k, None)
|
||||||
getattr(tx, k, None)
|
|
||||||
):
|
):
|
||||||
v = (
|
v = tx[k] if isdict else tx.dt
|
||||||
tx[k] if isdict
|
assert v is not None, f'No valid value for `{k}`!?'
|
||||||
else tx.dt
|
|
||||||
)
|
|
||||||
assert v is not None, (
|
|
||||||
f'No valid value for `{k}`!?'
|
|
||||||
)
|
|
||||||
|
|
||||||
# only call parser on the value if not None from
|
# only call parser on the value if not None from
|
||||||
# the `parsers` table above (when NOT using
|
# the `parsers` table above (when NOT using
|
||||||
|
|
@ -275,21 +269,8 @@ def iter_by_dt(
|
||||||
return v
|
return v
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# TODO: move to top?
|
# XXX: should never get here..
|
||||||
from piker.log import get_logger
|
breakpoint()
|
||||||
log = get_logger(__name__)
|
|
||||||
|
|
||||||
# XXX: we should really never get here..
|
|
||||||
# only if a ledger record has no expected sort(able)
|
|
||||||
# field will we likely hit this.. like with ze IB.
|
|
||||||
# if no sortable field just deliver epoch?
|
|
||||||
log.warning(
|
|
||||||
'No (time) sortable field for TXN:\n'
|
|
||||||
f'{tx}\n'
|
|
||||||
)
|
|
||||||
return from_timestamp(0)
|
|
||||||
# breakpoint()
|
|
||||||
|
|
||||||
|
|
||||||
entry: tuple[str, dict] | Transaction
|
entry: tuple[str, dict] | Transaction
|
||||||
for entry in sorted(
|
for entry in sorted(
|
||||||
|
|
|
||||||
|
|
@ -300,8 +300,7 @@ def disect(
|
||||||
assert not df.is_empty()
|
assert not df.is_empty()
|
||||||
|
|
||||||
# muck around in pdbp REPL
|
# muck around in pdbp REPL
|
||||||
# tractor.devx.mk_pdb().set_trace()
|
breakpoint()
|
||||||
# breakpoint()
|
|
||||||
|
|
||||||
# TODO: we REALLY need a better console REPL for this
|
# TODO: we REALLY need a better console REPL for this
|
||||||
# kinda thing..
|
# kinda thing..
|
||||||
|
|
|
||||||
|
|
@ -98,14 +98,13 @@ async def open_cached_client(
|
||||||
If one has not been setup do it and cache it.
|
If one has not been setup do it and cache it.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
brokermod: ModuleType = get_brokermod(brokername)
|
brokermod = get_brokermod(brokername)
|
||||||
|
|
||||||
# TODO: make abstract or `typing.Protocol`
|
|
||||||
# client: Client
|
|
||||||
async with maybe_open_context(
|
async with maybe_open_context(
|
||||||
acm_func=brokermod.get_client,
|
acm_func=brokermod.get_client,
|
||||||
kwargs=kwargs,
|
kwargs=kwargs,
|
||||||
|
|
||||||
) as (cache_hit, client):
|
) as (cache_hit, client):
|
||||||
|
|
||||||
if cache_hit:
|
if cache_hit:
|
||||||
log.runtime(f'Reusing existing {client}')
|
log.runtime(f'Reusing existing {client}')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,11 +99,6 @@ class Pair(Struct, frozen=True, kw_only=True):
|
||||||
|
|
||||||
permissionSets: list[list[str]]
|
permissionSets: list[list[str]]
|
||||||
|
|
||||||
# https://developers.binance.com/docs/binance-spot-api-docs#2025-08-26
|
|
||||||
# will become non-optional 2025-08-28?
|
|
||||||
# https://developers.binance.com/docs/binance-spot-api-docs#future-changes
|
|
||||||
pegInstructionsAllowed: bool|None = None
|
|
||||||
|
|
||||||
filters: dict[
|
filters: dict[
|
||||||
str,
|
str,
|
||||||
str | int | float,
|
str | int | float,
|
||||||
|
|
|
||||||
|
|
@ -471,15 +471,11 @@ def search(
|
||||||
|
|
||||||
'''
|
'''
|
||||||
# global opts
|
# global opts
|
||||||
brokermods: list[ModuleType] = list(config['brokermods'].values())
|
brokermods = list(config['brokermods'].values())
|
||||||
|
|
||||||
# TODO: this is coming from the `search --pdb` NOT from
|
|
||||||
# the `piker --pdb` XD ..
|
|
||||||
# -[ ] pull from the parent click ctx's values..dumdum
|
|
||||||
# assert pdb
|
|
||||||
|
|
||||||
# define tractor entrypoint
|
# define tractor entrypoint
|
||||||
async def main(func):
|
async def main(func):
|
||||||
|
|
||||||
async with maybe_open_pikerd(
|
async with maybe_open_pikerd(
|
||||||
loglevel=config['loglevel'],
|
loglevel=config['loglevel'],
|
||||||
debug_mode=pdb,
|
debug_mode=pdb,
|
||||||
|
|
|
||||||
|
|
@ -22,9 +22,7 @@ routines should be primitive data types where possible.
|
||||||
"""
|
"""
|
||||||
import inspect
|
import inspect
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import (
|
from typing import List, Dict, Any, Optional
|
||||||
Any,
|
|
||||||
)
|
|
||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
|
|
@ -36,10 +34,8 @@ from ..accounting import MktPair
|
||||||
|
|
||||||
|
|
||||||
async def api(brokername: str, methname: str, **kwargs) -> dict:
|
async def api(brokername: str, methname: str, **kwargs) -> dict:
|
||||||
'''
|
"""Make (proxy through) a broker API call by name and return its result.
|
||||||
Make (proxy through) a broker API call by name and return its result.
|
"""
|
||||||
|
|
||||||
'''
|
|
||||||
brokermod = get_brokermod(brokername)
|
brokermod = get_brokermod(brokername)
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as client:
|
||||||
meth = getattr(client, methname, None)
|
meth = getattr(client, methname, None)
|
||||||
|
|
@ -66,14 +62,10 @@ async def api(brokername: str, methname: str, **kwargs) -> dict:
|
||||||
|
|
||||||
async def stocks_quote(
|
async def stocks_quote(
|
||||||
brokermod: ModuleType,
|
brokermod: ModuleType,
|
||||||
tickers: list[str]
|
tickers: List[str]
|
||||||
|
) -> Dict[str, Dict[str, Any]]:
|
||||||
) -> dict[str, dict[str, Any]]:
|
"""Return quotes dict for ``tickers``.
|
||||||
'''
|
"""
|
||||||
Return a `dict` of snapshot quotes for the provided input
|
|
||||||
`tickers`: a `list` of fqmes.
|
|
||||||
|
|
||||||
'''
|
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as client:
|
||||||
return await client.quote(tickers)
|
return await client.quote(tickers)
|
||||||
|
|
||||||
|
|
@ -82,15 +74,13 @@ async def stocks_quote(
|
||||||
async def option_chain(
|
async def option_chain(
|
||||||
brokermod: ModuleType,
|
brokermod: ModuleType,
|
||||||
symbol: str,
|
symbol: str,
|
||||||
date: str|None = None,
|
date: Optional[str] = None,
|
||||||
) -> dict[str, dict[str, dict[str, Any]]]:
|
) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||||
'''
|
"""Return option chain for ``symbol`` for ``date``.
|
||||||
Return option chain for ``symbol`` for ``date``.
|
|
||||||
|
|
||||||
By default all expiries are returned. If ``date`` is provided
|
By default all expiries are returned. If ``date`` is provided
|
||||||
then contract quotes for that single expiry are returned.
|
then contract quotes for that single expiry are returned.
|
||||||
|
"""
|
||||||
'''
|
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as client:
|
||||||
if date:
|
if date:
|
||||||
id = int((await client.tickers2ids([symbol]))[symbol])
|
id = int((await client.tickers2ids([symbol]))[symbol])
|
||||||
|
|
@ -108,7 +98,7 @@ async def option_chain(
|
||||||
# async def contracts(
|
# async def contracts(
|
||||||
# brokermod: ModuleType,
|
# brokermod: ModuleType,
|
||||||
# symbol: str,
|
# symbol: str,
|
||||||
# ) -> dict[str, dict[str, dict[str, Any]]]:
|
# ) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||||
# """Return option contracts (all expiries) for ``symbol``.
|
# """Return option contracts (all expiries) for ``symbol``.
|
||||||
# """
|
# """
|
||||||
# async with brokermod.get_client() as client:
|
# async with brokermod.get_client() as client:
|
||||||
|
|
@ -120,24 +110,15 @@ async def bars(
|
||||||
brokermod: ModuleType,
|
brokermod: ModuleType,
|
||||||
symbol: str,
|
symbol: str,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> dict[str, dict[str, dict[str, Any]]]:
|
) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||||
'''
|
"""Return option contracts (all expiries) for ``symbol``.
|
||||||
Return option contracts (all expiries) for ``symbol``.
|
"""
|
||||||
|
|
||||||
'''
|
|
||||||
async with brokermod.get_client() as client:
|
async with brokermod.get_client() as client:
|
||||||
return await client.bars(symbol, **kwargs)
|
return await client.bars(symbol, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
async def search_w_brokerd(
|
async def search_w_brokerd(name: str, pattern: str) -> dict:
|
||||||
name: str,
|
|
||||||
pattern: str,
|
|
||||||
) -> dict:
|
|
||||||
|
|
||||||
# TODO: WHY NOT WORK!?!
|
|
||||||
# when we `step` through the next block?
|
|
||||||
# import tractor
|
|
||||||
# await tractor.pause()
|
|
||||||
async with open_cached_client(name) as client:
|
async with open_cached_client(name) as client:
|
||||||
|
|
||||||
# TODO: support multiple asset type concurrent searches.
|
# TODO: support multiple asset type concurrent searches.
|
||||||
|
|
@ -149,12 +130,12 @@ async def symbol_search(
|
||||||
pattern: str,
|
pattern: str,
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
|
||||||
) -> dict[str, dict[str, dict[str, Any]]]:
|
) -> Dict[str, Dict[str, Dict[str, Any]]]:
|
||||||
'''
|
'''
|
||||||
Return symbol info from broker.
|
Return symbol info from broker.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
results: list[str] = []
|
results = []
|
||||||
|
|
||||||
async def search_backend(
|
async def search_backend(
|
||||||
brokermod: ModuleType
|
brokermod: ModuleType
|
||||||
|
|
@ -162,13 +143,6 @@ async def symbol_search(
|
||||||
|
|
||||||
brokername: str = mod.name
|
brokername: str = mod.name
|
||||||
|
|
||||||
# TODO: figure this the FUCK OUT
|
|
||||||
# -> ok so obvi in the root actor any async task that's
|
|
||||||
# spawned outside the main tractor-root-actor task needs to
|
|
||||||
# call this..
|
|
||||||
# await tractor.devx._debug.maybe_init_greenback()
|
|
||||||
# tractor.pause_from_sync()
|
|
||||||
|
|
||||||
async with maybe_spawn_brokerd(
|
async with maybe_spawn_brokerd(
|
||||||
mod.name,
|
mod.name,
|
||||||
infect_asyncio=getattr(
|
infect_asyncio=getattr(
|
||||||
|
|
@ -188,6 +162,7 @@ async def symbol_search(
|
||||||
))
|
))
|
||||||
|
|
||||||
async with trio.open_nursery() as n:
|
async with trio.open_nursery() as n:
|
||||||
|
|
||||||
for mod in brokermods:
|
for mod in brokermods:
|
||||||
n.start_soon(search_backend, mod.name)
|
n.start_soon(search_backend, mod.name)
|
||||||
|
|
||||||
|
|
@ -197,13 +172,11 @@ async def symbol_search(
|
||||||
async def mkt_info(
|
async def mkt_info(
|
||||||
brokermod: ModuleType,
|
brokermod: ModuleType,
|
||||||
fqme: str,
|
fqme: str,
|
||||||
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
|
|
||||||
) -> MktPair:
|
) -> MktPair:
|
||||||
'''
|
'''
|
||||||
Return the `piker.accounting.MktPair` info struct from a given
|
Return MktPair info from broker including src and dst assets.
|
||||||
backend broker tradable src/dst asset pair.
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
async with open_cached_client(brokermod.name) as client:
|
async with open_cached_client(brokermod.name) as client:
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ from piker.brokers._util import get_logger
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .api import Client
|
from .api import Client
|
||||||
from ib_insync import IB
|
from ib_insync import IB
|
||||||
import i3ipc
|
|
||||||
|
|
||||||
log = get_logger('piker.brokers.ib')
|
log = get_logger('piker.brokers.ib')
|
||||||
|
|
||||||
|
|
@ -49,37 +48,6 @@ _reset_tech: Literal[
|
||||||
] = 'vnc'
|
] = 'vnc'
|
||||||
|
|
||||||
|
|
||||||
no_setup_msg:str = (
|
|
||||||
'No data reset hack test setup for {vnc_sockaddr}!\n'
|
|
||||||
'See config setup tips @\n'
|
|
||||||
'https://github.com/pikers/piker/tree/master/piker/brokers/ib'
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def try_xdo_manual(
|
|
||||||
vnc_sockaddr: str,
|
|
||||||
):
|
|
||||||
'''
|
|
||||||
Do the "manual" `xdo`-based screen switch + click
|
|
||||||
combo since apparently the `asyncvnc` client ain't workin..
|
|
||||||
|
|
||||||
Note this is only meant as a backup method for Xorg users,
|
|
||||||
ideally you can use a real vnc client and the `vnc_click_hack()`
|
|
||||||
impl!
|
|
||||||
|
|
||||||
'''
|
|
||||||
global _reset_tech
|
|
||||||
try:
|
|
||||||
i3ipc_xdotool_manual_click_hack()
|
|
||||||
_reset_tech = 'i3ipc_xdotool'
|
|
||||||
return True
|
|
||||||
except OSError:
|
|
||||||
log.exception(
|
|
||||||
no_setup_msg.format(vnc_sockaddr)
|
|
||||||
)
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
async def data_reset_hack(
|
async def data_reset_hack(
|
||||||
# vnc_host: str,
|
# vnc_host: str,
|
||||||
client: Client,
|
client: Client,
|
||||||
|
|
@ -122,9 +90,15 @@ async def data_reset_hack(
|
||||||
vnc_port: int
|
vnc_port: int
|
||||||
vnc_sockaddr: tuple[str] | None = client.conf.get('vnc_addrs')
|
vnc_sockaddr: tuple[str] | None = client.conf.get('vnc_addrs')
|
||||||
|
|
||||||
|
no_setup_msg:str = (
|
||||||
|
f'No data reset hack test setup for {vnc_sockaddr}!\n'
|
||||||
|
'See config setup tips @\n'
|
||||||
|
'https://github.com/pikers/piker/tree/master/piker/brokers/ib'
|
||||||
|
)
|
||||||
|
|
||||||
if not vnc_sockaddr:
|
if not vnc_sockaddr:
|
||||||
log.warning(
|
log.warning(
|
||||||
no_setup_msg.format(vnc_sockaddr)
|
no_setup_msg
|
||||||
+
|
+
|
||||||
'REQUIRES A `vnc_addrs: array` ENTRY'
|
'REQUIRES A `vnc_addrs: array` ENTRY'
|
||||||
)
|
)
|
||||||
|
|
@ -145,38 +119,27 @@ async def data_reset_hack(
|
||||||
port=vnc_port,
|
port=vnc_port,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
except (
|
except OSError:
|
||||||
OSError, # no VNC server avail..
|
if vnc_host != 'localhost':
|
||||||
PermissionError, # asyncvnc pw fail..
|
log.warning(no_setup_msg)
|
||||||
):
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import i3ipc # noqa (since a deps dynamic check)
|
import i3ipc # noqa (since a deps dynamic check)
|
||||||
except ModuleNotFoundError:
|
except ModuleNotFoundError:
|
||||||
log.warning(
|
log.warning(no_setup_msg)
|
||||||
no_setup_msg.format(vnc_sockaddr)
|
|
||||||
)
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if vnc_host not in {
|
try:
|
||||||
'localhost',
|
i3ipc_xdotool_manual_click_hack()
|
||||||
'127.0.0.1',
|
_reset_tech = 'i3ipc_xdotool'
|
||||||
}:
|
return True
|
||||||
focussed, matches = i3ipc_fin_wins_titled()
|
except OSError:
|
||||||
if not matches:
|
log.exception(no_setup_msg)
|
||||||
log.warning(
|
return False
|
||||||
no_setup_msg.format(vnc_sockaddr)
|
|
||||||
)
|
|
||||||
return False
|
|
||||||
else:
|
|
||||||
try_xdo_manual(vnc_sockaddr)
|
|
||||||
|
|
||||||
# localhost but no vnc-client or it borked..
|
|
||||||
else:
|
|
||||||
try_xdo_manual(vnc_sockaddr)
|
|
||||||
|
|
||||||
case 'i3ipc_xdotool':
|
case 'i3ipc_xdotool':
|
||||||
try_xdo_manual(vnc_sockaddr)
|
i3ipc_xdotool_manual_click_hack()
|
||||||
# i3ipc_xdotool_manual_click_hack()
|
|
||||||
|
|
||||||
case _ as tech:
|
case _ as tech:
|
||||||
raise RuntimeError(f'{tech} is not supported for reset tech!?')
|
raise RuntimeError(f'{tech} is not supported for reset tech!?')
|
||||||
|
|
@ -215,9 +178,9 @@ async def vnc_click_hack(
|
||||||
host,
|
host,
|
||||||
port=port,
|
port=port,
|
||||||
|
|
||||||
# TODO: doesn't work?
|
# TODO: doesn't work see:
|
||||||
# see, https://github.com/barneygale/asyncvnc/issues/7
|
# https://github.com/barneygale/asyncvnc/issues/7
|
||||||
password='doggy',
|
# password='ibcansmbz',
|
||||||
|
|
||||||
) as client:
|
) as client:
|
||||||
|
|
||||||
|
|
@ -231,103 +194,70 @@ async def vnc_click_hack(
|
||||||
client.keyboard.press('Ctrl', 'Alt', key) # keys are stacked
|
client.keyboard.press('Ctrl', 'Alt', key) # keys are stacked
|
||||||
|
|
||||||
|
|
||||||
def i3ipc_fin_wins_titled(
|
|
||||||
titles: list[str] = [
|
|
||||||
'Interactive Brokers', # tws running in i3
|
|
||||||
'IB Gateway', # gw running in i3
|
|
||||||
# 'IB', # gw running in i3 (newer version?)
|
|
||||||
|
|
||||||
# !TODO, remote vnc instance
|
|
||||||
# -[ ] something in title (or other Con-props) that indicates
|
|
||||||
# this is explicitly for ibrk sw?
|
|
||||||
# |_[ ] !can use modden spawn eventually!
|
|
||||||
'TigerVNC',
|
|
||||||
# 'vncviewer', # the terminal..
|
|
||||||
],
|
|
||||||
) -> tuple[
|
|
||||||
i3ipc.Con, # orig focussed win
|
|
||||||
list[tuple[str, i3ipc.Con]], # matching wins by title
|
|
||||||
]:
|
|
||||||
'''
|
|
||||||
Attempt to find a local-DE window titled with an entry in
|
|
||||||
`titles`.
|
|
||||||
|
|
||||||
If found deliver the current focussed window and all matching
|
|
||||||
`i3ipc.Con`s in a list.
|
|
||||||
|
|
||||||
'''
|
|
||||||
import i3ipc
|
|
||||||
ipc = i3ipc.Connection()
|
|
||||||
|
|
||||||
# TODO: might be worth offering some kinda api for grabbing
|
|
||||||
# the window id from the pid?
|
|
||||||
# https://stackoverflow.com/a/2250879
|
|
||||||
tree = ipc.get_tree()
|
|
||||||
focussed: i3ipc.Con = tree.find_focused()
|
|
||||||
|
|
||||||
matches: list[i3ipc.Con] = []
|
|
||||||
for name in titles:
|
|
||||||
results = tree.find_titled(name)
|
|
||||||
print(f'results for {name}: {results}')
|
|
||||||
if results:
|
|
||||||
con = results[0]
|
|
||||||
matches.append((
|
|
||||||
name,
|
|
||||||
con,
|
|
||||||
))
|
|
||||||
|
|
||||||
return (
|
|
||||||
focussed,
|
|
||||||
matches,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def i3ipc_xdotool_manual_click_hack() -> None:
|
def i3ipc_xdotool_manual_click_hack() -> None:
|
||||||
'''
|
'''
|
||||||
Do the data reset hack but expecting a local X-window using `xdotool`.
|
Do the data reset hack but expecting a local X-window using `xdotool`.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
focussed, matches = i3ipc_fin_wins_titled()
|
import i3ipc
|
||||||
orig_win_id = focussed.window
|
i3 = i3ipc.Connection()
|
||||||
|
|
||||||
|
# TODO: might be worth offering some kinda api for grabbing
|
||||||
|
# the window id from the pid?
|
||||||
|
# https://stackoverflow.com/a/2250879
|
||||||
|
t = i3.get_tree()
|
||||||
|
|
||||||
|
orig_win_id = t.find_focused().window
|
||||||
|
|
||||||
|
# for tws
|
||||||
|
win_names: list[str] = [
|
||||||
|
'Interactive Brokers', # tws running in i3
|
||||||
|
'IB Gateway', # gw running in i3
|
||||||
|
# 'IB', # gw running in i3 (newer version?)
|
||||||
|
]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for name, con in matches:
|
for name in win_names:
|
||||||
print(f'Resetting data feed for {name}')
|
results = t.find_titled(name)
|
||||||
win_id = str(con.window)
|
print(f'results for {name}: {results}')
|
||||||
w, h = con.rect.width, con.rect.height
|
if results:
|
||||||
|
con = results[0]
|
||||||
|
print(f'Resetting data feed for {name}')
|
||||||
|
win_id = str(con.window)
|
||||||
|
w, h = con.rect.width, con.rect.height
|
||||||
|
|
||||||
# TODO: seems to be a few libs for python but not sure
|
# TODO: seems to be a few libs for python but not sure
|
||||||
# if they support all the sub commands we need, order of
|
# if they support all the sub commands we need, order of
|
||||||
# most recent commit history:
|
# most recent commit history:
|
||||||
# https://github.com/rr-/pyxdotool
|
# https://github.com/rr-/pyxdotool
|
||||||
# https://github.com/ShaneHutter/pyxdotool
|
# https://github.com/ShaneHutter/pyxdotool
|
||||||
# https://github.com/cphyc/pyxdotool
|
# https://github.com/cphyc/pyxdotool
|
||||||
|
|
||||||
# TODO: only run the reconnect (2nd) kc on a detected
|
# TODO: only run the reconnect (2nd) kc on a detected
|
||||||
# disconnect?
|
# disconnect?
|
||||||
for key_combo, timeout in [
|
for key_combo, timeout in [
|
||||||
# only required if we need a connection reset.
|
# only required if we need a connection reset.
|
||||||
# ('ctrl+alt+r', 12),
|
# ('ctrl+alt+r', 12),
|
||||||
# data feed reset.
|
# data feed reset.
|
||||||
('ctrl+alt+f', 6)
|
('ctrl+alt+f', 6)
|
||||||
]:
|
]:
|
||||||
subprocess.call([
|
subprocess.call([
|
||||||
'xdotool',
|
'xdotool',
|
||||||
'windowactivate', '--sync', win_id,
|
'windowactivate', '--sync', win_id,
|
||||||
|
|
||||||
# move mouse to bottom left of window (where
|
# move mouse to bottom left of window (where
|
||||||
# there should be nothing to click).
|
# there should be nothing to click).
|
||||||
'mousemove_relative', '--sync', str(w-4), str(h-4),
|
'mousemove_relative', '--sync', str(w-4), str(h-4),
|
||||||
|
|
||||||
# NOTE: we may need to stick a `--retry 3` in here..
|
# NOTE: we may need to stick a `--retry 3` in here..
|
||||||
'click', '--window', win_id,
|
'click', '--window', win_id,
|
||||||
'--repeat', '3', '1',
|
'--repeat', '3', '1',
|
||||||
|
|
||||||
# hackzorzes
|
# hackzorzes
|
||||||
'key', key_combo,
|
'key', key_combo,
|
||||||
],
|
],
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
# re-activate and focus original window
|
# re-activate and focus original window
|
||||||
subprocess.call([
|
subprocess.call([
|
||||||
|
|
|
||||||
|
|
@ -1241,47 +1241,32 @@ async def deliver_trade_events(
|
||||||
# never relay errors for non-broker related issues
|
# never relay errors for non-broker related issues
|
||||||
# https://interactivebrokers.github.io/tws-api/message_codes.html
|
# https://interactivebrokers.github.io/tws-api/message_codes.html
|
||||||
code: int = err['error_code']
|
code: int = err['error_code']
|
||||||
reason: str = err['reason']
|
if code in {
|
||||||
reqid: str = str(err['reqid'])
|
200, # uhh
|
||||||
|
|
||||||
# "Warning:" msg codes,
|
|
||||||
# https://interactivebrokers.github.io/tws-api/message_codes.html#warning_codes
|
|
||||||
# - 2109: 'Outside Regular Trading Hours'
|
|
||||||
if 'Warning:' in reason:
|
|
||||||
log.warning(
|
|
||||||
f'Order-API-warning: {code!r}\n'
|
|
||||||
f'reqid: {reqid!r}\n'
|
|
||||||
f'\n'
|
|
||||||
f'{pformat(err)}\n'
|
|
||||||
# ^TODO? should we just print the `reason`
|
|
||||||
# not the full `err`-dict?
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
|
|
||||||
# XXX known special (ignore) cases
|
|
||||||
elif code in {
|
|
||||||
200, # uhh.. ni idea
|
|
||||||
|
|
||||||
# hist pacing / connectivity
|
# hist pacing / connectivity
|
||||||
162,
|
162,
|
||||||
165,
|
165,
|
||||||
|
|
||||||
|
# WARNING codes:
|
||||||
|
# https://interactivebrokers.github.io/tws-api/message_codes.html#warning_codes
|
||||||
|
# Attribute 'Outside Regular Trading Hours' is
|
||||||
|
# " 'ignored based on the order type and
|
||||||
|
# destination. PlaceOrder is now ' 'being
|
||||||
|
# processed.',
|
||||||
|
2109,
|
||||||
|
|
||||||
# XXX: lol this isn't even documented..
|
# XXX: lol this isn't even documented..
|
||||||
# 'No market data during competing live session'
|
# 'No market data during competing live session'
|
||||||
1669,
|
1669,
|
||||||
}:
|
}:
|
||||||
log.error(
|
|
||||||
f'Order-API-error which is non-cancel-causing ?!\n'
|
|
||||||
f'\n'
|
|
||||||
f'{pformat(err)}\n'
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
reqid: str = str(err['reqid'])
|
||||||
|
reason: str = err['reason']
|
||||||
|
|
||||||
if err['reqid'] == -1:
|
if err['reqid'] == -1:
|
||||||
log.error(
|
log.error(f'TWS external order error:\n{pformat(err)}')
|
||||||
f'TWS external order error ??\n'
|
|
||||||
f'{pformat(err)}\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
flow: dict = dict(
|
flow: dict = dict(
|
||||||
flows.get(reqid)
|
flows.get(reqid)
|
||||||
|
|
|
||||||
|
|
@ -587,7 +587,7 @@ async def get_bars(
|
||||||
data_cs.cancel()
|
data_cs.cancel()
|
||||||
|
|
||||||
# spawn new data reset task
|
# spawn new data reset task
|
||||||
data_cs, reset_done = await tn.start(
|
data_cs, reset_done = await nurse.start(
|
||||||
partial(
|
partial(
|
||||||
wait_on_data_reset,
|
wait_on_data_reset,
|
||||||
proxy,
|
proxy,
|
||||||
|
|
@ -607,11 +607,11 @@ async def get_bars(
|
||||||
# such that simultaneous symbol queries don't try data resettingn
|
# such that simultaneous symbol queries don't try data resettingn
|
||||||
# too fast..
|
# too fast..
|
||||||
unset_resetter: bool = False
|
unset_resetter: bool = False
|
||||||
async with trio.open_nursery() as tn:
|
async with trio.open_nursery() as nurse:
|
||||||
|
|
||||||
# start history request that we allow
|
# start history request that we allow
|
||||||
# to run indefinitely until a result is acquired
|
# to run indefinitely until a result is acquired
|
||||||
tn.start_soon(query)
|
nurse.start_soon(query)
|
||||||
|
|
||||||
# start history reset loop which waits up to the timeout
|
# start history reset loop which waits up to the timeout
|
||||||
# for a result before triggering a data feed reset.
|
# for a result before triggering a data feed reset.
|
||||||
|
|
@ -631,7 +631,7 @@ async def get_bars(
|
||||||
unset_resetter: bool = True
|
unset_resetter: bool = True
|
||||||
|
|
||||||
# spawn new data reset task
|
# spawn new data reset task
|
||||||
data_cs, reset_done = await tn.start(
|
data_cs, reset_done = await nurse.start(
|
||||||
partial(
|
partial(
|
||||||
wait_on_data_reset,
|
wait_on_data_reset,
|
||||||
proxy,
|
proxy,
|
||||||
|
|
@ -705,9 +705,7 @@ async def _setup_quote_stream(
|
||||||
# to_trio, from_aio = trio.open_memory_channel(2**8) # type: ignore
|
# to_trio, from_aio = trio.open_memory_channel(2**8) # type: ignore
|
||||||
def teardown():
|
def teardown():
|
||||||
ticker.updateEvent.disconnect(push)
|
ticker.updateEvent.disconnect(push)
|
||||||
log.error(
|
log.error(f"Disconnected stream for `{symbol}`")
|
||||||
f'Disconnected stream for `{symbol}`'
|
|
||||||
)
|
|
||||||
client.ib.cancelMktData(contract)
|
client.ib.cancelMktData(contract)
|
||||||
|
|
||||||
# decouple broadcast mem chan
|
# decouple broadcast mem chan
|
||||||
|
|
@ -763,10 +761,7 @@ async def open_aio_quote_stream(
|
||||||
symbol: str,
|
symbol: str,
|
||||||
contract: Contract | None = None,
|
contract: Contract | None = None,
|
||||||
|
|
||||||
) -> (
|
) -> trio.abc.ReceiveStream:
|
||||||
trio.abc.Channel| # iface
|
|
||||||
tractor.to_asyncio.LinkedTaskChannel # actually
|
|
||||||
):
|
|
||||||
|
|
||||||
from tractor.trionics import broadcast_receiver
|
from tractor.trionics import broadcast_receiver
|
||||||
global _quote_streams
|
global _quote_streams
|
||||||
|
|
@ -783,7 +778,6 @@ async def open_aio_quote_stream(
|
||||||
yield from_aio
|
yield from_aio
|
||||||
return
|
return
|
||||||
|
|
||||||
from_aio: tractor.to_asyncio.LinkedTaskChannel
|
|
||||||
async with tractor.to_asyncio.open_channel_from(
|
async with tractor.to_asyncio.open_channel_from(
|
||||||
_setup_quote_stream,
|
_setup_quote_stream,
|
||||||
symbol=symbol,
|
symbol=symbol,
|
||||||
|
|
@ -989,18 +983,17 @@ async def stream_quotes(
|
||||||
)
|
)
|
||||||
cs: trio.CancelScope | None = None
|
cs: trio.CancelScope | None = None
|
||||||
startup: bool = True
|
startup: bool = True
|
||||||
iter_quotes: trio.abc.Channel
|
|
||||||
while (
|
while (
|
||||||
startup
|
startup
|
||||||
or cs.cancel_called
|
or cs.cancel_called
|
||||||
):
|
):
|
||||||
with trio.CancelScope() as cs:
|
with trio.CancelScope() as cs:
|
||||||
async with (
|
async with (
|
||||||
trio.open_nursery() as tn,
|
trio.open_nursery() as nurse,
|
||||||
open_aio_quote_stream(
|
open_aio_quote_stream(
|
||||||
symbol=sym,
|
symbol=sym,
|
||||||
contract=con,
|
contract=con,
|
||||||
) as iter_quotes,
|
) as stream,
|
||||||
):
|
):
|
||||||
# ugh, clear ticks since we've consumed them
|
# ugh, clear ticks since we've consumed them
|
||||||
# (ahem, ib_insync is stateful trash)
|
# (ahem, ib_insync is stateful trash)
|
||||||
|
|
@ -1028,9 +1021,9 @@ async def stream_quotes(
|
||||||
await rt_ev.wait()
|
await rt_ev.wait()
|
||||||
cs.cancel() # cancel called should now be set
|
cs.cancel() # cancel called should now be set
|
||||||
|
|
||||||
tn.start_soon(reset_on_feed)
|
nurse.start_soon(reset_on_feed)
|
||||||
|
|
||||||
async with aclosing(iter_quotes):
|
async with aclosing(stream):
|
||||||
# if syminfo.get('no_vlm', False):
|
# if syminfo.get('no_vlm', False):
|
||||||
if not init_msg.shm_write_opts['has_vlm']:
|
if not init_msg.shm_write_opts['has_vlm']:
|
||||||
|
|
||||||
|
|
@ -1045,21 +1038,19 @@ async def stream_quotes(
|
||||||
# wait for real volume on feed (trading might be
|
# wait for real volume on feed (trading might be
|
||||||
# closed)
|
# closed)
|
||||||
while True:
|
while True:
|
||||||
ticker = await iter_quotes.receive()
|
ticker = await stream.receive()
|
||||||
|
|
||||||
# for a real volume contract we rait for
|
# for a real volume contract we rait for
|
||||||
# the first "real" trade to take place
|
# the first "real" trade to take place
|
||||||
if (
|
if (
|
||||||
# not calc_price
|
# not calc_price
|
||||||
# and not ticker.rtTime
|
# and not ticker.rtTime
|
||||||
False
|
not ticker.rtTime
|
||||||
# not ticker.rtTime
|
|
||||||
):
|
):
|
||||||
# spin consuming tickers until we
|
# spin consuming tickers until we
|
||||||
# get a real market datum
|
# get a real market datum
|
||||||
log.debug(f"New unsent ticker: {ticker}")
|
log.debug(f"New unsent ticker: {ticker}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.debug("Received first volume tick")
|
log.debug("Received first volume tick")
|
||||||
# ugh, clear ticks since we've
|
# ugh, clear ticks since we've
|
||||||
|
|
@ -1075,18 +1066,13 @@ async def stream_quotes(
|
||||||
log.debug(f"First ticker received {quote}")
|
log.debug(f"First ticker received {quote}")
|
||||||
|
|
||||||
# tell data-layer spawner-caller that live
|
# tell data-layer spawner-caller that live
|
||||||
# quotes are now active desptie not having
|
# quotes are now streaming.
|
||||||
# necessarily received a first vlm/clearing
|
|
||||||
# tick.
|
|
||||||
ticker = await iter_quotes.receive()
|
|
||||||
feed_is_live.set()
|
feed_is_live.set()
|
||||||
fqme: str = quote['fqme']
|
|
||||||
await send_chan.send({fqme: quote})
|
|
||||||
|
|
||||||
# last = time.time()
|
# last = time.time()
|
||||||
async for ticker in iter_quotes:
|
async for ticker in stream:
|
||||||
quote = normalize(ticker)
|
quote = normalize(ticker)
|
||||||
fqme: str = quote['fqme']
|
fqme = quote['fqme']
|
||||||
await send_chan.send({fqme: quote})
|
await send_chan.send({fqme: quote})
|
||||||
|
|
||||||
# ugh, clear ticks since we've consumed them
|
# ugh, clear ticks since we've consumed them
|
||||||
|
|
|
||||||
|
|
@ -549,7 +549,7 @@ async def open_trade_dialog(
|
||||||
# to be reloaded.
|
# to be reloaded.
|
||||||
balances: dict[str, float] = await client.get_balances()
|
balances: dict[str, float] = await client.get_balances()
|
||||||
|
|
||||||
await verify_balances(
|
verify_balances(
|
||||||
acnt,
|
acnt,
|
||||||
src_fiat,
|
src_fiat,
|
||||||
balances,
|
balances,
|
||||||
|
|
|
||||||
|
|
@ -37,12 +37,6 @@ import tractor
|
||||||
from async_generator import asynccontextmanager
|
from async_generator import asynccontextmanager
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import wrapt
|
import wrapt
|
||||||
|
|
||||||
# TODO, port to `httpx`/`trio-websocket` whenver i get back to
|
|
||||||
# writing a proper ws-api streamer for this backend (since the data
|
|
||||||
# feeds are free now) as per GH feat-req:
|
|
||||||
# https://github.com/pikers/piker/issues/509
|
|
||||||
#
|
|
||||||
import asks
|
import asks
|
||||||
|
|
||||||
from ..calc import humanize, percent_change
|
from ..calc import humanize, percent_change
|
||||||
|
|
|
||||||
|
|
@ -655,7 +655,6 @@ async def open_trade_dialog(
|
||||||
# in) use manually constructed table from calling
|
# in) use manually constructed table from calling
|
||||||
# the `.get_mkt_info()` provider EP above.
|
# the `.get_mkt_info()` provider EP above.
|
||||||
_mktmap_table=mkt_by_fqme,
|
_mktmap_table=mkt_by_fqme,
|
||||||
only_require=list(mkt_by_fqme),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
pp_msgs: list[BrokerdPosition] = []
|
pp_msgs: list[BrokerdPosition] = []
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ from pathlib import Path
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
|
||||||
Sequence,
|
Sequence,
|
||||||
Hashable,
|
Hashable,
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
|
|
@ -57,7 +56,7 @@ from piker.brokers import (
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from piker.accounting import (
|
from ..accounting import (
|
||||||
Asset,
|
Asset,
|
||||||
MktPair,
|
MktPair,
|
||||||
)
|
)
|
||||||
|
|
@ -150,68 +149,57 @@ class SymbologyCache(Struct):
|
||||||
'Implement `Client.get_assets()`!'
|
'Implement `Client.get_assets()`!'
|
||||||
)
|
)
|
||||||
|
|
||||||
get_mkt_pairs: Callable|None = getattr(
|
if get_mkt_pairs := getattr(client, 'get_mkt_pairs', None):
|
||||||
client,
|
|
||||||
'get_mkt_pairs',
|
pairs: dict[str, Struct] = await get_mkt_pairs()
|
||||||
None,
|
for bs_fqme, pair in pairs.items():
|
||||||
)
|
|
||||||
if not get_mkt_pairs:
|
# NOTE: every backend defined pair should
|
||||||
|
# declare it's ns path for roundtrip
|
||||||
|
# serialization lookup.
|
||||||
|
if not getattr(pair, 'ns_path', None):
|
||||||
|
raise TypeError(
|
||||||
|
f'Pair-struct for {self.mod.name} MUST define a '
|
||||||
|
'`.ns_path: str`!\n'
|
||||||
|
f'{pair}'
|
||||||
|
)
|
||||||
|
|
||||||
|
entry = await self.mod.get_mkt_info(pair.bs_fqme)
|
||||||
|
if not entry:
|
||||||
|
continue
|
||||||
|
|
||||||
|
mkt: MktPair
|
||||||
|
pair: Struct
|
||||||
|
mkt, _pair = entry
|
||||||
|
assert _pair is pair, (
|
||||||
|
f'`{self.mod.name}` backend probably has a '
|
||||||
|
'keying-symmetry problem between the pair-`Struct` '
|
||||||
|
'returned from `Client.get_mkt_pairs()`and the '
|
||||||
|
'module level endpoint: `.get_mkt_info()`\n\n'
|
||||||
|
"Here's the struct diff:\n"
|
||||||
|
f'{_pair - pair}'
|
||||||
|
)
|
||||||
|
# NOTE XXX: this means backends MUST implement
|
||||||
|
# a `Struct.bs_mktid: str` field to provide
|
||||||
|
# a native-keyed map to their own symbol
|
||||||
|
# set(s).
|
||||||
|
self.pairs[pair.bs_mktid] = pair
|
||||||
|
|
||||||
|
# NOTE: `MktPair`s are keyed here using piker's
|
||||||
|
# internal FQME schema so that search,
|
||||||
|
# accounting and feed init can be accomplished
|
||||||
|
# a sane, uniform, normalized basis.
|
||||||
|
self.mktmaps[mkt.fqme] = mkt
|
||||||
|
|
||||||
|
self.pair_ns_path: str = tractor.msg.NamespacePath.from_ref(
|
||||||
|
pair,
|
||||||
|
)
|
||||||
|
|
||||||
|
else:
|
||||||
log.warning(
|
log.warning(
|
||||||
'No symbology cache `Pair` support for `{provider}`..\n'
|
'No symbology cache `Pair` support for `{provider}`..\n'
|
||||||
'Implement `Client.get_mkt_pairs()`!'
|
'Implement `Client.get_mkt_pairs()`!'
|
||||||
)
|
)
|
||||||
return self
|
|
||||||
|
|
||||||
pairs: dict[str, Struct] = await get_mkt_pairs()
|
|
||||||
if not pairs:
|
|
||||||
log.warning(
|
|
||||||
'No pairs from intial {provider!r} sym-cache request?\n\n'
|
|
||||||
'`Client.get_mkt_pairs()` -> {pairs!r} ?'
|
|
||||||
)
|
|
||||||
return self
|
|
||||||
|
|
||||||
for bs_fqme, pair in pairs.items():
|
|
||||||
if not getattr(pair, 'ns_path', None):
|
|
||||||
# XXX: every backend defined pair must declare
|
|
||||||
# a `.ns_path: tractor.NamespacePath` to enable
|
|
||||||
# roundtrip serialization lookup from a local
|
|
||||||
# cache file.
|
|
||||||
raise TypeError(
|
|
||||||
f'Pair-struct for {self.mod.name} MUST define a '
|
|
||||||
'`.ns_path: str`!\n\n'
|
|
||||||
f'{pair!r}'
|
|
||||||
)
|
|
||||||
|
|
||||||
entry = await self.mod.get_mkt_info(pair.bs_fqme)
|
|
||||||
if not entry:
|
|
||||||
continue
|
|
||||||
|
|
||||||
mkt: MktPair
|
|
||||||
pair: Struct
|
|
||||||
mkt, _pair = entry
|
|
||||||
assert _pair is pair, (
|
|
||||||
f'`{self.mod.name}` backend probably has a '
|
|
||||||
'keying-symmetry problem between the pair-`Struct` '
|
|
||||||
'returned from `Client.get_mkt_pairs()`and the '
|
|
||||||
'module level endpoint: `.get_mkt_info()`\n\n'
|
|
||||||
"Here's the struct diff:\n"
|
|
||||||
f'{_pair - pair}'
|
|
||||||
)
|
|
||||||
# NOTE XXX: this means backends MUST implement
|
|
||||||
# a `Struct.bs_mktid: str` field to provide
|
|
||||||
# a native-keyed map to their own symbol
|
|
||||||
# set(s).
|
|
||||||
self.pairs[pair.bs_mktid] = pair
|
|
||||||
|
|
||||||
# NOTE: `MktPair`s are keyed here using piker's
|
|
||||||
# internal FQME schema so that search,
|
|
||||||
# accounting and feed init can be accomplished
|
|
||||||
# a sane, uniform, normalized basis.
|
|
||||||
self.mktmaps[mkt.fqme] = mkt
|
|
||||||
|
|
||||||
self.pair_ns_path: str = tractor.msg.NamespacePath.from_ref(
|
|
||||||
pair,
|
|
||||||
)
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -791,6 +791,7 @@ async def install_brokerd_search(
|
||||||
|
|
||||||
@acm
|
@acm
|
||||||
async def maybe_open_feed(
|
async def maybe_open_feed(
|
||||||
|
|
||||||
fqmes: list[str],
|
fqmes: list[str],
|
||||||
loglevel: str | None = None,
|
loglevel: str | None = None,
|
||||||
|
|
||||||
|
|
@ -844,12 +845,13 @@ async def maybe_open_feed(
|
||||||
|
|
||||||
@acm
|
@acm
|
||||||
async def open_feed(
|
async def open_feed(
|
||||||
|
|
||||||
fqmes: list[str],
|
fqmes: list[str],
|
||||||
|
|
||||||
loglevel: str|None = None,
|
loglevel: str | None = None,
|
||||||
allow_overruns: bool = True,
|
allow_overruns: bool = True,
|
||||||
start_stream: bool = True,
|
start_stream: bool = True,
|
||||||
tick_throttle: float|None = None, # Hz
|
tick_throttle: float | None = None, # Hz
|
||||||
|
|
||||||
allow_remote_ctl_ui: bool = False,
|
allow_remote_ctl_ui: bool = False,
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,10 +36,10 @@ from ._sharedmem import (
|
||||||
ShmArray,
|
ShmArray,
|
||||||
_Token,
|
_Token,
|
||||||
)
|
)
|
||||||
from piker.accounting import MktPair
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from piker.data.feed import Feed
|
from ..accounting import MktPair
|
||||||
|
from .feed import Feed
|
||||||
|
|
||||||
|
|
||||||
class Flume(Struct):
|
class Flume(Struct):
|
||||||
|
|
@ -82,7 +82,7 @@ class Flume(Struct):
|
||||||
|
|
||||||
# TODO: do we need this really if we can pull the `Portal` from
|
# TODO: do we need this really if we can pull the `Portal` from
|
||||||
# ``tractor``'s internals?
|
# ``tractor``'s internals?
|
||||||
feed: Feed|None = None
|
feed: Feed | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rt_shm(self) -> ShmArray:
|
def rt_shm(self) -> ShmArray:
|
||||||
|
|
|
||||||
|
|
@ -113,9 +113,9 @@ def validate_backend(
|
||||||
)
|
)
|
||||||
if ep is None:
|
if ep is None:
|
||||||
log.warning(
|
log.warning(
|
||||||
f'Provider backend {mod.name!r} is missing '
|
f'Provider backend {mod.name} is missing '
|
||||||
f'{daemon_name!r} support?\n'
|
f'{daemon_name} support :(\n'
|
||||||
f'|_module endpoint-func missing: {name!r}\n'
|
f'The following endpoint is missing: {name}'
|
||||||
)
|
)
|
||||||
|
|
||||||
inits: list[
|
inits: list[
|
||||||
|
|
|
||||||
|
|
@ -63,27 +63,23 @@ dependencies = [
|
||||||
"trio-util >=0.7.0, <0.8.0",
|
"trio-util >=0.7.0, <0.8.0",
|
||||||
"trio-websocket >=0.10.3, <0.11.0",
|
"trio-websocket >=0.10.3, <0.11.0",
|
||||||
"typer >=0.9.0, <1.0.0",
|
"typer >=0.9.0, <1.0.0",
|
||||||
|
"rapidfuzz >=3.5.2, <4.0.0",
|
||||||
|
"pdbp >=1.5.0, <2.0.0",
|
||||||
"trio >=0.27",
|
"trio >=0.27",
|
||||||
"pendulum",
|
"pendulum >=3.0.0, <4.0.0",
|
||||||
"httpx >=0.27.0, <0.28.0",
|
"httpx >=0.27.0, <0.28.0",
|
||||||
"cryptofeed >=2.4.0, <3.0.0",
|
"cryptofeed >=2.4.0, <3.0.0",
|
||||||
"pyarrow>=18.0.0",
|
"pyarrow>=18.0.0",
|
||||||
"websockets ==12.0",
|
"websockets ==12.0",
|
||||||
"msgspec>=0.19.0,<0.20",
|
"msgspec>=0.19.0,<0.20",
|
||||||
"tractor",
|
"tractor",
|
||||||
|
"asyncvnc",
|
||||||
"tomlkit",
|
"tomlkit",
|
||||||
"trio-typing>=0.10.0",
|
"trio-typing>=0.10.0",
|
||||||
"numba>=0.61.0",
|
"numba>=0.61.0",
|
||||||
"pyvnc",
|
|
||||||
]
|
]
|
||||||
# ------ dependencies ------
|
|
||||||
|
|
||||||
|
[project.optional-dependencies]
|
||||||
# TODO: add an `--only daemon` group for running non-ui / pikerd
|
|
||||||
# service tree in distributed mode B)
|
|
||||||
# https://docs.astral.sh/uv/concepts/projects/dependencies/#optional-dependencies
|
|
||||||
|
|
||||||
[dependency-groups]
|
|
||||||
uis = [
|
uis = [
|
||||||
# https://docs.astral.sh/uv/concepts/projects/dependencies/#optional-dependencies
|
# https://docs.astral.sh/uv/concepts/projects/dependencies/#optional-dependencies
|
||||||
# TODO: make sure the levenshtein shit compiles on nix..
|
# TODO: make sure the levenshtein shit compiles on nix..
|
||||||
|
|
@ -96,11 +92,12 @@ uis = [
|
||||||
# for consideration,
|
# for consideration,
|
||||||
# - 'visidata'
|
# - 'visidata'
|
||||||
|
|
||||||
"qdarkstyle >=3.0.2, <4.0.0",
|
# TODO: add an `--only daemon` group for running non-ui / pikerd
|
||||||
"pyqt6 >=6.7.0, <7.0.0",
|
# service tree in distributed mode B)
|
||||||
"pyqtgraph",
|
# https://docs.astral.sh/uv/concepts/projects/dependencies/#optional-dependencies
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
# TODO: a toolset that makes debugging a `pikerd` service (tree) easy
|
# TODO: a toolset that makes debugging a `pikerd` service (tree) easy
|
||||||
# to hack on directly using more or less the local env:
|
# to hack on directly using more or less the local env:
|
||||||
# - xonsh + xxh
|
# - xonsh + xxh
|
||||||
|
|
@ -109,92 +106,40 @@ uis = [
|
||||||
#
|
#
|
||||||
# console ehancements and eventually remote debugging extras/helpers.
|
# console ehancements and eventually remote debugging extras/helpers.
|
||||||
# use `uv --dev` to enable
|
# use `uv --dev` to enable
|
||||||
repl = [
|
|
||||||
# debug
|
|
||||||
"pdbp >=1.5.0, <2.0.0",
|
|
||||||
"greenback >=1.1.1, <2.0.0",
|
|
||||||
"xonsh",
|
|
||||||
"prompt-toolkit ==3.0.40",
|
|
||||||
"pyperclip>=1.9.0",
|
|
||||||
|
|
||||||
]
|
|
||||||
testing = [
|
|
||||||
"pytest",
|
|
||||||
]
|
|
||||||
de = [
|
|
||||||
# DE-specific
|
|
||||||
"i3ipc>=2.2.1",
|
|
||||||
]
|
|
||||||
dev = [
|
dev = [
|
||||||
# https://docs.astral.sh/uv/concepts/projects/dependencies/#development-dependencies
|
"pytest >=6.0.0, <7.0.0",
|
||||||
"cython >=3.0.0, <4.0.0",
|
"elasticsearch >=8.9.0, <9.0.0",
|
||||||
|
"xonsh >=0.14.2, <0.15.0",
|
||||||
# nested deps-groups
|
"prompt-toolkit ==3.0.40",
|
||||||
# https://docs.astral.sh/uv/concepts/projects/dependencies/#nesting-groups
|
"cython >=3.0.0, <4.0.0",
|
||||||
{include-group = 'uis'},
|
"greenback >=1.1.1, <2.0.0",
|
||||||
{include-group = 'repl'},
|
"ruff>=0.9.6",
|
||||||
{include-group = 'testing'},
|
|
||||||
{include-group = 'de'},
|
|
||||||
]
|
]
|
||||||
lint = [
|
|
||||||
# XXX, with flake.nix needs to be from nixpkgs
|
|
||||||
"ruff>=0.9.6"
|
|
||||||
#
|
|
||||||
# ^TODO? these markers don't work; use deps-flags for now?
|
|
||||||
# ; os_name != 'nixos' and platform_system != 'NixOS'",
|
|
||||||
# ; defined('IN_NIX_SHELL')",
|
|
||||||
]
|
|
||||||
dbs = [
|
|
||||||
"elasticsearch >=8.9.0, <9.0.0",
|
|
||||||
]
|
|
||||||
# ------ dependency-groups ------
|
|
||||||
|
|
||||||
|
|
||||||
[tool.pytest.ini_options]
|
|
||||||
# https://docs.pytest.org/en/stable/reference/reference.html#configuration-options
|
|
||||||
testpaths = [
|
|
||||||
"tests",
|
|
||||||
]
|
|
||||||
# https://docs.pytest.org/en/stable/reference/reference.html#confval-console_output_style
|
|
||||||
console_output_style = 'progress'
|
|
||||||
|
|
||||||
# https://docs.pytest.org/en/stable/how-to/plugins.html#disabling-plugins-from-autoloading
|
|
||||||
# https://docs.pytest.org/en/stable/how-to/plugins.html#deactivating-unregistering-a-plugin-by-name
|
|
||||||
addopts = '-p no:xonsh'
|
|
||||||
# ------ tool.pytest ------
|
|
||||||
|
|
||||||
|
|
||||||
[project.scripts]
|
[project.scripts]
|
||||||
piker = "piker.cli:cli"
|
piker = "piker.cli:cli"
|
||||||
pikerd = "piker.cli:pikerd"
|
pikerd = "piker.cli:pikerd"
|
||||||
ledger = "piker.accounting.cli:ledger"
|
ledger = "piker.accounting.cli:ledger"
|
||||||
# ------ project.scripts ------
|
|
||||||
|
|
||||||
[tool.hatch.build.targets.sdist]
|
[tool.hatch.build.targets.sdist]
|
||||||
include = ["piker"]
|
include = ["piker"]
|
||||||
|
|
||||||
[tool.hatch.build.targets.wheel]
|
[tool.hatch.build.targets.wheel]
|
||||||
include = ["piker"]
|
include = ["piker"]
|
||||||
# ------ tool.hatch ------
|
|
||||||
|
|
||||||
|
|
||||||
# TODO? move to a `uv.toml`?
|
# TODO? move to a `uv.toml`?
|
||||||
[tool.uv]
|
[tool.uv]
|
||||||
python-preference = 'system'
|
python-preference = 'system'
|
||||||
python-downloads = 'manual'
|
python-downloads = 'manual'
|
||||||
# https://docs.astral.sh/uv/concepts/projects/dependencies/#default-groups
|
|
||||||
default-groups = ['uis', 'dev']
|
|
||||||
# ------ tool.uv ------
|
|
||||||
|
|
||||||
|
|
||||||
[tool.uv.sources]
|
[tool.uv.sources]
|
||||||
pyqtgraph = { git = "https://github.com/pikers/pyqtgraph.git" }
|
pyqtgraph = { git = "https://github.com/pikers/pyqtgraph.git" }
|
||||||
|
asyncvnc = { git = "https://github.com/pikers/asyncvnc.git", branch = "main" }
|
||||||
tomlkit = { git = "https://github.com/pikers/tomlkit.git", branch ="piker_pin" }
|
tomlkit = { git = "https://github.com/pikers/tomlkit.git", branch ="piker_pin" }
|
||||||
pyvnc = { git = "https://github.com/regulad/pyvnc.git" }
|
|
||||||
|
|
||||||
# XXX since, we're like, always hacking new shite all-the-time. Bp
|
# XXX, since we're like, always hacking new shite atm.. Bp
|
||||||
tractor = { git = "https://github.com/goodboy/tractor.git", branch ="piker_pin" }
|
tractor = { git = "https://pikers.dev/goodboy/tractor", branch = "piker_pin" }
|
||||||
# tractor = { git = "https://pikers.dev/goodboy/tractor", branch = "piker_pin" }
|
|
||||||
# tractor = { git = "https://pikers.dev/goodboy/tractor", branch = "main" }
|
# tractor = { git = "https://pikers.dev/goodboy/tractor", branch = "main" }
|
||||||
# ------ goodboy ------
|
|
||||||
# hackin dev-envs, usually there's something new he's hackin in..
|
|
||||||
# tractor = { path = "../tractor", editable = true }
|
# tractor = { path = "../tractor", editable = true }
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue