Get kivy/questrade shit working again

basic_orders
Tyler Goodlet 2021-02-21 12:32:40 -05:00
parent f724798336
commit e6ea053d40
4 changed files with 25 additions and 14 deletions

View File

@ -1,5 +1,5 @@
# piker: trading gear for hackers # 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 # 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 # it under the terms of the GNU Affero General Public License as published by
@ -16,7 +16,9 @@
""" """
Actor-aware broker agnostic interface. Actor-aware broker agnostic interface.
""" """
from typing import Dict
from contextlib import asynccontextmanager, AsyncExitStack from contextlib import asynccontextmanager, AsyncExitStack
import trio import trio
@ -28,7 +30,7 @@ from ..log import get_logger
log = get_logger(__name__) log = get_logger(__name__)
_clients: Dict[str, 'Client'] = {} _cache: Dict[str, 'Client'] = {}
@asynccontextmanager @asynccontextmanager
async def get_cached_client( 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. 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'] lock = clients['_lock']
client = None client = None

View File

@ -180,15 +180,18 @@ async def symbol_data(broker: str, tickers: List[str]):
return await feed.client.symbol_info(tickers) return await feed.client.symbol_info(tickers)
_feeds_cache = {}
@asynccontextmanager @asynccontextmanager
async def get_cached_feed( async def get_cached_feed(
brokername: str, brokername: str,
) -> BrokerFeed: ) -> BrokerFeed:
"""Get/create a ``BrokerFeed`` from/in the current actor. """Get/create a ``BrokerFeed`` from/in the current actor.
""" """
# check if a cached client is in the local actor's statespace global _feeds_cache
ss = tractor.current_actor().statespace
feeds = ss.setdefault('feeds', {'_lock': trio.Lock()}) # check if a cached feed is in the local actor
feeds = _feeds_cache.setdefault('feeds', {'_lock': trio.Lock()})
lock = feeds['_lock'] lock = feeds['_lock']
feed = None feed = None
try: try:

View File

@ -1,5 +1,5 @@
# piker: trading gear for hackers # 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 # 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 # it under the terms of the GNU Affero General Public License as published by

View File

@ -144,14 +144,17 @@ async def update_quotes(
log.warn("Data feed connection dropped") log.warn("Data feed connection dropped")
_widgets = {}
async def stream_symbol_selection(): async def stream_symbol_selection():
"""An RPC async gen for streaming the symbol corresponding """An RPC async gen for streaming the symbol corresponding
value corresponding to the last clicked row. value corresponding to the last clicked row.
Essentially of an event stream of clicked symbol values. Essentially of an event stream of clicked symbol values.
""" """
widgets = tractor.current_actor().statespace['widgets'] global _widgets
table = widgets['table'] table = _widgets['table']
send_chan, recv_chan = trio.open_memory_channel(0) send_chan, recv_chan = trio.open_memory_channel(0)
table._click_queues.append(send_chan) table._click_queues.append(send_chan)
try: try:
@ -238,8 +241,6 @@ async def _async_main(
# set up a pager view for large ticker lists # set up a pager view for large ticker lists
table.bind(minimum_height=table.setter('height')) table.bind(minimum_height=table.setter('height'))
ss = tractor.current_actor().statespace
async def spawn_opts_chain(): async def spawn_opts_chain():
"""Spawn an options chain UI in a new subactor. """Spawn an options chain UI in a new subactor.
""" """
@ -276,7 +277,10 @@ async def _async_main(
'header': header, 'header': header,
'pager': pager, 'pager': pager,
} }
ss['widgets'] = widgets
global _widgets
_widgets = widgets
nursery.start_soon( nursery.start_soon(
update_quotes, update_quotes,
nursery, nursery,