TradingPairIdentifier#

tradeexecutor.state.identifier.TradingPairIdentifier Python class in Trading Strategy framework.

class TradingPairIdentifier[source]#

Bases: object

Uniquely identify one trading pair across all tradeable blockchain assets.

  • Tokens are converted from machine readable token0 - token1 pair to more human-friendly base and quote token pair. See conversion.

  • This class is a data class that is a copy-by-value in the persistent state: We copy both machine-readable information (smart contract addresses) and human readable information (symbols), as both are important to store for the persistent use - we do not expect to be able to lookup the information again with smart contract addresses in the future, as API access is expensive and blockchains may permanently be abandon.

  • This class is preferred to be used as immutable, but sometimes it is handy to manually override :py:attr`fee` for different backtesting scenarios

__init__(base, quote, pool_address, exchange_address, internal_id=None, internal_exchange_id=None, info_url=None, fee=None, reverse_token_order=None)#
Parameters:
Return type:

None

Methods

__init__(base, quote, pool_address, ...[, ...])

from_dict(kvs, *[, infer_missing])

from_json(s, *[, parse_float, parse_int, ...])

get_human_description()

Same as get_ticker().

get_identifier()

We use the smart contract pool address to uniquely identify trading positions.

get_ticker()

Return base token symbol - quote token symbol human readable ticket.

has_complete_info()

Check if the pair has good information.

has_reverse_token_order()

Has Uniswap smart contract a flipped token order.

schema(*[, infer_missing, only, exclude, ...])

to_dict([encode_json])

to_json(*[, skipkeys, ensure_ascii, ...])

Attributes

base

Base token in this trading pair

quote

Quote token in this trading pair

pool_address

Smart contract address of the pool contract.

exchange_address

Exchange address.

internal_id

How this asset is referred in the internal database

internal_exchange_id

What is the internal exchange id of this trading pair.

info_url

Info page URL for this trading pair e.g.

fee

Trading fee for this pair.

reverse_token_order

The underlying token0/token1 for Uniswap pair is flipped compared to base token/quote token.

chain_id

Return raw chain id.

base: AssetIdentifier#

Base token in this trading pair

E.g. WETH

quote: AssetIdentifier#

Quote token in this trading pair

E.g. USDC

pool_address: str#

Smart contract address of the pool contract.

  • Uniswap v2 pair contract address

  • Uniswap v3 pool contract address

exchange_address: str#

Exchange address. Identifies a decentralised exchange. Uniswap v2 likes are identified by their factor address.

internal_id: Optional[int]#

How this asset is referred in the internal database

Internal ids are not stable over the long duration. Internal ids are not also stable across different oracles. Always use (chain_id, pool_address) pair for persistent lookups.

internal_exchange_id: Optional[int]#

What is the internal exchange id of this trading pair.

info_url: Optional[str]#

Info page URL for this trading pair e.g. with the price charts

fee: Optional[float]#

Trading fee for this pair.

Liquidity provider fee expressed as the percent of the trade.

E.g. 0.0030 for 0.30% fee.

Should be filled for all Uniswap v2 and Uniswap v3 pairs. If the smaller Uni v2 forks do not have good data, 0.0030% is assumed.

reverse_token_order: Optional[bool]#

The underlying token0/token1 for Uniswap pair is flipped compared to base token/quote token.

Use has_reverse_token_order() to access - might not be set.

property chain_id: int#

Return raw chain id.

Get one from the base token, beacuse both tokens are on the same chain.

See also tradingstrategy.chain.ChainId

get_identifier()[source]#

We use the smart contract pool address to uniquely identify trading positions.

Ethereum address is lowercased, not checksummed.

Return type:

str

get_ticker()[source]#

Return base token symbol - quote token symbol human readable ticket.

Example: WETH-USDC.

Return type:

str

get_human_description()[source]#

Same as get_ticker().

Return type:

str

has_complete_info()[source]#

Check if the pair has good information.

Because of the open-ended nature a lot of irrelevant broken data can be found on blockchains.

Both base and quote token must have

  • Symbol

  • Decimals

This check is mainly useful to filter out crap tokens from the trading decisions.

Return type:

bool

__init__(base, quote, pool_address, exchange_address, internal_id=None, internal_exchange_id=None, info_url=None, fee=None, reverse_token_order=None)#
Parameters:
Return type:

None

has_reverse_token_order()[source]#

Has Uniswap smart contract a flipped token order.

  • Is token0 base token or token0 is the quote token

See eth_defi.uniswap_v3.price.get_onchain_price()

Return type:

bool