Enforce lower case symbols across providers

symbol_search
Tyler Goodlet 2021-05-10 10:17:06 -04:00
parent 478b114708
commit 5766dd518d
2 changed files with 23 additions and 12 deletions

View File

@ -379,13 +379,25 @@ class Feed:
@asynccontextmanager @asynccontextmanager
async def open_symbol_search(self) -> AsyncIterator[dict]: async def open_symbol_search(self) -> AsyncIterator[dict]:
open_search = getattr(self.mod, 'open_symbol_search', None)
if open_search is None:
# just return a pure pass through searcher
async def passthru(text: str) -> Dict[str, Any]:
return text
self.search = passthru
yield self.search
self.search = None
return
async with self._brokerd_portal.open_context( async with self._brokerd_portal.open_context(
open_search,
self.mod.open_symbol_search,
) as (ctx, cache): ) as (ctx, cache):
async with ctx.open_stream() as stream: # shield here since we expect the search rpc to be
# cancellable by the user as they see fit.
async with ctx.open_stream(shield=True) as stream:
async def search(text: str) -> Dict[str, Any]: async def search(text: str) -> Dict[str, Any]:
await stream.send(text) await stream.send(text)
@ -448,7 +460,7 @@ async def open_feed(
""" """
global _cache, _cache_lock global _cache, _cache_lock
sym = symbols[0] sym = symbols[0].lower()
# TODO: feed cache locking, right now this is causing # TODO: feed cache locking, right now this is causing
# issues when reconncting to a long running emsd? # issues when reconncting to a long running emsd?
@ -526,11 +538,6 @@ async def open_feed(
_cache[(brokername, sym)] = feed _cache[(brokername, sym)] = feed
try: async with feed.open_symbol_search():
async with feed.open_symbol_search(): yield feed
yield feed
finally:
# always cancel the far end producer task
with trio.CancelScope(shield=True):
await stream.aclose()

View File

@ -94,6 +94,7 @@ class ChartSpace(QtGui.QWidget):
# self.init_strategy_ui() # self.init_strategy_ui()
self.vbox.addLayout(self.toolbar_layout) self.vbox.addLayout(self.toolbar_layout)
self.vbox.addLayout(self.hbox) self.vbox.addLayout(self.hbox)
self._chart_cache = {} self._chart_cache = {}
self.linkedcharts: 'LinkedSplitCharts' = None self.linkedcharts: 'LinkedSplitCharts' = None
self.symbol_label: Optional[QtGui.QLabel] = None self.symbol_label: Optional[QtGui.QLabel] = None
@ -135,6 +136,9 @@ class ChartSpace(QtGui.QWidget):
Expects a ``numpy`` structured array containing all the ohlcv fields. Expects a ``numpy`` structured array containing all the ohlcv fields.
""" """
# our symbol key style is always lower case
symbol_key = symbol_key.lower()
linkedcharts = self._chart_cache.get(symbol_key) linkedcharts = self._chart_cache.get(symbol_key)
if not self.vbox.isEmpty(): if not self.vbox.isEmpty():