Get kivy/questrade shit working again
parent
f724798336
commit
e6ea053d40
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue