pikers / piker

(e2e) foss trading for non-tinas
GNU Affero General Public License v3.0
102 stars 17 forks source link

Paper trade improvements #462

Closed algorandpa closed 1 year ago

algorandpa commented 1 year ago

Test suite todo:


Future dark-order and alert storage todo test suite (maybe to do in a follow up PR):

~submit an order that does not clear, stop and start pikerd, ensure order is re-registered in emsd~ => deferred to #463 ~will likely requires Order serialization to file system and load~ => deferred to #464

goodboy commented 1 year ago

@algorandpa while i'm testing and reviewing this you might as well make your follow issue(s) for that last bullet and whatever else 🏄🏼

algorandpa commented 1 year ago

Issue created for second task here @goodboy

goodboy commented 1 year ago

Oh and for the trailing white space issue you seem to have; try out this vim config snippet:

set list listchars=tab:\ \ ,extends:$,precedes:^,trail:-
goodboy commented 1 year ago

When this lands I believe we'll be completing the bullet from the paper engine support section in https://github.com/pikers/piker/issues/345 🥳

At the time when we merge this PR you can check off that bullet and put a sub-bullet linking to this I'd say.

goodboy commented 1 year ago

Ok as per discussion on matrix, I found a couple issues:

screenshot-2023-02-21_12-24-43

Updating pps.toml for <module 'posixpath' from '/usr/lib/python3.10/posixpath.py'>:

Feb 21 12:40:17 (paperboi.binance[be4a8e], 6026, piker.clearing._paper_engine.handle_order_requests)) [INFO] piker.clearing._paper_engine _paper_engine.py:507 Submitted paper LIMIT 8cec6566-4de0-4d3a-9a27-35aae5f515fe: BrokerdOrder(oid='a45a7742-108b-46e5-82b8-9689ca474b4e', account='paper', time_ns=1677001217069566678, symbol='btcusdt', price=24455.41, size=0.04093, action='buy', reqid=None) Feb 21 12:40:17 (emsd[3acd02], 6021, piker.clearing._ems.translate_and_relay_brokerd_events)) [INFO] piker.clearing._ems _ems.py:694 Received broker trade event: {'account': 'paper', 'avg_price': 24450.87, 'broker': 'binance', 'currency': '', 'name': 'position', 'size': 0.04093, 'symbol': 'btcusdt.binance'}

goodboy commented 1 year ago

Lol, sorry hit the wrong button on that last comment 😂

Ok I found the issue for the second bullet above I'm going to comment on the code backlinking to that comment.

goodboy commented 1 year ago

Tested, and reviewed code, I have some minor comments but I will address them in a PR of my own, decimalization_take_2 branch.

I presume you want to make that vs. master once this lands yah?

goodboy commented 1 year ago

Ok so did some manual testing and everything is working minus what's expected not to, which i'm going to state below and feel free to correct:


Remaining ToDo for this to land:

again excellent work getting this test harness started @algorandpa

goodboy commented 1 year ago

Huh, so interesting..

I ref to #470 i am seeing that the rounding/precision issues only seem to be in the .pp.PpTable stuff since the order mode UI does indeed wipe on zeroing after closing out the pos over multiple pikerd sessions.

screenshot-2023-02-28_13-40-02

goodboy commented 1 year ago

Though i'm sure @guilledk is totally aware of the details, just putting this for myself and the knowledge of others as per the fix landing in #470.

Turns out the msging layer seems to be completely fine in terms of zeroing pps despite using floats throughout sizing arithmetic; the issue seems to be purely in our .pp.PpTable size storage and arithmetic sub-sys.

As an example here i was able to get the precision error to linger in the pps.toml but in the UI and at the msging layer there was a zeroed pp every time i started a new session and the accum_size = 2.7755575615628914e-17 was present in the clearing table:

[binance.paper."btcusdt.binance"]
size = 2.7755575615628914e-17
ppu = 23489.324999999997
bsuid = "btcusdt"
clears = [
 { dt = "2023-02-28T18:36:42.360930+00:00", ppu = 23455.5, accum_size = -0.04264, price = 23455.5, size = -0.04264, cost = 0, tid = "34323ca0-277b-4f9f-b77e-1ef4718c49c5" },
 { dt = "2023-02-28T18:36:44.500479+00:00", ppu = 23456.435, accum_size = -0.08528, price = 23457.37, size = -0.04264, cost = 0, tid = "9996508c-b94b-489f-910f-c9360c9ce031" },
 { dt = "2023-02-28T18:36:46.400183+00:00", ppu = 23456.00666666667, accum_size = -0.12791999999999998, price = 23455.15, size = -0.04264, cost = 0, tid = "15dfe435-d54b-450d-b1ec-21db6e535c17" },
 { dt = "2023-02-28T18:38:37.989248+00:00", ppu = 23462.75, accum_size = 2.7755575615628914e-17, price = 23462.75, size = 0.12792, cost = 0, tid = "138dcf2b-5ab9-43b3-bb45-0465da730ac9" },
 { dt = "2023-02-28T18:44:02.788944+00:00", ppu = 23480.89, accum_size = 0.04258000000000003, price = 23480.89, size = 0.04258, cost = 0, tid = "e098b4d2-72b2-41a9-b1f4-e74f6c457c56" },
 { dt = "2023-02-28T18:44:11.890799+00:00", ppu = 23480.89, accum_size = 2.7755575615628914e-17, price = 23482.39, size = -0.04258, cost = 0, tid = "672167d1-ee78-4e54-91a6-7fc63f96349f" },
 { dt = "2023-02-28T18:44:41.429072+00:00", ppu = 23491.16, accum_size = 0.042570000000000024, price = 23491.16, size = 0.04257, cost = 0, tid = "df3eeead-e6ad-477a-9720-c5143ace03cf" },
 { dt = "2023-02-28T18:44:44.812730+00:00", ppu = 23489.324999999997, accum_size = 0.08514000000000002, price = 23487.49, size = 0.04257, cost = 0, tid = "30f471e6-e1c0-484b-91cd-cd9c9aec8804" },
 { dt = "2023-02-28T18:44:48.019707+00:00", ppu = 23489.324999999997, accum_size = 0.042570000000000024, price = 23488.71, size = -0.04257, cost = 0, tid = "6f6f2a34-3fe0-436b-9896-4874172cbfc2" },
 { dt = "2023-02-28T18:45:31.141610+00:00", ppu = 23489.324999999997, accum_size = 2.7755575615628914e-17, price = 23480.55, size = -0.04257, cost = 0, tid = "46440830-caed-4b76-b6b3-0ac27fa7b054" },
]