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