Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/Uniswap Liquidity Error #225 [WIP] #6731

Open
wants to merge 21 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6da8b6f
Added min max amount config and check balance before creating position
mlguys Dec 21, 2023
8fc8305
added comment
mlguys Dec 21, 2023
c625de5
updated test cases
mlguys Dec 21, 2023
6f710df
Merge branch 'development' into fix/uniswap-lp-error-225
mlguys Dec 21, 2023
26272fe
Added:
mlguys Dec 21, 2023
e1e00da
Added:
mlguys Dec 22, 2023
cf09043
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Jan 8, 2024
3f99337
Merge branch 'development' into fix/uniswap-lp-error-225
rapcmia Jan 22, 2024
cd75f8f
Merge branch 'development' into fix/uniswap-lp-error-225
mlguys Jan 23, 2024
fc52f2a
Merge branch 'development' into fix/uniswap-lp-error-225
mlguys Feb 1, 2024
da898fe
Add status report interval and + rebalancing to AMM LP strategy
mlguys Jan 23, 2024
56c73a5
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Feb 5, 2024
6420135
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Feb 13, 2024
85563b0
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Feb 14, 2024
9b61404
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Feb 15, 2024
b6a9260
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Feb 27, 2024
eaeab61
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Feb 27, 2024
d4afdb7
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Mar 7, 2024
73d0292
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Mar 12, 2024
aba207a
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz Mar 20, 2024
6d5b4fd
Merge branch 'development' into fix/uniswap-lp-error-225
nikspz May 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion hummingbot/connector/gateway/amm_lp/gateway_evm_amm_lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GatewayEVMAMMLP(ConnectorBase):
"""

API_CALL_TIMEOUT = 10.0
POLL_INTERVAL = 1.0
POLL_INTERVAL = 10.0
UPDATE_BALANCE_INTERVAL = 30.0
APPROVAL_ORDER_ID_PATTERN = re.compile(r"approve-(\w+)-(\w+)")

Expand Down Expand Up @@ -1256,3 +1256,9 @@ def tracking_states(self) -> Dict[str, any]:
def _get_gateway_instance(self) -> GatewayHttpClient:
gateway_instance = GatewayHttpClient.get_instance(self._client_config)
return gateway_instance

def set_pool_interval(self, interval: int):
self.POLL_INTERVAL = interval

def set_update_balance_interval(self, interval: int):
self.UPDATE_BALANCE_INTERVAL = interval
248 changes: 222 additions & 26 deletions hummingbot/strategy/amm_v3_lp/amm_v3_lp.py

Large diffs are not rendered by default.

26 changes: 23 additions & 3 deletions hummingbot/strategy/amm_v3_lp/amm_v3_lp_config_map.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from decimal import Decimal

from hummingbot.client.config.config_validators import validate_decimal, validate_market_trading_pair
from hummingbot.client.config.config_validators import validate_decimal, validate_int, validate_market_trading_pair
from hummingbot.client.config.config_var import ConfigVar
from hummingbot.client.settings import (
AllConnectorSettings,
Expand Down Expand Up @@ -71,17 +71,37 @@ def market_prompt() -> str:
validator=lambda v: validate_decimal(v, Decimal("0"), inclusive=False),
default=Decimal("1"),
prompt_on_new=True),
"amount": ConfigVar(
key="amount",
"buffer_spread": ConfigVar(
key="buffer_spread",
prompt="How far from the position price range do you want to keep the position active? (Enter 1 to indicate 1%) >>> ",
type_str="decimal",
validator=lambda v: validate_decimal(v, Decimal("0"), inclusive=False),
default=Decimal("0.5"),
prompt_on_new=True),
"max_amount": ConfigVar(
key="max_amount",
prompt="Enter the maximum value(in terms of base asset) to use for providing liquidity. >>>",
prompt_on_new=True,
validator=lambda v: validate_decimal(v, Decimal("0"), inclusive=False),
type_str="decimal"),
"min_amount": ConfigVar(
key="min_amount",
prompt="Enter the minimum value (in terms of base asset) to use for providing liquidity. >>>",
prompt_on_new=True,
validator=lambda v: validate_decimal(v, Decimal("0"), inclusive=False),
type_str="decimal"),
"min_profitability": ConfigVar(
key="min_profitability",
prompt="What is the minimum unclaimed fees an out of range position must have before it is closed? (in terms of base asset) >>>",
prompt_on_new=False,
validator=lambda v: validate_decimal(v, Decimal("0"), inclusive=False),
default=Decimal("1"),
type_str="decimal"),
"status_report_interval": ConfigVar(
key="status_report_interval",
prompt="How often should the bot get market updates from gateway? (in seconds) >>>",
prompt_on_new=True,
validator=lambda v: validate_int(v, 1, inclusive=True),
default=10,
type_str="int"),
}
12 changes: 9 additions & 3 deletions hummingbot/strategy/amm_v3_lp/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ def start(self):
pair = c_map.get("market").value
fee_tier = c_map.get("fee_tier").value
price_spread = c_map.get("price_spread").value / Decimal("100")
amount = c_map.get("amount").value
buffer_spread = c_map.get("buffer_spread").value / Decimal("100")
min_amount = c_map.get("min_amount").value
max_amount = c_map.get("max_amount").value
min_profitability = c_map.get("min_profitability").value
status_report_interval = c_map.get("status_report_interval").value

self._initialize_markets([(connector, [pair])])
base, quote = pair.split("-")
Expand All @@ -21,5 +24,8 @@ def start(self):
self.strategy = AmmV3LpStrategy(market_info,
fee_tier,
price_spread,
amount,
min_profitability)
buffer_spread,
min_amount,
max_amount,
min_profitability,
status_report_interval)
9 changes: 8 additions & 1 deletion hummingbot/templates/conf_amm_v3_lp_strategy_TEMPLATE.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ fee_tier: null
# The spread between lower price to the upper price
price_spread: null

# The buffer to keep position active when price is moving out of range
buffer_spread: null

# The amount of token (liquidity) provided to the pool
amount: null
max_amount: null
min_amount: null

# The minimum profit required before positions can be adjusted
min_profitability: null

# How often should the bot get market updates from gateway?
status_report_interval: null
20 changes: 16 additions & 4 deletions test/hummingbot/strategy/amm_v3_lp/test_amm_v3_lp.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,16 @@ async def check_network(self) -> NetworkStatus:
async def cancel_outdated_orders(self, _: int) -> List:
return []

async def _update_balances(self):
pass


class AmmV3LpUnitTest(unittest.TestCase):
def setUp(self):
self.clock: Clock = Clock(ClockMode.REALTIME)
self.stack: contextlib.ExitStack = contextlib.ExitStack()
self.lp: MockAMMLP = MockAMMLP("onion")
self.lp.set_balance(BASE_ASSET, 500)
self.lp.set_balance(BASE_ASSET, 5)
self.lp.set_balance(QUOTE_ASSET, 500)
self.market_info = MarketTradingPairTuple(self.lp, TRADING_PAIR, BASE_ASSET, QUOTE_ASSET)

Expand All @@ -154,7 +157,8 @@ def setUp(self):
self.market_info,
"LOW",
Decimal("0.2"),
Decimal("1"),
Decimal("10"),
Decimal("100"),
Decimal("10"),
)
self.clock.add_iterator(self.lp)
Expand Down Expand Up @@ -193,19 +197,27 @@ async def test_format_status(self):

Assets:
Exchange Asset Total Balance Available Balance
0 onion HBOT 500 500
0 onion HBOT 5 5
1 onion USDT 500 500"""
current_status = await self.strategy.format_status()
print(current_status)
self.assertTrue(expected_status in current_status)

@async_test(loop=ev_loop)
async def test_any_active_position(self):
async def test_any_active_position_when_below_min_amount(self):
await asyncio.sleep(2)
self.assertFalse(self.strategy.any_active_position(Decimal("1")))

@async_test(loop=ev_loop)
async def test_any_active_position_when_above_min_amount(self):
await asyncio.sleep(2)
self.lp.set_balance(BASE_ASSET, 500)
await asyncio.sleep(2)
self.assertTrue(self.strategy.any_active_position(Decimal("1")))

@async_test(loop=ev_loop)
async def test_positions_are_created_with_price(self):
self.lp.set_balance(BASE_ASSET, 500)
await asyncio.sleep(2)
self.assertEqual(len(self.strategy.active_positions), 1)
self.lp.set_price(TRADING_PAIR, 2)
Expand Down
6 changes: 4 additions & 2 deletions test/hummingbot/strategy/amm_v3_lp/test_amm_v3_lp_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def setUp(self) -> None:
amm_v3_lp_config_map.get("market").value = "ETH-USDT"
amm_v3_lp_config_map.get("fee_tier").value = "LOW"
amm_v3_lp_config_map.get("price_spread").value = Decimal("1")
amm_v3_lp_config_map.get("amount").value = Decimal("1")
amm_v3_lp_config_map.get("max_amount").value = Decimal("10")
amm_v3_lp_config_map.get("min_amount").value = Decimal("1")
amm_v3_lp_config_map.get("min_profitability").value = Decimal("10")

def _initialize_market_assets(self, market, trading_pairs):
Expand All @@ -42,5 +43,6 @@ def error(self, message, exc_info):
@unittest.mock.patch('hummingbot.strategy.amm_v3_lp.amm_v3_lp.AmmV3LpStrategy.add_markets')
def test_amm_v3_lp_strategy_creation(self, mock):
amm_v3_lp_start.start(self)
self.assertEqual(self.strategy._amount, Decimal(1))
self.assertEqual(self.strategy._max_amount, Decimal(10))
self.assertEqual(self.strategy._min_amount, Decimal(1))
self.assertEqual(self.strategy._min_profitability, Decimal("10"))