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

Rekt pps? problem? => piker.accounting #489

Merged
merged 294 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
294 commits
Select commit Hold shift + click to select a range
452cd7d
Optionally load `MktPair` in `Flume`s
goodboy Mar 21, 2023
d4a5a30
Add `MktPair.suffix: str` read from contract info
goodboy Mar 21, 2023
1d08ee6
`.clearing`: broad rename of `fqsn` -> `fqme`
goodboy Mar 21, 2023
0f30417
Use `MktPair` for `Flume.symbol` when used by backend
goodboy Mar 22, 2023
580165f
Expect new `MktPair.tick_size: Decimal` attr in ems
goodboy Mar 22, 2023
a9778e4
Always cast `Order.symbol: str` for now
goodboy Mar 22, 2023
d62fb65
`kraken`: parse our source asset key and set on `MktPair.src: str`
goodboy Mar 22, 2023
b6df83a
Typecast `OrderMode.staged.symbol: str` before `.copy()`!
goodboy Mar 22, 2023
7be85a8
Drop use of legacy `Symbol.broker_info` in display startup
goodboy Mar 22, 2023
dc2332c
'`kraken`: finally, use new `MktPair` in `'mkt_info'` init msg field!'
goodboy Mar 22, 2023
6272cae
Drop more `Optional` usage on our `Struct`
goodboy Mar 22, 2023
406565f
Rename `fqsn` -> `fqme` in paper engine
goodboy Mar 22, 2023
fd9e484
Add `.__str__()` to mktpair and symbol types, fix `MktPair.fqme` toke…
goodboy Mar 22, 2023
0694662
Use `str(cmd.symbol)` for fqme on cancels, add `_nowait()` method names
goodboy Mar 22, 2023
5817828
Rename `Client.send_update()` -> `.update_nowait()`
goodboy Mar 22, 2023
7498cbb
Use `Struct.copy()` with update dict for `Order` from staged
goodboy Mar 22, 2023
2454dda
Use `MktPair` attr `.size_tick` in charting
goodboy Mar 22, 2023
3bf48ab
Use a single log for entire `.clearing` subsys
goodboy Mar 22, 2023
a462de6
Use a single log for entire `.service` subsys
goodboy Mar 22, 2023
2ae9576
Add common logger instance for `.brokers`
goodboy Mar 22, 2023
ea42f66
Use common `.brokers` logger in most backends
goodboy Mar 22, 2023
1c576d7
Dump `Position`s as pformatted dicts for now..
goodboy Mar 22, 2023
3e5da64
Cache contract lookups from `Client.get_con()`
goodboy Mar 22, 2023
c59ec77
WIP: refactor ib pp load init
goodboy Mar 22, 2023
59b095b
`kraken`: heh, use `trio_util` for trades streamz tooo XD
goodboy Mar 22, 2023
199a5e8
`ib`: stick exc handler around client connection erros
goodboy Mar 23, 2023
16e11d4
Move toml table decoder to separate mod
goodboy Mar 23, 2023
f304901
`ib`: drop use of `_account2clients` in `load_clients_for_trio()`
goodboy Mar 23, 2023
aa5f252
`ib`: never override existing ledger records
goodboy Mar 23, 2023
8f79c37
Generalize `MktPair.from_msg()` handling
goodboy Mar 23, 2023
b718b56
`binance`: use `MktPair` in live feed setup
goodboy Mar 23, 2023
c5b172a
`binance`: pre-process `Pair` filters at init
goodboy Mar 23, 2023
485a17a
Drop weird extra line from license headers
goodboy Mar 24, 2023
e0067a4
WIP: trying out `typer` for ledger cli
goodboy Mar 24, 2023
ccfafee
Drop `cryptofeed`, what a mess XD
goodboy Mar 24, 2023
ff285fb
`binance`: adjust earch to expect `Pair`s
goodboy Mar 26, 2023
2c23bc1
First working `brokerd` -> `trades_dialogue()` ep loader
goodboy Mar 27, 2023
978c59f
`ib`: break up data vs. broker enabled modules
goodboy Mar 27, 2023
29ad20b
`ib`: only process ledger-txs once per client
goodboy Mar 27, 2023
6012306
Use our `@acm` alias in paper eng
goodboy Mar 27, 2023
53c76d3
Drop `Optional` use from daemon mod
goodboy Mar 27, 2023
bc249fb
Move `.clearing._allocate` -> `accounting._allocate`
goodboy Mar 27, 2023
7b3d724
Rework `.config` routines to use `pathlib.Path`
goodboy Mar 27, 2023
4494acb
Write a separate `pps.<brokername>.<accountname>.toml` file per account
goodboy Mar 27, 2023
2cb59fe
Flatter format for pos/ledger mngr statements
goodboy Mar 27, 2023
a336def
`ib`: again, only *update* ledger records from API
goodboy Mar 27, 2023
29a5910
`ib`: move flex utils to new submod
goodboy Mar 28, 2023
50be10a
`ib`: keep broker name in `Transaction.fqsn`
goodboy Mar 28, 2023
9f7aa3d
Always use the "most resolved" `Position.symbol: MktPair`
goodboy Mar 29, 2023
61fb783
Formalize a ledger type + API: `TransactionLedger`
goodboy Mar 29, 2023
a74caa9
Add paper engine "offline loading" support to the ledger cli
goodboy Mar 29, 2023
1560330
Convert `Flume.MktPair.size_tick` to float for dark clearing
goodboy Mar 29, 2023
2cc77c2
Rework paper engine for "offline" pp loading
goodboy Mar 29, 2023
48f0969
`kraken`: write ledger and pps files on startup
goodboy Mar 30, 2023
72abe98
Async-ify order client methods and some renaming
goodboy Mar 30, 2023
fb13c7c
`ib`: drop pp mismatch err block, we already do it in audit routine
goodboy Mar 30, 2023
879657c
Detail `pikerd` sock bind collision in error
goodboy Apr 1, 2023
56cd15f
ib: maybe incr client id; can't catch api errors..
goodboy Apr 2, 2023
96006b2
Adjust tests to `.clearing._client.OrderClient` type
goodboy Apr 3, 2023
008bfed
ib: lul, fix oil (cl) venue to correctly be nymex..
goodboy Apr 3, 2023
d67031d
Ensure we set the test config dir in the root actor..
goodboy Apr 4, 2023
b619e4a
WIP complete rework of paper engine tests
goodboy Apr 4, 2023
1944f75
Expose `piker.clearing.OrderClient`
goodboy Apr 4, 2023
eb7a746
Always pass `loglevel: str` to daemon root task eps
goodboy Apr 4, 2023
4c1d174
Expect `loglevel: str` in brokerd root task ep
goodboy Apr 4, 2023
97e3c06
Set `emsd` log level and clearly report startup pps
goodboy Apr 4, 2023
9770a39
Cancel the `OrderClient` sync-method relay task on exit
goodboy Apr 4, 2023
f513614
paper engine: use the `fqme` for the `bs_mktid`
goodboy Apr 4, 2023
a635998
Drop masked `MktPair.size_tick_digits()` cruft
goodboy Apr 4, 2023
70efce1
`kraken`: handle ws connection startup status msgs
goodboy Apr 4, 2023
b2a5f86
Use `--pdb` flag to config `brokerd` debug mode
goodboy Apr 4, 2023
2d609dc
Drop `loglevel` from `spawn_args` inputs to `maybe_spawn_daemon()`
goodboy Apr 4, 2023
2806a4c
Tweak ems msg-received log msg
goodboy Apr 4, 2023
33a7836
paper: always sync pps.toml state on startup
goodboy Apr 4, 2023
b8a975a
Drop `"<broker>.<account>.."` from pps.toml entries
goodboy Apr 4, 2023
05a33ae
Make default order size to decimal
goodboy Apr 5, 2023
5ee044e
Another `@acm` in `._cacheables` XD
goodboy Apr 5, 2023
1d2d4b4
Only log about pps once in order mode code
goodboy Apr 5, 2023
3f2f5ed
kraken: rename `Client._atable` -> `_altnames`
goodboy Apr 5, 2023
6decd41
kraken: drop console setup, now done during brokerd init
goodboy Apr 5, 2023
2140185
`kraken`: add module level `get_mkt_info()`
goodboy Apr 5, 2023
83514b0
`binance`: add `get_mkt_info()` ep
goodboy Apr 5, 2023
55b4866
Use `force_mkt` override in paper pps updates
goodboy Apr 5, 2023
f42bc2d
`pprint.pformat()` IB position mismatch log msgs
goodboy Apr 5, 2023
6225988
paper: on no input fqme, load all mktinfos from pos table
goodboy Apr 5, 2023
250e1c4
`ledger` cli: dump colored summary lines to console
goodboy Apr 6, 2023
b7ddf9c
paper-eng: close context and terminate actor on exit
goodboy Apr 6, 2023
f92c289
Drop old blessings code, general cleanups
goodboy Apr 6, 2023
4845659
`order_mode`: broad rename book -> client
goodboy Apr 8, 2023
abbba1f
Pack startup pps into a table keyed by fqmes
goodboy Apr 9, 2023
e524c6f
`binance`: add startup caching info log msg
goodboy Apr 10, 2023
30af91a
Rewrite order ctl tests as a parametrization
goodboy Apr 10, 2023
2ed9e40
Better EMS client-side msg formatting
goodboy Apr 10, 2023
9287650
Fix zero-pp entry to toml case for new file-per-account format
goodboy Apr 11, 2023
589232d
Only flip size sign for seels if not already -ve
goodboy Apr 11, 2023
7de914d
Fix bad-fqme test, adjust prices based on buy/sell
goodboy Apr 11, 2023
3b75799
Link `tractor` debug mode to `pytest` --pdb flag
goodboy Apr 11, 2023
dedc51a
Quantize order prices prior to `OrderClient.send()`
goodboy Apr 11, 2023
2cf7dac
Another fqsn -> fqme rename
goodboy Apr 11, 2023
146e099
More explicit test mod docstring
goodboy Apr 11, 2023
02eb966
Rename ems test mod
goodboy Apr 11, 2023
48cae3c
`ib`: rejects their own fractional size tick..
goodboy Apr 11, 2023
b810de3
Rename fqsn -> fqme in feeds tests
goodboy Apr 12, 2023
b1e162e
Fix ._util import in questrade backend
goodboy Apr 14, 2023
611d86d
Change `Flume.symbol` -> `.mkt: MktPair`
goodboy Apr 14, 2023
a301fab
Change`.ui._fsp` to use `Flume.mkt`
goodboy Apr 14, 2023
0917b58
Flip `.feed` and `._sampling` over to new stuff
goodboy Apr 14, 2023
10a39ca
More detailed dark-slap comments
goodboy Apr 14, 2023
0d2e713
`binance`: facepalm, swap price/size_tick methods..
goodboy Apr 16, 2023
bba1ee4
Allow mkt info table input to `.iter_trans()`
goodboy Apr 17, 2023
f106472
Fix size quantization and closed position popping..
goodboy Apr 17, 2023
7ee6f36
Actually, require `mkt_by_fqme` in `.iter_trans()`
goodboy Apr 17, 2023
4b7ac1d
Port paper engine to latest `.accounting` sys fixes
goodboy Apr 17, 2023
83f1922
`binance.get_mkt_info()`: bleh, right `@lru_cache` dun work for async..
goodboy Apr 17, 2023
fa88924
Do we need feed mod enabled? no right?
goodboy Apr 17, 2023
06b80ff
ARRG, disable `dunst` notifications for now in order mode
goodboy Apr 17, 2023
53a41ba
Add subsys log to new `.data._util`
goodboy Apr 18, 2023
d4c8ba1
`.accounting._mktinfo`: better fqme `MktPair` handling
goodboy Apr 18, 2023
afdbf8e
`.accounting`: Use `_fqme()` throughout and export decimal converters
goodboy Apr 18, 2023
6f5a265
Port `.clearing` to new `unpack_fqme()`
goodboy Apr 18, 2023
d48b2c5
`._paper_engine`: right, load `MktPair` in `fqme is not None` usage
goodboy Apr 18, 2023
4129d69
Add `.data.validate` checker for live feed layer
goodboy Apr 18, 2023
adb62dc
Port oustanding parts of codebase to `unpack_fqme()`
goodboy Apr 18, 2023
6008497
Use more "hierarchical" schema for fsp shm segment names
goodboy Apr 18, 2023
d1cf90e
ib: finally convert ledger processing to use `MktPair`
goodboy Apr 18, 2023
b4f2f49
ib: make `stream_quotes()` compat with new init msg bare-minimums
goodboy Apr 18, 2023
765b8f8
Support both input msg-sequence types
goodboy Apr 19, 2023
83802e9
Drop (missed) usage of `Symbol.from_fqsn()` in order mode
goodboy Apr 19, 2023
4131ff1
Rename `bs_mktid` -> `bs_fqme` and drop (some) `fqsn`s
goodboy Apr 19, 2023
e317310
binance: make `stream_quotes()` deliver new `list[FeedInit]` API
goodboy Apr 19, 2023
1b50bff
Error test harness if `--pdb` passed without `-s`
goodboy Apr 19, 2023
bcf355e
Fix up `@async_lifo_cache` typing, add TODOs for move to `tractor`
goodboy Apr 19, 2023
af2f875
binance: use `@async_lifo_cache` on `.get_mkt_info()` ep
goodboy Apr 19, 2023
d0e01ff
Fix `Symbol.from_fqme()` extra added symbols..
goodboy Apr 20, 2023
0d93871
kraken: drop `Client.cache_assets()`, simpler `.pair_info()`, drop `.…
goodboy Apr 20, 2023
d728897
kraken: port to `FeedInit` and proper impl of `get_mkt_info()` ep
goodboy Apr 20, 2023
4a0beda
kraken: asyncify and use `get_mkt_info()` in `norm_trade_records()`
goodboy Apr 20, 2023
3cd853c
order_mode: revert switch to `MktPair` for pre-order loading
goodboy Apr 20, 2023
9d04acc
Factor out all history mgmt-logic into a new `.data.history`
goodboy Apr 20, 2023
59743b7
Rework `NoBsWs` to avoid agen/`trio` incompatibility
goodboy Apr 21, 2023
b03564d
binance: port to new `NoBsWs` api and drop `trio_util` usage
goodboy Apr 21, 2023
34ff5ff
kraken: port to new `NoBsWs`, passing timeout (counts) during setup
goodboy Apr 21, 2023
f6cd08c
Attempt to guard against numercial "anomalies" in `Viz.maxmin()`, add…
goodboy Apr 21, 2023
af068c5
binance: port `stream_messages()` to use `match:` and a new `L1` struct
goodboy Apr 21, 2023
ed434e2
Disable ems init order-dialog notifications by default
goodboy Apr 21, 2023
0b43e0a
Try having `brokerd` eps defined in `.brokers._daemon`
goodboy Apr 21, 2023
0a8dd7b
Try to disable `snappy` compression on variables; it breaks everythin…
goodboy Apr 21, 2023
363a2bb
binance: use new `int` sub-id for each request
goodboy Apr 22, 2023
7a3bce3
.data._web_bs: add client module name to log msgs
goodboy Apr 26, 2023
685688d
ib: add `mbt.cme` micro-btc futes to adhoc set
goodboy Apr 26, 2023
226c336
Smh, handle `fixture==None` case..
goodboy May 9, 2023
c415bd1
If backend does not provide `bs_mktid`, use the `bs_fqme`
goodboy May 9, 2023
05fb4a4
kraken: drop recv timeout for recon ws
goodboy May 9, 2023
038b20d
wsbs: increase msg rx timeout to 16 secs
goodboy May 9, 2023
cb8833d
ib: clear error events on every received?
goodboy May 9, 2023
88f3912
test_ems: doc out some remaining suites
goodboy May 9, 2023
96532ad
ui._display: no downsampling on history chart default view call
goodboy May 9, 2023
f8c8f63
Drop `Optional` usage from marketstore module
goodboy May 9, 2023
80338e1
kucoin: WIP moving to FeedInit API
goodboy May 9, 2023
f1f2ba2
kucoin: deliver `FeedInit` msgs on feed startup
goodboy May 9, 2023
361fc46
Drop passing `loglevel` to `stream_quotes()`, level is set when actor…
goodboy May 9, 2023
769b292
Allow `brokerd` runtime switch to paper mode
goodboy May 9, 2023
c6e5368
paperboi: fix fqme parsing to handle `bs_fqme` cases
goodboy May 9, 2023
e06f9dc
kucoin: port to new `NoBsWs` api semantics
goodboy May 10, 2023
7ff8aa1
ib: passthrough host arg to vnc client for click hack
goodboy May 11, 2023
957224b
ib: support remote host vnc client connections
goodboy May 12, 2023
488a0cd
Add `.config.load_account()`
goodboy May 12, 2023
5278f8b
Add `.config.load_ledger()` for transaction record files
goodboy May 12, 2023
5f79434
Use new `.config` helpers for `accounting._pos/._ledger` file loading
goodboy May 12, 2023
2865f0e
`piker.config`: use `tomlkit` for accounting files
goodboy May 12, 2023
a62283b
Drop final use of `toml` 3rd party lib
goodboy May 12, 2023
df96155
Always allow overruns in sampler context
goodboy May 13, 2023
50a4c42
Add `touch_if_dne: bool` to `config.load()`
goodboy May 13, 2023
779c0b7
Make `.accounting._ledger` use `tomlkit`
goodboy May 13, 2023
c349d50
Allow creation of empty account files
goodboy May 13, 2023
b288d70
ib.broker: load account name map as a `bidict` (no `tomlkit` support)
goodboy May 13, 2023
b572cd1
kucoin: store fqme -> mktids table
goodboy May 13, 2023
2e8268b
Allow passing `allow_overruns: bool` to `Services.start_service_task()`
goodboy May 13, 2023
1f0db31
ib.broker: always cast `asset_type` to `str`
goodboy May 13, 2023
cfb125b
`.data.feed`: finally solve startup overruns issue
goodboy May 13, 2023
ebe351e
kucoin: raise `DataUnavailable` if we get empty time array at some po…
goodboy May 14, 2023
98c0438
Woops, implement `Symbol.fqme` same a `Mktpair`..
goodboy May 15, 2023
1e1e64f
ib: fix op error when `end_dt` is `None`: the first query
goodboy May 15, 2023
1263835
ib.api: make `get_sym_details()` and `get_quote()` mutex methods
goodboy May 15, 2023
f20e2d6
ib.feed: start drafting out `get_mkt_info()` endpoint
goodboy May 15, 2023
b096ee3
Make `FeedInit.shm_write_opts` an empty dict by default
goodboy May 16, 2023
147e1ba
Remove typo-ed `sum_tick_vlm` config from all crypto backends
goodboy May 16, 2023
07b7d1d
ib: implement `FeedInit` style quote stream setup
goodboy May 16, 2023
5c8a45c
Fix `MktPair.bs_fqme` to properly strip broker suffix
goodboy May 17, 2023
ae049eb
Pass and use `MktPair` throughout history routines
goodboy May 17, 2023
3294def
`fqme` adjustments to marketstore module
goodboy May 17, 2023
d0ba9a0
Start draft `conf.toml` "root" config with tsdb contact info
goodboy May 17, 2023
a44e926
kucoin: handle ws welcome, subs-ack and pong msgs
goodboy May 17, 2023
12bfabf
Expose `.accounting.unpack_fqme()`
goodboy May 17, 2023
89e8a83
Support fqme rendering *without* the src key
goodboy May 17, 2023
907eaa6
Pass `mkt: MktPair` to `.open_history_client()`
goodboy May 17, 2023
b2bf0b0
ib.api: wholesale fqsn -> fqme renames
goodboy May 17, 2023
97b2b25
Avoid import cycle in clearing client
goodboy May 18, 2023
a1a1067
Go back to `tomllib` for ledger loading, it's wayy faster
goodboy May 18, 2023
8d7a9fa
Make `MktPair.pair()` a meth, allow passing in a delim character
goodboy May 18, 2023
89d24cf
Oof, fix closed position popping by fqme..
goodboy May 18, 2023
c6da09f
Add fast(er), time-sorted ledger records
goodboy May 18, 2023
5300361
Add longer timeout on brokerd ctx cancel; seems to work?
goodboy May 22, 2023
60a6f32
ib: use flex report datetime sort
goodboy May 22, 2023
e4e4cac
.data.feed: Less stringency with fqme matching
goodboy May 22, 2023
660a94d
Don't expect `conf.toml`'s network section
goodboy May 22, 2023
2f2d612
Add todo to switch to `dst/src` delim
goodboy May 22, 2023
588770d
ib: rename lingering fqsn -> fqme
goodboy May 22, 2023
c93d119
Move tmpdir creation into separate fixture
goodboy May 22, 2023
31a00ec
Rename fqsn -> fqme in ui mods
goodboy May 22, 2023
dd10acb
Replace `Transaction.fqsn` -> `.fqme`
goodboy May 22, 2023
7f24669
Remove remaining `fqsn` usage from code base minus backward compats
goodboy May 22, 2023
d3bafb0
Always prefer a config template if found
goodboy May 23, 2023
56b23e1
Add docker and elasticsearch to test deps
goodboy May 23, 2023
611d1ee
Drop db flags from pikerd startup
goodboy May 23, 2023
bd919f9
_ahab: use `Services` api to spawn docker tasks
goodboy May 23, 2023
e7a172b
Reimplement marketstore and elasticsearch daemons
goodboy May 23, 2023
d094625
Activate docker daemons via flags using exit stack
goodboy May 23, 2023
cd55d02
Re-implement db tests using new ahab daemons
goodboy May 23, 2023
6ad8c60
More detailed `Position.events` todo
goodboy May 23, 2023
ff74d47
kucoin: fix fqme or search result key lookups
goodboy May 23, 2023
b44b091
ib: i guess only discard `MktPair.src: Asset` on non-forex XD
goodboy May 23, 2023
e82f7f9
Skip elasticsearch test for now, container build seems borked?
goodboy May 24, 2023
8e97814
Add "no vlm" indication to `FeedInit`
goodboy May 24, 2023
e8787d8
ib: unset vlm via new `FeedInit.shm_write_opts` field
goodboy May 24, 2023
9a063cc
ib: Solve lingering bugs for non-vlm contracts
goodboy May 24, 2023
bd8e476
Port everything strictly to `Position.mkt` and `Flume.mkt`
goodboy May 24, 2023
738d0ca
Rename db tests to test_docker_services
goodboy May 24, 2023
35f0520
Drop `Symbol` / `.symbol` support from `.accounting`
goodboy May 24, 2023
39af215
kraken: use new `Position.mkt` attr
goodboy May 24, 2023
1b577ee
Change over the UI layer to use `MktPair`
goodboy May 24, 2023
7381c36
Strictly drop `LinkedSplits.symbol` B)
goodboy May 24, 2023
f0a346d
Some linting fixes after trying out `ruff`
goodboy May 24, 2023
da4d344
Change to `piker_pin` branch in `tomlkit` fork
goodboy May 25, 2023
9c80969
.data.validate: add missing endpoint warnings
goodboy May 25, 2023
9bc11d8
Add basic config checking tests
goodboy May 25, 2023
4a8e8a3
Fix account config loading logic discovered in new test XD
goodboy May 25, 2023
06cc3ac
Tidy up ems tests as per some `ruff`in
goodboy May 25, 2023
3d8c1a7
ib: don't log-emit ib pp msg when none exists..
goodboy May 26, 2023
40c5f39
conftest: be explicit about which config we touch
goodboy May 26, 2023
3b5bd8f
Ensure quote last price is a `float`
goodboy May 26, 2023
5f1d0fc
`tmpconfdir`: always assert brokers config created
goodboy May 26, 2023
5e2107f
Adjust `config.load()` to handle CI git checkout dir, seems they chan…
goodboy May 26, 2023
9ec664f
Drop elastic search container build for now since we're also skipping…
goodboy May 26, 2023
024cf8b
add in `[kucoin]` section to brokers conf
goodboy May 26, 2023
4f67ac0
Change to new context-cancelled msg contents: pikerd is canceller
goodboy May 26, 2023
d6331ce
Add nonlocal annots to satisfy ruff
goodboy May 28, 2023
41aa87f
Fix `_digits` attr names in order mode..
goodboy May 28, 2023
f6549fc
Always allocate a new `OrderClient` per `open_ems()` call
goodboy May 28, 2023
abd3cef
Parametrize ems service test to cancel with API and kbi
goodboy May 28, 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
4 changes: 4 additions & 0 deletions config/conf.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[network]
tsdb.backend = 'marketstore'
tsdb.host = 'localhost'
tsdb.grpc_port = 5995
13 changes: 13 additions & 0 deletions dockering/ib/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
# https://github.com/waytrade/ib-gateway-docker/blob/master/docker-compose.yml
version: "3.5"


services:

ib_gw_paper:

# apparently java is a mega cukc:
# https://stackoverflow.com/a/56895801
# https://bugs.openjdk.org/browse/JDK-8150460
ulimits:
# nproc: 65535
nproc: 6000
nofile:
soft: 2000
hard: 3000

# other image tags available:
# https://github.com/waytrade/ib-gateway-docker#supported-tags
# image: waytrade/ib-gateway:981.3j
Expand Down
73 changes: 59 additions & 14 deletions piker/_cacheables.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# piker: trading gear for hackers
# Copyright (C) Tyler Goodlet (in stewardship for piker0)
# Copyright (C) Tyler Goodlet (in stewardship for pikers)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
Expand All @@ -14,14 +14,20 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

"""
'''
Cacheing apis and toolz.

"""
'''

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

from tractor.trionics import maybe_open_context
Expand All @@ -32,19 +38,54 @@

log = get_logger(__name__)


def async_lifo_cache(maxsize=128):
"""Async ``cache`` with a LIFO policy.
T = TypeVar("T")
P = ParamSpec("P")


# TODO: move this to `tractor.trionics`..
# - egs. to replicate for tests: https://github.com/aio-libs/async-lru#usage
# - their suite as well:
# https://github.com/aio-libs/async-lru/tree/master/tests
# - asked trio_util about it too:
# https://github.com/groove-x/trio-util/issues/21
def async_lifo_cache(
maxsize=128,

# NOTE: typing style was learned from:
# https://stackoverflow.com/a/71132186
) -> Callable[
Callable[P, Awaitable[T]],
Callable[
Callable[P, Awaitable[T]],
Callable[P, Awaitable[T]],
],
]:
'''
Async ``cache`` with a LIFO policy.

Implemented my own since no one else seems to have
a standard. I'll wait for the smarter people to come
up with one, but until then...
"""

NOTE: when decorating, due to this simple/naive implementation, you
MUST call the decorator like,

.. code:: python

@async_lifo_cache()
async def cache_target():

'''
cache = OrderedDict()

def decorator(fn):
def decorator(
fn: Callable[P, Awaitable[T]],
) -> Callable[P, Awaitable[T]]:

async def wrapper(*args):
async def decorated(
*args: P.args,
**kwargs: P.kwargs,
) -> T:
key = args
try:
return cache[key]
Expand All @@ -53,16 +94,20 @@ async def wrapper(*args):
# discard last added new entry
cache.popitem()

# do it
cache[key] = await fn(*args)
# call underlying
cache[key] = await fn(
*args,
**kwargs,
)
return cache[key]

return wrapper
return decorated

return decorator


@asynccontextmanager
# TODO: move this to `.brokers.utils`..
@acm
async def open_cached_client(
brokername: str,
) -> 'Client': # noqa
Expand Down
115 changes: 115 additions & 0 deletions piker/accounting/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# piker: trading gear for hackers
# Copyright (C) Tyler Goodlet (in stewardship for pikers)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.

# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

'''
"Accounting for degens": count dem numberz that tracks how much you got
for tendiez.

'''
from ..log import get_logger

from ._ledger import (
iter_by_dt,
Transaction,
TransactionLedger,
open_trade_ledger,
)
from ._pos import (
load_pps_from_ledger,
open_pps,
Position,
PpTable,
)
from ._mktinfo import (
Asset,
dec_digits,
digits_to_dec,
MktPair,
Symbol,
unpack_fqme,
)
from ._allocate import (
mk_allocator,
Allocator,
)

log = get_logger(__name__)

__all__ = [
'Allocator',
'Asset',
'MktPair',
'Position',
'PpTable',
'Symbol',
'Transaction',
'TransactionLedger',
'dec_digits',
'digits_to_dec',
'iter_by_dt',
'load_pps_from_ledger',
'mk_allocator',
'open_pps',
'open_trade_ledger',
'unpack_fqme',
]


def get_likely_pair(
src: str,
dst: str,
bs_mktid: str,

) -> str | None:
'''
Attempt to get the likely trading pair matching a given destination
asset `dst: str`.

'''
try:
src_name_start = bs_mktid.rindex(src)
except (
ValueError, # substr not found
):
# TODO: handle nested positions..(i.e.
# positions where the src fiat was used to
# buy some other dst which was furhter used
# to buy another dst..)
# log.warning(
# f'No src fiat {src} found in {bs_mktid}?'
# )
return

likely_dst = bs_mktid[:src_name_start]
if likely_dst == dst:
return bs_mktid


if __name__ == '__main__':
import sys
from pprint import pformat

args = sys.argv
assert len(args) > 1, 'Specifiy account(s) from `brokers.toml`'
args = args[1:]
for acctid in args:
broker, name = acctid.split('.')
trans, updated_pps = load_pps_from_ledger(broker, name)
print(
f'Processing transactions into pps for {broker}:{acctid}\n'
f'{pformat(trans)}\n\n'
f'{pformat(updated_pps)}'
)
60 changes: 35 additions & 25 deletions piker/clearing/_allocate.py → piker/accounting/_allocate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

from bidict import bidict

from ..data._source import Symbol
from ._pos import Position
from . import MktPair
from ..data.types import Struct
from ..pp import Position


_size_units = bidict({
Expand All @@ -42,7 +42,7 @@

class Allocator(Struct):

symbol: Symbol
mkt: MktPair

# TODO: if we ever want ot support non-uniform entry-slot-proportion
# "sizes"
Expand Down Expand Up @@ -114,8 +114,8 @@ def next_order_info(
depending on position / order entry config.

'''
sym = self.symbol
ld = sym.lot_size_digits
mkt: MktPair = self.mkt
ld: int = mkt.size_tick_digits

size_unit = self.size_unit
live_size = live_pp.size
Expand All @@ -125,13 +125,13 @@ def next_order_info(
u_per_slot, currency_per_slot = self.step_sizes()

if size_unit == 'units':
slot_size = u_per_slot
l_sub_pp = self.units_limit - abs_live_size
slot_size: float = u_per_slot
l_sub_pp: float = self.units_limit - abs_live_size

elif size_unit == 'currency':
live_cost_basis = abs_live_size * live_pp.ppu
slot_size = currency_per_slot / price
l_sub_pp = (self.currency_limit - live_cost_basis) / price
live_cost_basis: float = abs_live_size * live_pp.ppu
slot_size: float = currency_per_slot / price
l_sub_pp: float = (self.currency_limit - live_cost_basis) / price

else:
raise ValueError(
Expand All @@ -141,8 +141,14 @@ def next_order_info(
# an entry (adding-to or starting a pp)
if (
live_size == 0
or (action == 'buy' and live_size > 0)
or action == 'sell' and live_size < 0
or (
action == 'buy'
and live_size > 0
)
or (
action == 'sell'
and live_size < 0
)
):
order_size = min(
slot_size,
Expand Down Expand Up @@ -178,7 +184,7 @@ def next_order_info(
order_size = max(slotted_pp, slot_size)

if (
abs_live_size < slot_size or
abs_live_size < slot_size

# NOTE: front/back "loading" heurstic:
# if the remaining pp is in between 0-1.5x a slot's
Expand All @@ -187,14 +193,17 @@ def next_order_info(
# **without** going past a net-zero pp. if the pp is
# > 1.5x a slot size, then front load: exit a slot's and
# expect net-zero to be acquired on the final exit.
slot_size < pp_size < round((1.5*slot_size), ndigits=ld) or

# underlying requires discrete (int) units (eg. stocks)
# and thus our slot size (based on our limit) would
# exit a fractional unit's worth so, presuming we aren't
# supporting a fractional-units-style broker, we need
# exit the final unit.
ld == 0 and abs_live_size == 1
or slot_size < pp_size < round((1.5*slot_size), ndigits=ld)
or (

# underlying requires discrete (int) units (eg. stocks)
# and thus our slot size (based on our limit) would
# exit a fractional unit's worth so, presuming we aren't
# supporting a fractional-units-style broker, we need
# exit the final unit.
ld == 0
and abs_live_size == 1
)
):
order_size = abs_live_size

Expand All @@ -203,13 +212,14 @@ def next_order_info(
# compute a fractional slots size to display
slots_used = self.slots_used(
Position(
symbol=sym,
mkt=mkt,
size=order_size,
ppu=price,
bsuid=sym,
bs_mktid=mkt.bs_mktid,
)
)

# TODO: render an actual ``Executable`` type here?
return {
'size': abs(round(order_size, ndigits=ld)),
'size_digits': ld,
Expand Down Expand Up @@ -249,7 +259,7 @@ def slots_used(

def mk_allocator(

symbol: Symbol,
mkt: MktPair,
startup_pp: Position,

# default allocation settings
Expand All @@ -276,6 +286,6 @@ def mk_allocator(
defaults.update(user_def)

return Allocator(
symbol=symbol,
mkt=mkt,
**defaults,
)
Loading