nectarengine.pool module
- class nectarengine.pool.LiquidityPool(api: Api | None = None, blockchain_instance: Any | None = None)
Bases:
listAccess the hive-engine liquidity pools
- Parameters:
blockchain_instance (Hive) – Hive instance
- add_liquidity(account: str, token_pair: str, base_quantity: float, quote_quantity: float, max_price_impact: float | None = None, max_deviation: float | None = None) Dict[str, Any]
Add liquidity to a pool.
- Parameters:
account (str) – account name
token_pair (str) – Token pair in the format ‘TOKEN1:TOKEN2’
base_quantity (float) – Amount to deposit into the base token reserve (first token in pair)
quote_quantity (float) – Amount to deposit into the quote token reserve (second token in pair)
max_price_impact (float) – (optional) Amount of tolerance to price impact after adding liquidity
max_deviation (float) – (optional) Amount of tolerance to price difference versus the regular HE market
Add liquidity example:
from nectarengine.pool import LiquidityPool from nectar import Hive active_wif = "5xxxx" hv = Hive(keys=[active_wif]) pool = LiquidityPool(blockchain_instance=hv) pool.add_liquidity("test", "GLD:SLV", 1000, 16000, max_price_impact=1, max_deviation=1)
- create_pool(account: str, token_pair: str) Dict[str, Any]
Create a new liquidity pool for a token pair.
- Parameters:
account (str) – account name
token_pair (str) – Token pair in the format ‘TOKEN1:TOKEN2’
Create pool example:
from nectarengine.pool import LiquidityPool from nectar import Hive active_wif = "5xxxx" hv = Hive(keys=[active_wif]) pool = LiquidityPool(blockchain_instance=hv) pool.create_pool("test", "GLD:SLV")
- create_reward_pool(account: str, token_pair: str, lottery_winners: int, lottery_interval_hours: int, lottery_amount: float, mined_token: str) Dict[str, Any]
Create a reward pool for liquidity providers.
- Parameters:
account (str) – account name
token_pair (str) – Token pair in the format ‘TOKEN1:TOKEN2’
lottery_winners (int) – Number of lottery winners per round (1-20)
lottery_interval_hours (int) – How often in hours to run a lottery (1-720)
lottery_amount (float) – Amount to pay out per round
mined_token (str) – Which token to issue as reward
Create reward pool example:
from nectarengine.pool import LiquidityPool from nectar import Hive active_wif = "5xxxx" hv = Hive(keys=[active_wif]) pool = LiquidityPool(blockchain_instance=hv) pool.create_reward_pool("test", "GLD:SLV", 20, 1, 1, "GLD")
- get_liquidity_positions(account: str | None = None, token_pair: str | None = None, limit: int = 100, offset: int = 0) List[Dict[str, Any]]
Returns liquidity positions. When account is set, only positions from the given account are shown. When token_pair is set, only positions for the given token pair are shown.
- get_pool(token_pair: str) Pool
Returns a specific liquidity pool for a given token pair
- Parameters:
token_pair (str) – Token pair in the format ‘TOKEN1:TOKEN2’
- Raises:
PoolDoesNotExist – If the pool does not exist
- Returns:
Pool object
- Return type:
- get_pools() List[Dict[str, Any]]
Returns all liquidity pools as list
- refresh() None
- remove_liquidity(account: str, token_pair: str, shares_out: float) Dict[str, Any]
Remove liquidity from a pool.
- Parameters:
account (str) – account name
token_pair (str) – Token pair in the format ‘TOKEN1:TOKEN2’
shares_out (float) – Percentage > 0 <= 100 - amount of liquidity shares to convert into tokens
Remove liquidity example:
from nectarengine.pool import LiquidityPool from nectar import Hive active_wif = "5xxxx" hv = Hive(keys=[active_wif]) pool = LiquidityPool(blockchain_instance=hv) pool.remove_liquidity("test", "GLD:SLV", 50)
- set_id(ssc_id: str) None
Sets the ssc id (default is ssc-mainnet-hive)
- set_reward_pool_active(account: str, token_pair: str, mined_token: str, active: bool) Dict[str, Any]
Enable or disable a reward pool.
- Parameters:
account (str) – account name
token_pair (str) – Token pair in the format ‘TOKEN1:TOKEN2’
mined_token (str) – Which token to issue as reward
active (bool) – Set reward pool to active or inactive
Set reward pool active example:
from nectarengine.pool import LiquidityPool from nectar import Hive active_wif = "5xxxx" hv = Hive(keys=[active_wif]) pool = LiquidityPool(blockchain_instance=hv) pool.set_reward_pool_active("test", "GLD:SLV", "GLD", True)
- swap_tokens(account: str, token_pair: str, token_symbol: str, token_amount: float, trade_type: str, min_amount_out: float | None = None, max_amount_in: float | None = None) Dict[str, Any]
Swap tokens using a liquidity pool.
- Parameters:
account (str) – account name
token_pair (str) – Token pair in the format ‘TOKEN1:TOKEN2’
token_symbol (str) – Token symbol being traded
token_amount (float) – Amount of tokens to trade
trade_type (str) – Either ‘exactInput’ or ‘exactOutput’
min_amount_out (float) – (optional) Minimum amount expected out for exactInput trade
max_amount_in (float) – (optional) Maximum amount expected in for exactOutput trade
Swap tokens example (exactInput):
from nectarengine.pool import LiquidityPool from nectar import Hive active_wif = "5xxxx" hv = Hive(keys=[active_wif]) pool = LiquidityPool(blockchain_instance=hv) pool.swap_tokens("test", "GLD:SLV", "GLD", 1, "exactInput", min_amount_out=1)