calculate_max_position_whale_risk
Documentation for eth_defi.gmx.market_depth.calculate_max_position_whale_risk function.
- calculate_max_position_whale_risk(market, portfolio_usd, max_oi_pct, is_long)
Calculate the maximum position size subject to whale-risk constraints.
Analogous to sizing a position in a Uniswap pool so as not to become too large relative to the pool’s liquidity. On GMX, we don’t want to represent more than
max_oi_pctof one side’s open interest, because:Exiting a large position will move OI against us.
Other traders may push OI further, increasing funding/borrowing drag.
In extreme cases the pool capacity cap prevents new positions entirely.
The maximum position is:
max_position = min(portfolio_usd, max_oi_pct * side_oi, available_cap)
For a $100 000 portfolio with
max_oi_pct = 0.025(2.5 %), a market with $1 M long OI allows at most$25 000on the long side — meaning 10 equally weighted positions would already be constrained.Example:
from eth_defi.gmx.api import GMXAPI from eth_defi.gmx.market_depth import calculate_max_position_whale_risk api = GMXAPI(chain="arbitrum") markets = api.get_market_depth() for m in markets: result = calculate_max_position_whale_risk( market=m, portfolio_usd=100_000, max_oi_pct=0.025, is_long=True, ) print(f"{m.market_symbol}: max ${result.max_position_usd:,.0f} ({result.pct_of_total_oi:.2f}% of OI) {'OK' if result.whale_ok and result.cap_ok else result.binding_constraint}")
- Parameters
market (eth_defi.gmx.market_depth.MarketDepthInfo) – Market depth snapshot
portfolio_usd (float) – Total portfolio value in USD
max_oi_pct (float) – Maximum share of one side’s OI the position may represent. E.g.
0.025means 2.5 %.is_long (bool) –
Truefor long side,Falsefor short side
- Returns
PositionSizingResultwith the capped position and diagnostics- Return type