LegacyPairUniverse#

tradingstrategy.pair.LegacyPairUniverse Python class in Trading Strategy framework.

class LegacyPairUniverse[source]#

Bases: object

The queries universe, as returned by the server.

Note

TODO: Legacy prototype implementation and will be deprecated.

Converts raw pair dataset to easier to use DEXPair in-memory index.

You likely want to use PandasPairUniverse, as its offers much more functionality than this implemetation.

__init__(pairs)[source]#
Parameters:

pairs (Dict[int, DEXPair]) –

Methods

__init__(pairs)

create_from_pyarrow_table(table)

Convert columnar presentation to a Python in-memory objects.

create_from_pyarrow_table_with_filters(table)

Convert columnar presentation to a Python in-memory objects.

get_active_pairs()

Filter for pairs that have see a trade for the last 30 days

get_all_pairs_on_exchange(exchange_id)

Get all trading pair on a decentralsied exchange.

get_inactive_pairs()

Filter for pairs that have not see a trade for the last 30 days

get_pair_by_id(pair_id)

Resolve pair by its id.

get_pair_by_ticker(base_token, quote_token)

Get a trading pair by its ticker symbols.

get_pair_by_ticker_by_exchange(exchange_id, ...)

Get a trading pair by its ticker symbols.

Attributes

pairs

Internal id -> DEXPair mapping

__init__(pairs)[source]#
Parameters:

pairs (Dict[int, DEXPair]) –

pairs: Dict[int, DEXPair]#

Internal id -> DEXPair mapping

classmethod create_from_pyarrow_table(table)[source]#

Convert columnar presentation to a Python in-memory objects.

Some data manipulation is easier with objects instead of columns.

Note

This seems to quite slow operation. It is recommend you avoid this if you do not need row-like data.

Parameters:

table (Table) –

Return type:

LegacyPairUniverse

classmethod create_from_pyarrow_table_with_filters(table, chain_id_filter=None)[source]#

Convert columnar presentation to a Python in-memory objects.

Filter the pairs based on given filter arguments.

Parameters:
Return type:

LegacyPairUniverse

get_pair_by_id(pair_id)[source]#

Resolve pair by its id.

Only useful for debugging. Does a slow look

Parameters:

pair_id (int) –

Return type:

Optional[DEXPair]

get_pair_by_ticker(base_token, quote_token)[source]#

Get a trading pair by its ticker symbols.

Note that this method works only very simple universes, as any given pair is poised to have multiple tokens and multiple trading pairs on different exchanges.

Raises:
  • DuplicatePair – If the universe contains more than single entry for the pair.

  • PairNotFoundError – If the pair is not found.

Returns:

None if there is no match

Parameters:
  • base_token (str) –

  • quote_token (str) –

Return type:

Optional[DEXPair]

get_pair_by_ticker_by_exchange(exchange_id, base_token, quote_token)[source]#

Get a trading pair by its ticker symbols.

Note that this method works only very simple universes, as any given pair is poised to have multiple tokens and multiple trading pairs on different exchanges.

Parameters:
  • exchange_id (int) – E.g. 1 for uniswap_v2

  • base_token (str) –

  • quote_token (str) –

Raises:

DuplicatePair – If the universe contains more than single entry for the pair. Because we are looking by a token symbol there might be fake tokens with the same symbol.

Returns:

None if there is no match

Return type:

Optional[DEXPair]

get_all_pairs_on_exchange(exchange_id)[source]#

Get all trading pair on a decentralsied exchange.

Use ExchangeUniverse.get_by_chain_and_slug to resolve the exchange_id first. :param chain_id: E.g. ChainId.ethereum

Parameters:

exchange_id (int) – E.g. 1 for uniswap_v2

Raises:

DuplicatePair – If the universe contains more than single entry for the pair. Because we are looking by a token symbol there might be fake tokens with the same symbol.

Returns:

None if there is no match

Return type:

Iterable[DEXPair]

get_active_pairs()[source]#

Filter for pairs that have see a trade for the last 30 days

Return type:

Iterable[DEXPair]

get_inactive_pairs()[source]#

Filter for pairs that have not see a trade for the last 30 days

Return type:

Iterable[DEXPair]