dojo.observations
This module contains the observation objects emitted by the environments.
Base observation class for all environments.
Add a singal.
It will be logged and displayed in the dashboard.
Add the gas prices in a block to the internal fees datastructure.
Return the number of decimals of the token.
Parameters
- token: token symbol.
Contains observation logic for the Gmx agents and policies.
Initialize the observation.
Parameters
- backend: The backend to use.
Method to set prices from GMX environment.
Method to set market dict (market_key -> Market) from GMX environment.
Get the positions of a given account.
Parameters
- account: The account address to get positions for.
Returns
A list of Position objects representing the account's positions.
Calculate the price of the index token.
This method retrieves the market information and oracle prices for the index token, then calculates the average price using the minimum and maximum prices provided by the oracle. The price is scaled according to the token's decimals and the oracle precision.
Returns
The calculated price of the index token as a Decimal.
Calculate the price of the long token.
This method retrieves the market information and oracle prices for the long token, then calculates the average price using the minimum and maximum prices provided by the oracle. The price is scaled according to the token's decimals and the oracle precision.
Returns
The calculated price of the long token as a Decimal.
Calculate the price of the short token.
This method retrieves the market information and oracle prices for the short token, then calculates the average price using the minimum and maximum prices provided by the oracle. The price is scaled according to the token's decimals and the oracle precision.
Returns
The calculated price of the short token as a Decimal.
Retrieve a position based on the given position key.
This method interacts with the backend to call the getPosition
function
from the Reader
contract, using the provided position key. The data
retrieved is then used to create and return a Position
object.
Parameters
- position_key: The key identifying the position to retrieve.
Returns
A
Position
object representing the retrieved position.
Retrieve the market token price and market pool value info for traders.
Parameters
- maximize: A boolean indicating whether to maximize the price.
Returns
A tuple containing the calculated GM token value as a Decimal and a
MarketPoolValueInfo
object with detailed market pool value information.
Retrieve the market token price and market pool value info for deposits.
Parameters
- maximize: A boolean indicating whether to maximize the price.
Returns
A tuple containing the calculated GM token value as a Decimal and a
MarketPoolValueInfo
object with detailed market pool value information.
Retrieve the market token price and market pool value info for withdrawals.
Parameters
- maximize: A boolean indicating whether to maximize the price.
Returns
A tuple containing the calculated GM token value as a Decimal and a
MarketPoolValueInfo
object with detailed market pool value information.
Retrieve the position PnL in USD.
Parameters
- position: The position object containing details of the position.
Returns
A
PositionPnl
object containing the PnL details in USD.
Retrieve the net PnL.
Parameters
- maximize: A boolean indicating whether to maximize the PnL.
Returns
The net PnL as a Decimal.
Retrieve the PnL for a given position type.
Parameters
- is_long: A boolean indicating whether the position is long.
- maximize: A boolean indicating whether to maximize the PnL.
Returns
The PnL as a Decimal.
Retrieve the open interest with PnL.
Parameters
- is_long: A boolean indicating whether the position is long.
- maximize: A boolean indicating whether to maximize the PnL.
Returns
The open interest with PnL as a Decimal.
Contains observation logic for the UniswapV3 agents and policies.
Initialize the observation.
Parameters
- pools: list of pools to use in the environment.
- backend: The backend to use.
Get the addresses of the tokens in a pool.
Parameters
- pool: The pool name.
Get the symbols of the tokens in a pool.
Parameters
- pool: The pool name.
Get the tick spacing of a pool.
Parameters
- pool: The pool name.
Get the active tick range in a pool.
Parameters
- pool: The pool name.
Get the contents of the pool's slot0.
Ref https://docs.uniswap.org/contracts/v3/reference/core/interfaces/pool/IUniswapV3PoolState#slot0
Get the pool liquidity of the active range.
Ref https://docs.uniswap.org/contracts/v3/reference/core/interfaces/pool/IUniswapV3PoolState#liquidity
Returns a tuple of various tick info.
The return format is: int128 liquidityNet uint256 feeGrowthOutside0X128 uint256 feeGrowthOutside1X128 int56 tickCumulativeOutside uint160 secondsPerLiquidityOutsideX128 uint32 secondsOutside bool initialized
Ref https://docs.uniswap.org/contracts/v3/reference/core/interfaces/pool/IUniswapV3PoolState#ticks
noqa: E501
Get the pool position of an owner in the specified tick range.
Parameters
- pool: The pool name.
- owner: The owner address.
- tick_lower: The lower tick of the position.
- tick_upper: The upper tick of the position.
Returns
A dictionary containing the position data, with keys: -
token0
: The symbol of the token0 of the pool. -token1
: The symbol of the token1 of the pool. -pool
: The name of the pool. -owner
: The address of the owner. -tick_range
: The tick range of the LP position. -liquidity
: The liquidity of the position. -uncollected_fees
: The uncollected fees of the position. -uncollected_fees_adjusted
: The uncollected fees of the position adjusted by the token decimals.
Get LP position data of an LP NFT.
Parameters
- token_id: The token ID of the LP NFT.
Returns
A dictionary containing the LP position data, with keys: -
token0
: The symbol of the token0 of the pool. -token1
: The symbol of the token1 of the pool. -fee
: The fee of the pool. -pool
: The name of the pool. -tick_range
: The tick range of the LP position. -liquidity
: The liquidity of the LP position. -real_quantities
: The real token quantities of the LP position. -uncollected_fees
: The uncollected fees of the LP position.
Get the uncollected LP fees owed to an LP portfolio.
Parameters
- token_ids: The token IDs of the LP NFTs in the portfolio.
Get the total real token quantities invested in an LP portfolio.
Parameters
- token_ids: The token IDs of the LP NFTs in the portfolio.
Get the total token that would be received on withdrawing some positions.
This is equivalent to lp_fees()+lp_quantities() for each position.
Parameters
- token_ids: The token IDs of the LP NFTs in the portfolio.
Get the token quantities and uncollected fees invested in an LP portfolio.
Parameters
- token_ids: The token IDs of the LP NFTs in the portfolio.
Get the pool liquidities related information across ticks.
Parameters
- pool: The name of the pool.
- from_tick: The bottom tick of the range (included).
- to_tick: The top tick of the range (included).
Returns
A dict containing: -
current_tick_idx
: The index of the currently active tick in the returned arrays (int). -real_quantities
: The tick indexed real token quantities of the pool (num_ticks, 2). -liquidities
: The tick indexed liquidities of the pool (num_ticks,). -lower_ticks
: The tick indexed lower ticks of the pool (num_ticks,).
Get the pool's trade fee.
Parameters
- pool: The name of the pool.
Returns
The pool's trade fee.
Contains observation logic for the AAVEv3 agents and policies.
Initialize the observation.
Parameters
- backend: The backend to use.
ERC20 token balance.
Includes loands borrowed via AAVE.
Get the price of an asset on AAVE in the Pools base currency.
Get the price of an asset on AAVE in the Pools base currency.
Get account data in the pools base currency.