From 69c9ecc5e3d504e7f3b9fe6c022f55c6e2b37df9 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Tue, 14 Mar 2023 20:55:37 -0400 Subject: [PATCH] `kraken`: write `pps.toml` on updates for now --- piker/brokers/kraken/broker.py | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/piker/brokers/kraken/broker.py b/piker/brokers/kraken/broker.py index 72d6f0fe..5509968a 100644 --- a/piker/brokers/kraken/broker.py +++ b/piker/brokers/kraken/broker.py @@ -50,6 +50,7 @@ from piker.accounting import ( ) from piker.accounting._mktinfo import ( Symbol, + MktPair, digits_to_dec, ) from piker.clearing._messages import ( @@ -370,6 +371,8 @@ def trades2pps( acctid: str, new_trans: dict[str, Transaction] = {}, + write_storage: bool = True, + ) -> tuple[ list[BrokerdPosition], list[Transaction], @@ -400,13 +403,20 @@ def trades2pps( # right since `.broker` is already # included? account='kraken.' + acctid, - symbol=p.symbol.front_fqsn(), + symbol=p.symbol.fqme, size=p.size, avg_price=p.ppu, currency='', ) position_msgs.append(msg) + if write_storage: + # TODO: ideally this blocks the this task + # as little as possible. we need to either do + # these writes in another actor, or try out `trio`'s + # async file IO api? + table.write_config() + return position_msgs @@ -639,6 +649,12 @@ async def trades_dialogue( ) await ctx.started((ppmsgs, [acc_name])) + # TODO: ideally this blocks the this task + # as little as possible. we need to either do + # these writes in another actor, or try out `trio`'s + # async file IO api? + table.write_config() + # Get websocket token for authenticated data stream # Assert that a token was actually received. resp = await client.endpoint('GetWebSocketsToken', {}) @@ -814,8 +830,6 @@ async def handle_order_updates( for pp_msg in ppmsgs: await ems_stream.send(pp_msg) - ledger_trans.update(new_trans) - # process and relay order state change events # https://docs.kraken.com/websockets/#message-openOrders case [ @@ -1184,9 +1198,21 @@ def norm_trade_records( }[record['type']] # we normalize to kraken's `altname` always.. - bsuid, pair_info = Client.normalize_symbol(record['pair']) + bsuid, pair_info = Client.normalize_symbol( + record['pair'] + ) fqsn = f'{bsuid}.kraken' + dst, src = pair_info.wsname.lower().split('/') + # mkpair = MktPair( + # src=src, + # dst=dst, + # price_tick=digits_to_dec(pair_info.pair_decimals), + # size_tick=digits_to_dec(pair_info.lot_decimals), + # dst_type='crypto_currency', + # ) + # breakpoint() + mktpair = Symbol.from_fqsn( fqsn, info={