Skip to content

Commit

Permalink
kraken: switch to rapidfuzz API
Browse files Browse the repository at this point in the history
  • Loading branch information
goodboy committed Sep 21, 2023
1 parent 46d83e9 commit a97a0ce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
19 changes: 13 additions & 6 deletions piker/brokers/kraken/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
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,
Expand Down Expand Up @@ -548,13 +551,17 @@ async def search_symbols(
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,
Expand Down
13 changes: 2 additions & 11 deletions piker/brokers/kraken/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a97a0ce

Please sign in to comment.