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)#
Methods
__init__
(base, quote, pool_address, ...[, ...])from_dict
(kvs, *[, infer_missing])from_json
(s, *[, parse_float, parse_int, ...])Same as get_ticker().
We use the smart contract pool address to uniquely identify trading positions.
Return base token symbol - quote token symbol human readable ticket.
Check if the pair has good information.
Has Uniswap smart contract a flipped token order.
schema
(*[, infer_missing, only, exclude, ...])to_dict
([encode_json])to_json
(*[, skipkeys, ensure_ascii, ...])Attributes
Base token in this trading pair
Quote token in this trading pair
Smart contract address of the pool contract.
Exchange address.
How this asset is referred in the internal database
What is the internal exchange id of this trading pair.
Info page URL for this trading pair e.g.
Trading fee for this pair.
The underlying token0/token1 for Uniswap pair is flipped compared to base token/quote token.
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.
- 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:
- get_ticker()[source]#
Return base token symbol - quote token symbol human readable ticket.
Example: WETH-USDC.
- Return type:
- 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:
- __init__(base, quote, pool_address, exchange_address, internal_id=None, internal_exchange_id=None, info_url=None, fee=None, reverse_token_order=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: