From e6ea053d40aeb7bb5edfd3fa9de8c448964d3d8d Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Sun, 21 Feb 2021 12:32:40 -0500 Subject: [PATCH] Get kivy/questrade shit working again --- piker/brokers/api.py | 12 ++++++++---- piker/brokers/data.py | 9 ++++++--- piker/data/marketstore.py | 2 +- piker/ui/kivy/monitor.py | 16 ++++++++++------ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/piker/brokers/api.py b/piker/brokers/api.py index f54a0e86..75fc8a14 100644 --- a/piker/brokers/api.py +++ b/piker/brokers/api.py @@ -1,5 +1,5 @@ # piker: trading gear for hackers -# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0) +# Copyright (C) Tyler Goodlet (in stewardship for piker0) # 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 @@ -16,7 +16,9 @@ """ Actor-aware broker agnostic interface. + """ +from typing import Dict from contextlib import asynccontextmanager, AsyncExitStack import trio @@ -28,7 +30,7 @@ from ..log import get_logger log = get_logger(__name__) -_clients: Dict[str, 'Client'] = {} +_cache: Dict[str, 'Client'] = {} @asynccontextmanager async def get_cached_client( @@ -40,9 +42,11 @@ async def get_cached_client( If one has not been setup do it and cache it. """ - global _clients + global _cache - clients = ss.setdefault('clients', {'_lock': trio.Lock()}) + clients = _cache.setdefault('clients', {'_lock': trio.Lock()}) + + # global cache task lock lock = clients['_lock'] client = None diff --git a/piker/brokers/data.py b/piker/brokers/data.py index cdf056b4..82e08507 100644 --- a/piker/brokers/data.py +++ b/piker/brokers/data.py @@ -180,15 +180,18 @@ async def symbol_data(broker: str, tickers: List[str]): return await feed.client.symbol_info(tickers) +_feeds_cache = {} + @asynccontextmanager async def get_cached_feed( brokername: str, ) -> BrokerFeed: """Get/create a ``BrokerFeed`` from/in the current actor. """ - # check if a cached client is in the local actor's statespace - ss = tractor.current_actor().statespace - feeds = ss.setdefault('feeds', {'_lock': trio.Lock()}) + global _feeds_cache + + # check if a cached feed is in the local actor + feeds = _feeds_cache.setdefault('feeds', {'_lock': trio.Lock()}) lock = feeds['_lock'] feed = None try: diff --git a/piker/data/marketstore.py b/piker/data/marketstore.py index d8cb3930..27bcda70 100644 --- a/piker/data/marketstore.py +++ b/piker/data/marketstore.py @@ -1,5 +1,5 @@ # piker: trading gear for hackers -# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0) +# Copyright (C) Tyler Goodlet (in stewardship for piker0) # 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 diff --git a/piker/ui/kivy/monitor.py b/piker/ui/kivy/monitor.py index 47e52605..6c0a7736 100644 --- a/piker/ui/kivy/monitor.py +++ b/piker/ui/kivy/monitor.py @@ -62,7 +62,7 @@ async def update_quotes( color = colorcode('gray') # if the cell has been "highlighted" make sure to change its color - if hdrcell.background_color != [0]*4: + if hdrcell.background_color != [0] * 4: hdrcell.background_color = color # update row header and '%' cell text color @@ -144,14 +144,17 @@ async def update_quotes( log.warn("Data feed connection dropped") +_widgets = {} + + async def stream_symbol_selection(): """An RPC async gen for streaming the symbol corresponding value corresponding to the last clicked row. Essentially of an event stream of clicked symbol values. """ - widgets = tractor.current_actor().statespace['widgets'] - table = widgets['table'] + global _widgets + table = _widgets['table'] send_chan, recv_chan = trio.open_memory_channel(0) table._click_queues.append(send_chan) try: @@ -238,8 +241,6 @@ async def _async_main( # set up a pager view for large ticker lists table.bind(minimum_height=table.setter('height')) - ss = tractor.current_actor().statespace - async def spawn_opts_chain(): """Spawn an options chain UI in a new subactor. """ @@ -276,7 +277,10 @@ async def _async_main( 'header': header, 'pager': pager, } - ss['widgets'] = widgets + + global _widgets + _widgets = widgets + nursery.start_soon( update_quotes, nursery,