exchange.liquidation_price combined position and position_assets

This commit is contained in:
Sam Germain 2022-01-28 05:06:06 -06:00
parent 0b5c2e97b3
commit fe037aa971
4 changed files with 31 additions and 41 deletions

View File

@ -282,16 +282,15 @@ class Binance(Exchange):
open_rate: float, # Entry price of position open_rate: float, # Entry price of position
is_short: bool, is_short: bool,
leverage: float, leverage: float,
trading_mode: TradingMode,
mm_ratio: float, mm_ratio: float,
position: float, # Absolute value of position size
trading_mode: TradingMode,
collateral: Collateral, collateral: Collateral,
maintenance_amt: Optional[float] = None, # (Binance) maintenance_amt: Optional[float] = None, # (Binance)
position: Optional[float] = None, # (Binance and Gateio) Absolute value of position size
wallet_balance: Optional[float] = None, # (Binance and Gateio) wallet_balance: Optional[float] = None, # (Binance and Gateio)
taker_fee_rate: Optional[float] = None, # (Gateio & Okex) taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
liability: Optional[float] = None, # (Okex) liability: Optional[float] = None, # (Okex)
interest: Optional[float] = None, # (Okex) interest: Optional[float] = None, # (Okex)
position_assets: Optional[float] = None, # * (Okex) Might be same as position
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
) -> Optional[float]: ) -> Optional[float]:
@ -303,22 +302,20 @@ class Binance(Exchange):
:param open_rate: (EP1) Entry price of position :param open_rate: (EP1) Entry price of position
:param is_short: True if the trade is a short, false otherwise :param is_short: True if the trade is a short, false otherwise
:param leverage: The amount of leverage on the trade :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) :param mm_ratio: (MMR)
# Binance's formula specifies maintenance margin rate which is mm_ratio * 100% # 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 :param collateral: Either ISOLATED or CROSS
:param maintenance_amt: (CUM) Maintenance Amount of position :param maintenance_amt: (CUM) Maintenance Amount of position
:param wallet_balance: (WB) :param wallet_balance: (WB)
Cross-Margin Mode: crossWalletBalance Cross-Margin Mode: crossWalletBalance
Isolated-Margin Mode: isolatedWalletBalance Isolated-Margin Mode: isolatedWalletBalance
:param position: Absolute value of position size (in base currency)
# * Not required by Binance # * Not required by Binance
:param taker_fee_rate: :param taker_fee_rate:
:param liability: :param liability:
:param interest: :param interest:
:param position_assets:
# * Only required for Cross # * Only required for Cross
:param mm_ex_1: (TMM) :param mm_ex_1: (TMM)

View File

@ -2019,16 +2019,15 @@ class Exchange:
open_rate: float, # Entry price of position open_rate: float, # Entry price of position
is_short: bool, is_short: bool,
leverage: float, leverage: float,
trading_mode: TradingMode,
mm_ratio: float, mm_ratio: float,
position: float, # Absolute value of position size
trading_mode: TradingMode,
collateral: Optional[Collateral] = Collateral.ISOLATED, collateral: Optional[Collateral] = Collateral.ISOLATED,
maintenance_amt: Optional[float] = None, # (Binance) maintenance_amt: Optional[float] = None, # (Binance)
position: Optional[float] = None, # (Binance and Gateio) Absolute value of position size
wallet_balance: Optional[float] = None, # (Binance and Gateio) wallet_balance: Optional[float] = None, # (Binance and Gateio)
taker_fee_rate: Optional[float] = None, # (Gateio & Okex) taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
liability: Optional[float] = None, # (Okex) liability: Optional[float] = None, # (Okex)
interest: Optional[float] = None, # (Okex) interest: Optional[float] = None, # (Okex)
position_assets: Optional[float] = None, # * (Okex) Might be same as position
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
) -> Optional[float]: ) -> Optional[float]:
@ -2097,28 +2096,26 @@ class Exchange:
taker_fee_rate, taker_fee_rate,
liability, liability,
interest, interest,
position_assets,
mm_ex_1, mm_ex_1,
upnl_ex_1, upnl_ex_1,
) )
def liquidation_price_helper( def liquidation_price_helper(
self, self,
open_rate: float, open_rate: float, # Entry price of position
is_short: bool, is_short: bool,
leverage: float, leverage: float,
trading_mode: TradingMode,
mm_ratio: float, mm_ratio: float,
position: float, # Absolute value of position size
trading_mode: TradingMode,
collateral: Collateral, collateral: Collateral,
maintenance_amt: Optional[float] = None, maintenance_amt: Optional[float] = None, # (Binance)
position: Optional[float] = None, wallet_balance: Optional[float] = None, # (Binance and Gateio)
wallet_balance: Optional[float] = None, taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
taker_fee_rate: Optional[float] = None, liability: Optional[float] = None, # (Okex)
liability: Optional[float] = None, interest: Optional[float] = None, # (Okex)
interest: Optional[float] = None, mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
position_assets: Optional[float] = None, upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
mm_ex_1: Optional[float] = 0.0,
upnl_ex_1: Optional[float] = 0.0,
) -> Optional[float]: ) -> Optional[float]:
raise OperationalException(f"liquidation_price is not implemented for {self.name}") raise OperationalException(f"liquidation_price is not implemented for {self.name}")

View File

