nqs_sdk.coding_envs.protocols.uniswap_v3.uniswap_v3_coding_env module

class nqs_sdk.coding_envs.protocols.uniswap_v3.uniswap_v3_coding_env.UniswapV3CodingProtocol(pool, generators=[])[source]

Bases: CodingProtocol, UniswapV3Protocol

__init__(pool, generators=[])[source]
id()[source]

Returns the id of the protocol

Return type:

str

get_protocol_factory()[source]

Returns the protocol factory

Return type:

Optional[ProtocolMetaFactory]

get_protocol_description()[source]

Returns the description of the protocol, the market description and the coding interface

Return type:

tuple[str, str, list[str]]

get_tx_generators()[source]

Returns the list of all tx generators

Return type:

List[TxGenerator]

get_observables_names()[source]

Returns the list of all observables names

Return type:

list[str]

property token0: str

Get the name of the token0 of the pool.

property token1: str

Get the name of the token1 of the pool.

property fee_tier: float

Get the fee tier of the pool.

is_position_exists(token_id)[source]

Check if the position exists.

Parameters:

token_id (str) – Token ID of the position

Returns:

True if the position exists, False otherwise

Return type:

bool

dex_spot(lookback=None)[source]

Get the price of token0 in units of token1.

Parameters:

lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period. If None, returns only the current price.

Returns:

the series of spot prices (i.e. the price of token0 in units of token1)

(None if not available).

Return type:

pandas.Series

liquidity(lookback=None)[source]

Get the liquidity parameter in the pool for the current tick.

Parameters:

lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period. If None, returns only the current liquidity.

Returns:

the series of liquidity values (None if not available)

Return type:

pandas.Series

total_volume_numeraire(lookback=None)[source]

Get the total volume of swaps in the pool in units of the user numeraire.

Parameters:
  • lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period.

  • None (If)

  • volume. (returns only the current)

Returns:

Series of total volume in numeraire (None if not available)

Return type:

pandas.Series

total_volume(token, lookback=None)[source]

Get the total volume of swaps in the pool for the specified token.

Parameters:
  • token (bool) – False for token0, True for token1

  • lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period. If None, returns only the current volume.

Returns:

Series of total volume for the specified token (None if not available)

Return type:

pandas.Series

total_holdings(token, lookback=None)[source]

Get the total holdings of the specified token in the pool.

Parameters:
  • token (bool) – False for token0, True for token1

  • lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period. If None, returns only the current volume.

Returns:

Series of total holdings for the specified token (None if not available)

Return type:

pandas.Series

total_fees(token=None, lookback=None)[source]

Get the total fees in the pool.

Parameters:
  • token (Optional[bool]) – False for token0, True for token1. If None, returns fees in numeraire.

  • lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period. If None, returns only the current fees.

Returns:

Series of total fees (in token units if token specified, otherwise in numeraire)

(None if not available).

Return type:

pandas.Series

total_value_locked(lookback=None)[source]

Get the total value locked in the pool in units of the user numeraire.

Parameters:

lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period. If None, returns only the current value locked.

Returns:

Series of total value locked (None if not available)

Return type:

pandas.Series

get_tick(lookback=None)[source]

Get the tick of the pool.

Parameters:
  • lookback (Optional[datetime.timedelta]) – Return all data included in the lookback period.

  • None (If)

  • tick. (returns only the current)

Returns:

Series of tick values (None if not available)

Return type:

pandas.Series

swap(amount, token, price_limit=None)[source]

Swap or exchange tokens in the pool. At least one of the arguments should be provided.

Parameters:
  • amount (float) – The amount of token to be swapped.

  • token (bool) – True for swapping token1 to token0, False for swapping token0 to token1.

  • price_limit (Optional[float]) – The price limit for the swap. If None, the swap is done at the current price.

Return type:

None

mint(price_lower, price_upper, max_token0, max_token1, token_id)[source]

Uniswap V3 minting enables users to provide (add) liquidity within specific price ranges.

Parameters:
  • price_lower (float) – The lower price of the liquidity range.

  • price_upper (float) – The upper price of the liquidity range.

  • max_token0 (float) – The maximum amount of token0 to be used.

  • max_token1 (float) – The maximum amount of token1 to be used.

  • token_id (str) – A string identifier of the position.

