feat: add asymmetric compensation & exact liquidity support to hedger
This commit is contained in:
@ -128,8 +128,8 @@ CLOSE_POSITION_ENABLED = True
|
||||
OPEN_POSITION_ENABLED = True
|
||||
REBALANCE_ON_CLOSE_BELOW_RANGE = True
|
||||
TARGET_INVESTMENT_VALUE_USDC = 2000
|
||||
INITIAL_HEDGE_CAPITAL_USDC = 2000 # Your starting Hyperliquid balance for Benchmark calc
|
||||
RANGE_WIDTH_PCT = Decimal("0.01") # +/- 1% (2% total width)
|
||||
INITIAL_HEDGE_CAPITAL_USDC = 1000 # Your starting Hyperliquid balance for Benchmark calc
|
||||
RANGE_WIDTH_PCT = Decimal("0.05") # +/- 5% (10% total width)
|
||||
SLIPPAGE_TOLERANCE = Decimal("0.02") # do not change, or at least remember it ( 0.02 = 2.0% slippage tolerance)
|
||||
TRANSACTION_TIMEOUT_SECONDS = 30
|
||||
|
||||
@ -179,9 +179,10 @@ def send_transaction_robust(
|
||||
"""
|
||||
try:
|
||||
# 1. Prepare Params
|
||||
# Use 'pending' to ensure we get the correct nonce if a tx was just sent/mined
|
||||
tx_params = {
|
||||
'from': account.address,
|
||||
'nonce': w3.eth.get_transaction_count(account.address),
|
||||
'nonce': w3.eth.get_transaction_count(account.address, 'pending'),
|
||||
'value': value,
|
||||
'chainId': w3.eth.chain_id,
|
||||
}
|
||||
@ -541,7 +542,7 @@ def mint_new_position(w3: Web3, npm_contract, account: LocalAccount, token0: str
|
||||
# IncreaseLiquidity Event (Topic0)
|
||||
increase_liq_topic = Web3.keccak(text="IncreaseLiquidity(uint256,uint128,uint256,uint256)").hex()
|
||||
|
||||
minted_data = {'token_id': None, 'amount0': 0, 'amount1': 0}
|
||||
minted_data = {'token_id': None, 'liquidity': 0, 'amount0': 0, 'amount1': 0}
|
||||
|
||||
for log in receipt.logs:
|
||||
topics = [t.hex() for t in log['topics']]
|
||||
@ -560,6 +561,7 @@ def mint_new_position(w3: Web3, npm_contract, account: LocalAccount, token0: str
|
||||
data = data[2:]
|
||||
|
||||
# liquidity is first 32 bytes (padded), amt0 next 32, amt1 next 32
|
||||
minted_data['liquidity'] = int(data[0:64], 16)
|
||||
minted_data['amount0'] = int(data[64:128], 16)
|
||||
minted_data['amount1'] = int(data[128:192], 16)
|
||||
|
||||
@ -872,6 +874,7 @@ def main():
|
||||
"entry_price": round(entry_price, 2),
|
||||
"amount0_initial": round(fmt_amt0, 4),
|
||||
"amount1_initial": round(fmt_amt1, 2),
|
||||
"liquidity": str(minted['liquidity']),
|
||||
"range_upper": round(float(price_from_tick(tick_upper, d0, d1)), 2),
|
||||
"range_lower": round(float(price_from_tick(tick_lower, d0, d1)), 2),
|
||||
"timestamp_open": int(time.time())
|
||||
@ -891,4 +894,4 @@ def main():
|
||||
time.sleep(MONITOR_INTERVAL_SECONDS)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
main()
|
||||
Reference in New Issue
Block a user