@ -57,16 +57,15 @@ class Gateio(Exchange):
open_rate: float, # Entry price of position open_rate: float, # Entry price of position
is_short: bool, is_short: bool,
leverage: float, leverage: float,
trading_mode: TradingMode,
mm_ratio: float, mm_ratio: float,
position: float, # Absolute value of position size
trading_mode: TradingMode,
collateral: Collateral, collateral: Collateral,
maintenance_amt: Optional[float] = None, # (Binance) maintenance_amt: Optional[float] = None, # (Binance)
position: Optional[float] = None, # (Binance and Gateio) Absolute value of position size
wallet_balance: Optional[float] = None, # (Binance and Gateio) wallet_balance: Optional[float] = None, # (Binance and Gateio)
taker_fee_rate: Optional[float] = None, # (Gateio & Okex) taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
liability: Optional[float] = None, # (Okex) liability: Optional[float] = None, # (Okex)
interest: Optional[float] = None, # (Okex) interest: Optional[float] = None, # (Okex)
position_assets: Optional[float] = None, # * (Okex) Might be same as position
mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
) -> Optional[float]: ) -> Optional[float]:
@ -77,21 +76,19 @@ class Gateio(Exchange):
:param open_rate: Entry price of position :param open_rate: Entry price of position
:param is_short: True if the trade is a short, false otherwise :param is_short: True if the trade is a short, false otherwise
:param leverage: The amount of leverage on the trade :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 position: Absolute value of position size (in base currency)
:param mm_ratio: :param mm_ratio:
:param trading_mode: SPOT, MARGIN, FUTURES, etc.
:param collateral: Either ISOLATED or CROSS :param collateral: Either ISOLATED or CROSS
:param maintenance_amt: # * Not required by Gateio :param maintenance_amt: # * Not required by Gateio
:param wallet_balance: :param wallet_balance:
Cross-Margin Mode: crossWalletBalance Cross-Margin Mode: crossWalletBalance
Isolated-Margin Mode: isolatedWalletBalance Isolated-Margin Mode: isolatedWalletBalance
:param position: Absolute value of position size (in base currency)
:param taker_fee_rate: :param taker_fee_rate:
# * Not required by Gateio # * Not required by Gateio
:param liability: :param liability:
:param interest: :param interest:
:param position_assets:
:param mm_ex_1: :param mm_ex_1:
:param upnl_ex_1: :param upnl_ex_1:
""" """

View File

@ -33,18 +33,17 @@ class Okex(Exchange):
open_rate: float, # Entry price of position open_rate: float, # Entry price of position
is_short: bool, is_short: bool,
leverage: float, leverage: float,
trading_mode: TradingMode,
mm_ratio: float, mm_ratio: float,
position: float, # Absolute value of position size
trading_mode: TradingMode,
collateral: Collateral, collateral: Collateral,
maintenance_amt: Optional[float] = None, # Not required maintenance_amt: Optional[float] = None, # (Binance)
position: Optional[float] = None, # Not required wallet_balance: Optional[float] = None, # (Binance and Gateio)
wallet_balance: Optional[float] = None, # Not required taker_fee_rate: Optional[float] = None, # (Gateio & Okex)
taker_fee_rate: Optional[float] = None, # * required liability: Optional[float] = None, # (Okex)
liability: Optional[float] = None, # * required interest: Optional[float] = None, # (Okex)
interest: Optional[float] = None, # * required mm_ex_1: Optional[float] = 0.0, # (Binance) Cross only
position_assets: Optional[float] = None, # * required (Might be same as position) upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only
mm_ex_1: Optional[float] = 0.0, # Not required
upnl_ex_1: Optional[float] = 0.0, # Not required
) -> Optional[float]: ) -> Optional[float]:
""" """
PERPETUAL: https://www.okex.com/support/hc/en-us/articles/ PERPETUAL: https://www.okex.com/support/hc/en-us/articles/
@ -54,22 +53,22 @@ class Okex(Exchange):
:param open_rate: (EP1) Entry price of position :param open_rate: (EP1) Entry price of position
:param is_short: True if the trade is a short, false otherwise :param is_short: True if the trade is a short, false otherwise
:param leverage: The amount of leverage on the trade :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 position: Absolute value of position size (in base currency)
:param mm_ratio: :param mm_ratio:
Okex: [assets in the position - (liability +interest) * mark price] / Okex: [assets in the position - (liability +interest) * mark price] /
(maintenance margin + liquidation fee) (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 collateral: Either ISOLATED or CROSS
:param maintenance_amt: # * Not required by Okex :param maintenance_amt: # * Not required by Okex
:param wallet_balance: # * Not required by Okex :param wallet_balance: # * Not required by Okex
:param position: # * Not required by Okex
:param taker_fee_rate: :param taker_fee_rate:
:param liability: :param liability:
Initial liabilities + deducted interest Initial liabilities + deducted interest
Long positions: Liability is calculated in quote currency. Long positions: Liability is calculated in quote currency.
Short positions: Liability is calculated in trading currency. Short positions: Liability is calculated in trading currency.
:param interest: Interest that has not been deducted yet. :param interest: Interest that has not been deducted yet.
:param position_assets: Total position assets on-hold by pending order
:param mm_ex_1: # * Not required by Okex :param mm_ex_1: # * Not required by Okex
:param upnl_ex_1: # * Not required by Okex :param upnl_ex_1: # * Not required by Okex
""" """