kraken: switch to `rapidfuzz` API
parent
46d83e9ca9
commit
a97a0ced8c
|
@ -38,7 +38,10 @@ import base64
|
|||
import trio
|
||||
|
||||
from piker import config
|
||||
from piker.data import def_iohlcv_fields
|
||||
from piker.data import (
|
||||
def_iohlcv_fields,
|
||||
match_from_pairs,
|
||||
)
|
||||
from piker.accounting._mktinfo import (
|
||||
Asset,
|
||||
digits_to_dec,
|
||||
|
@ -548,13 +551,17 @@ class Client:
|
|||
await self.get_mkt_pairs()
|
||||
assert self._pairs, '`Client.get_mkt_pairs()` was never called!?'
|
||||
|
||||
matches = fuzzy.extractBests(
|
||||
pattern,
|
||||
self._pairs,
|
||||
matches: dict[str, Pair] = match_from_pairs(
|
||||
pairs=self._pairs,
|
||||
query=pattern.upper(),
|
||||
score_cutoff=50,
|
||||
)
|
||||
# repack in dict form
|
||||
return {item[0].altname: item[0] for item in matches}
|
||||
|
||||
# repack in .altname-keyed output table
|
||||
return {
|
||||
pair.altname: pair
|
||||
for pair in matches.values()
|
||||
}
|
||||
|
||||
async def bars(
|
||||
self,
|
||||
|
|
|
@ -136,19 +136,10 @@ async def open_symbol_search(ctx: tractor.Context) -> None:
|
|||
await ctx.started(cache)
|
||||
|
||||
async with ctx.open_stream() as stream:
|
||||
|
||||
async for pattern in stream:
|
||||
|
||||
matches = fuzzy.extractBests(
|
||||
pattern,
|
||||
client._pairs,
|
||||
score_cutoff=50,
|
||||
await stream.send(
|
||||
await client.search_symbols(pattern)
|
||||
)
|
||||
# repack in dict form
|
||||
await stream.send({
|
||||
pair[0].altname: pair[0]
|
||||
for pair in matches
|
||||
})
|
||||
|
||||
|
||||
@async_lifo_cache()
|
||||
|
|
Loading…
Reference in New Issue