-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fixed float dust bug on zero position #470
Conversation
piker/clearing/_paper_engine.py
Outdated
@@ -530,7 +535,7 @@ async def trades_dialogue( | |||
|
|||
): | |||
|
|||
with open_pps(broker, 'paper', False) as table: | |||
with open_pps(broker, 'paper') as table: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not quite following why you're not writing immediately here any more?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure that open_pps
call is just meant to load the pps.toml
file into the _positions
module var and then iterate on it to send position messages to the ems.
9e2ac6d
to
1323981
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abc2d45
to
3b4f123
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than the first comment
I'm just gonna manually test with the same scenario I got in #462, presuming it's resolved I'll merge 🏄🏼 |
327aa5c
to
501fe9a
Compare
@guilledk another thing I think should change is to just put the when are we ever going to need to have a separate section?
ad discussed in chat i think we can just stick all the symbol info fields directly in the pp entry since they're one to one: [binance.paper."btcusdt.binance"]
size = 0.04235
ppu = 23611.15
bsuid = "btcusdt"
asset_type = "crypto"
price_tick_size = 0.01
lot_tick_size = 1e-5
clears = [
{ dt = "2023-03-01T23:37:51.559601+00:00", ppu = 23611.15, accum_size = 0.04235, price = 23611.15, size = 0.04235, cost = 0, tid = "0c162a01-9e63-4121-9475-182cf80753e8" },
] |
piker/pp.py
Outdated
@@ -957,7 +981,8 @@ def open_pps( | |||
expiry = pendulum.parse(expiry) | |||
|
|||
pp = pp_objs[bsuid] = Position( | |||
Symbol.from_fqsn(fqsn, info={}), | |||
Symbol.from_fqsn( | |||
fqsn, entry['symbol']), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in chat, we need to do a entry.get('symbol')
here and instead just fill in a default Symbol
here to continue supporting old pps.toml
files.
Further for entries detected as crypto
we should probably put a big warning that the entry needs to be recalculated to avoid the precision error this patch was originally meant to fix!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added in the bit about backward compat for existing pps.toml
files (since this definitely breaks for me 😂
I'm more then happy to make a patch to this PR before landing 🏄🏼
Add decimal quantize API to Symbol to simplify by-broker truncation Add symbol info to `pps.toml` Move _assert call to outside the _async_main context manager Minor indentation and styling changes, also convert a few prints to log calls Fix multi write / race condition on open_pps call Switch open_pps to not write by default Fix integer math kraken syminfo _tick_size initialization
…ps.toml causing it to load pp wrong on second open, also fix header leak bug
501fe9a
to
6be96a9
Compare
In order to support existing `pps.toml` files in the wild which don't have the `asset_type, price_tick_size, lot_tick_size` fields, we need to only optionally read them and instead expect that backends will write the fields going forward (coming in follow patches). Further this makes some small asset-size (vlm accounting) quantization related adjustments: - rename `Symbol.decimal_quant()` -> `.quantize_size()` since that is explicitly what this method is doing. - and expect an input `size: float` which we cast to decimal instead of doing it inside the `.calc_size()` caller code. - drop `Symbol.iterfqsns()` which wasn't being used anywhere at all.. Additionally, this drafts out a new replacement market-trading-pair data type to eventually replace `.data._source.Symbol` -> `MktPair` which we aren't using yet, but serves as the documentation-driven motivator ;) and, it relates to #467.
Also includes a retyping of `Client._pair: dict[str, Pair]` to look up pair structs and map all alt-key-name-sets to each for easy precision info lookup to set the `.sym` field for each transaction including for on-chain transfers which kraken provides as an "asset decimals" field, presumably pulled from the particular block-token's limitation info.
…info Backward compat support for `Transaction.sym: Symbol`
With the merging of my sub-pr i think this is ready to land 🏄🏼 i saw one last msg that was interesting with a piker.clearing._ems _ems.py:694 Received broker trade event:
{'account': 'paper',
'avg_price': 22409.6,
'broker': 'binance',
'currency': 'btcusdt',
'name': 'position',
'size': -0.0,
'symbol': 'btcusdt.binance'} gonna do one more review pass. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure this is finally ready!
I guess we just need to make sure the tests are all good in CI 🚀
In #462 we discovered a bug on the positioning system when trying to get to a zero position state, after investigation we found out it was caused by float precision, the solution is to truncate based on the maximun supported on a symbol by symbol basis.