ExchangeUniverse#
API documentation for tradingstrategy.exchange.ExchangeUniverse Python class in Trading Strategy framework.
- class ExchangeUniverse[source]#
Bases:
objectExchange manager.
Contains look up for exchanges by their internal primary key ids.
Methods
__init__(exchanges)add(exchanges)Add more exchanges to the universe.
from_collection(exchanges)Create exchange universe from a collection of exchanges.
from_dict(kvs, *[, infer_missing])from_json(s, *[, parse_float, parse_int, ...])from_json_fast(data)Deserialise exchange universe from JSON without dataclasses_json reflection.
Get all exchange slugs.
get_by_chain_and_factory(chain_id, ...)Get the exchange implementation on a specific chain.
get_by_chain_and_name(chain_id, name)Get the exchange implementation on a specific chain.
get_by_chain_and_slug(chain_id, slug)Get the exchange implementation on a specific chain.
get_by_id(id)get_exchange_count()Get the one and the only exchange in this universe.
Get top exchanges sorted by their 30d volume.
limit_to_chains(chain_ids)Remove all but named exchanges from the set.
limit_to_slugs(slugs)Remove all but named exchanges from the
schema(*[, infer_missing, only, exclude, ...])to_dict([encode_json])to_json(*[, skipkeys, ensure_ascii, ...])Attributes
Exchange id -> Exchange data mapping.
- exchanges: Dict[int, Exchange]#
Exchange id -> Exchange data mapping. In the JSON payload, keys are stringified integers (e.g.
"1").
- classmethod from_json_fast(data)[source]#
Deserialise exchange universe from JSON without dataclasses_json reflection.
Uses
orjsonfor JSON parsing and direct dict-to-object construction, bypassing the per-field type introspection that makesfrom_json()slow for large exchange sets (~17k exchanges).- Parameters:
- Return type:
- static from_collection(exchanges)[source]#
Create exchange universe from a collection of exchanges.
- Parameters:
exchanges (Collection[Exchange]) –
- Return type:
- get_top_exchanges_by_30d_volume()[source]#
Get top exchanges sorted by their 30d volume.
Note that we consider volume only for supported quote tokens. See
tradingstrategy.exchange.Exchangefor more details.
- get_by_chain_and_factory(chain_id, factory_address)[source]#
Get the exchange implementation on a specific chain.
- get_single()[source]#
Get the one and the only exchange in this universe.
- Returns:
The exchange
- Raises:
AssertionError – in the case the universe does not contain a single exchange
- Return type:
- limit_to_chains(chain_ids)[source]#
Remove all but named exchanges from the set.
- Parameters:
chain_ids (set[tradingstrategy.chain.ChainId]) –
- Return type:
- add(exchanges)[source]#
Add more exchanges to the universe.
Mostly done to support vault faux data
- Parameters:
exchanges (list[tradingstrategy.exchange.Exchange]) –