Return type:

Optional[dict[str, Decimal]]

burn(amount_ratio, token_id)[source]

Uniswap v3 burn is the burning of LP tokens, when users can effectively withdraw liquidity from specific price ranges within Uniswap V3 liquidity pools.

Parameters:
  • amount_ratio (float) – Amount of liquidity to be burned (between 0.0 and 1.0 where 1.0 represent all

  • position). (the liquidity of the)

  • token_id (str) – The id of position to be burned.

Return type:

None

active_liquidity(token_id=None)[source]

Get liquidity that is currently active in the pool.

Parameters:

position (str, optional) – Position ID to get specific position’s active liquidity. If None, returns user’s total active liquidity.

Returns:

Active liquidity amount at the requested block number

Return type:

Decimal

position_liquidity(token_id=None)[source]

Get total liquidity allocated in the pool

Parameters:

position (str) – Position ID to get specific user position’s active liquidity.

Returns:

Total liquidity amount for the pool or a specific user position

(None if not available)

Return type:

Optional[Decimal]

token_amount(token, token_id=None)[source]

Get actual token amount in the pool.

Parameters:
  • token (str) – str to query amount for

  • position (str, optional) – Position ID to get specific position’s token amount. If None, returns user’s total token amount.

Returns:

Amount of specified token at the requested block number

Return type:

Decimal

net_position(token_id)[source]

Get the value of agent’s position in the pool.

Parameters:

position (str) – Position ID to query

Returns:

Position value in units of numeraire at the requested block number

Return type:

Decimal

fees_collected(token=None, token_id=None)[source]

Get collected fees.

Parameters:
  • token (str, optional) – str to query fees for

  • position (str, optional) – Position ID to get specific position’s fees. If None, returns user’s total collected fees.

Returns:

Amount of collected fees in specified token or numeraire at the requested block number

Return type:

Decimal

fees_not_collected(token=None, token_id=None)[source]

Get uncollected fees.

Parameters:
  • token (str, optional) – str to query fees for

  • position (str, optional) – Position ID to get specific position’s fees. If None, returns user’s total uncollected fees.

Returns:

Amount of uncollected fees in specified token or numeraire at the requested block number

Return type:

Decimal

abs_impermanent_loss(token_id=None)[source]

Get absolute impermanent loss.

Parameters:

position (str, optional) – Position ID to get specific position’s IL. If None, returns IL for all user’s open positions.

Returns:

Impermanent loss in units of numeraire at the requested block number

Return type:

Decimal

perc_impermanent_loss(token_id=None)[source]

Get impermanent loss as a percentage.

Parameters:

position (str, optional) – Position ID to get specific position’s IL. If None, returns IL percentage for all user’s open positions.

Returns:

Impermanent loss as a percentage

Return type:

Decimal

static_ptf_value(token_id=None)[source]

Get value of the static portfolio.

Parameters:

position (str, optional) – Position ID to get specific position’s value. If None, returns value for all user’s open positions.

Returns:

Static portfolio value in numeraire at the requested block number

Return type:

Decimal

permanent_loss(token_id=None)[source]

Get realized/permanent loss.

Parameters:

position (str, optional) – Position ID to get specific position’s loss. If None, returns loss for all user’s open positions.

Returns:

Permanent loss in units of numeraire at the requested block number

Return type:

Decimal

loss_versus_rebalancing(token_id=None)[source]

Get loss compared to rebalancing strategy.

Parameters:

position (str, optional) – Position ID to get specific position’s LVR. If None, returns LVR for all user’s open positions.

Returns:

Loss versus rebalancing in units of numeraire at the requested block number

Return type:

Decimal

total_fees_relative_to_lvr(token_id=None)[source]

Get total accumulated fees as percentage of LVR.

Parameters:

position (str, optional) – Position ID to get specific position’s relative fees. If None, returns relative fees for all user’s open positions.

Returns:

Fees as percentage of loss versus rebalancing at the requested block number

Return type:

Decimal

position_bounds(token_id)[source]

Get price bounds of a position.

Parameters:

position (str) – Position ID to query

Returns:

Lower and upper price bounds of the position

Return type:

tuple[Decimal, Decimal]