okex.liquidation_price formula update
This commit is contained in:
parent
fe037aa971
commit
7f4894d68e
@ -289,8 +289,6 @@ class Binance(Exchange):
|
||||
maintenance_amt: Optional[float] = None, # (Binance)
|
||||
wallet_balance: Optional[float] = None, # (Binance and Gateio)
|
||||
taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
|
||||
liability: Optional[float] = None, # (Okex)
|
||||
interest: Optional[float] = None, # (Okex)
|
||||
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
) -> Optional[float]:
|
||||
@ -314,8 +312,6 @@ class Binance(Exchange):
|
||||
|
||||
# * Not required by Binance
|
||||
:param taker_fee_rate:
|
||||
:param liability:
|
||||
:param interest:
|
||||
|
||||
# * Only required for Cross
|
||||
:param mm_ex_1: (TMM)
|
||||
|
@ -2026,8 +2026,6 @@ class Exchange:
|
||||
maintenance_amt: Optional[float] = None, # (Binance)
|
||||
wallet_balance: Optional[float] = None, # (Binance and Gateio)
|
||||
taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
|
||||
liability: Optional[float] = None, # (Okex)
|
||||
interest: Optional[float] = None, # (Okex)
|
||||
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
) -> Optional[float]:
|
||||
@ -2036,12 +2034,12 @@ class Exchange:
|
||||
:param open_rate: (EP1) Entry price of position
|
||||
:param is_short: True if the trade is a short, false otherwise
|
||||
:param leverage: The amount of leverage on the trade
|
||||
:param trading_mode: SPOT, MARGIN, FUTURES, etc.
|
||||
:param position: Absolute value of position size (in base currency)
|
||||
:param mm_ratio: (MMR)
|
||||
Okex: [assets in the position - (liability +interest) * mark price] /
|
||||
(maintenance margin + liquidation fee)
|
||||
# * Note: Binance's formula specifies maintenance margin rate which is mm_ratio * 100%
|
||||
:param position: Absolute value of position size (in base currency)
|
||||
:param trading_mode: SPOT, MARGIN, FUTURES, etc.
|
||||
:param collateral: Either ISOLATED or CROSS
|
||||
|
||||
# * Binance
|
||||
@ -2051,21 +2049,10 @@ class Exchange:
|
||||
:param wallet_balance: (WB)
|
||||
Cross-Margin Mode: crossWalletBalance
|
||||
Isolated-Margin Mode: isolatedWalletBalance
|
||||
:param position: Absolute value of position size (in base currency)
|
||||
|
||||
# * Gateio & Okex
|
||||
:param taker_fee_rate:
|
||||
|
||||
# * Okex
|
||||
:param liability:
|
||||
Initial liabilities + deducted interest
|
||||
• Long positions: Liability is calculated in quote currency.
|
||||
• Short positions: Liability is calculated in trading currency.
|
||||
:param interest:
|
||||
Interest that has not been deducted yet.
|
||||
:param position_assets:
|
||||
Total position assets – on-hold by pending order
|
||||
|
||||
# * Cross only (Binance)
|
||||
:param mm_ex_1: (TMM)
|
||||
Cross-Margin Mode: Maintenance Margin of all other contracts, excluding Contract 1
|
||||
@ -2084,20 +2071,18 @@ class Exchange:
|
||||
)
|
||||
|
||||
return self.liquidation_price_helper(
|
||||
open_rate,
|
||||
is_short,
|
||||
leverage,
|
||||
trading_mode,
|
||||
mm_ratio,
|
||||
collateral,
|
||||
maintenance_amt,
|
||||
position,
|
||||
wallet_balance,
|
||||
taker_fee_rate,
|
||||
liability,
|
||||
interest,
|
||||
mm_ex_1,
|
||||
upnl_ex_1,
|
||||
open_rate=open_rate,
|
||||
is_short=is_short,
|
||||
leverage=leverage,
|
||||
mm_ratio=mm_ratio,
|
||||
position=position,
|
||||
trading_mode=trading_mode,
|
||||
collateral=collateral,
|
||||
maintenance_amt=maintenance_amt,
|
||||
wallet_balance=wallet_balance,
|
||||
taker_fee_rate=taker_fee_rate,
|
||||
mm_ex_1=mm_ex_1,
|
||||
upnl_ex_1=upnl_ex_1,
|
||||
)
|
||||
|
||||
def liquidation_price_helper(
|
||||
@ -2112,8 +2097,6 @@ class Exchange:
|
||||
maintenance_amt: Optional[float] = None, # (Binance)
|
||||
wallet_balance: Optional[float] = None, # (Binance and Gateio)
|
||||
taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
|
||||
liability: Optional[float] = None, # (Okex)
|
||||
interest: Optional[float] = None, # (Okex)
|
||||
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
) -> Optional[float]:
|
||||
|
@ -64,8 +64,6 @@ class Gateio(Exchange):
|
||||
maintenance_amt: Optional[float] = None, # (Binance)
|
||||
wallet_balance: Optional[float] = None, # (Binance and Gateio)
|
||||
taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
|
||||
liability: Optional[float] = None, # (Okex)
|
||||
interest: Optional[float] = None, # (Okex)
|
||||
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
) -> Optional[float]:
|
||||
@ -87,8 +85,6 @@ class Gateio(Exchange):
|
||||
:param taker_fee_rate:
|
||||
|
||||
# * Not required by Gateio
|
||||
:param liability:
|
||||
:param interest:
|
||||
:param mm_ex_1:
|
||||
:param upnl_ex_1:
|
||||
"""
|
||||
|
@ -40,8 +40,6 @@ class Okex(Exchange):
|
||||
maintenance_amt: Optional[float] = None, # (Binance)
|
||||
wallet_balance: Optional[float] = None, # (Binance and Gateio)
|
||||
taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
|
||||
liability: Optional[float] = None, # (Okex)
|
||||
interest: Optional[float] = None, # (Okex)
|
||||
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
|
||||
) -> Optional[float]:
|
||||
@ -57,36 +55,26 @@ class Okex(Exchange):
|
||||
:param mm_ratio:
|
||||
Okex: [assets in the position - (liability +interest) * mark price] /
|
||||
(maintenance margin + liquidation fee)
|
||||
:param position:
|
||||
Total position assets – on-hold by pending order
|
||||
:param trading_mode: SPOT, MARGIN, FUTURES, etc.
|
||||
:param collateral: Either ISOLATED or CROSS
|
||||
:param maintenance_amt: # * Not required by Okex
|
||||
:param wallet_balance: # * Not required by Okex
|
||||
:param wallet_balance: # * margin_balance?
|
||||
:param taker_fee_rate:
|
||||
:param liability:
|
||||
Initial liabilities + deducted interest
|
||||
• Long positions: Liability is calculated in quote currency.
|
||||
• Short positions: Liability is calculated in trading currency.
|
||||
:param interest: Interest that has not been deducted yet.
|
||||
:param mm_ex_1: # * Not required by Okex
|
||||
:param upnl_ex_1: # * Not required by Okex
|
||||
"""
|
||||
|
||||
if (not liability or not interest or not taker_fee_rate or not position_assets):
|
||||
if (not taker_fee_rate):
|
||||
raise OperationalException(
|
||||
"Parameters liability, interest, taker_fee_rate, position_assets"
|
||||
"are required by Okex.liquidation_price"
|
||||
"Parameter taker_fee_rate is required by Okex.liquidation_price"
|
||||
)
|
||||
|
||||
if trading_mode == TradingMode.FUTURES and collateral == Collateral.ISOLATED:
|
||||
|
||||
if is_short:
|
||||
return (liability + interest) * (1 + mm_ratio) * (1 + taker_fee_rate)
|
||||
return (margin_balance + (face_value * number_of_contracts * open_price)) / [face_value * number_of_contracts * (mm_ratio + taker_fee_rate + 1)]
|
||||
else:
|
||||
return (
|
||||
(liability + interest) * (1 + mm_ratio) * (1 + taker_fee_rate) /
|
||||
position_assets
|
||||
)
|
||||
return (margin_balance - (face_value * number_of_contracts * open_price)) / [face_value * number_of_contracts * (mm_ratio + taker_fee_rate - 1)]
|
||||
else:
|
||||
raise OperationalException(
|
||||
f"Okex does not support {collateral.value} Mode {trading_mode.value} trading")
|
||||
|
Loading…
Reference in New Issue
Block a user