From fe037aa971cd7c92edc0bc472769d9ad4b99a927 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Fri, 28 Jan 2022 05:06:06 -0600 Subject: [PATCH] exchange.liquidation_price combined position and position_assets --- freqtrade/exchange/binance.py | 11 ++++------- freqtrade/exchange/exchange.py | 27 ++++++++++++--------------- freqtrade/exchange/gateio.py | 9 +++------ freqtrade/exchange/okex.py | 25 ++++++++++++------------- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 55168aebf..01c22aee6 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -282,16 +282,15 @@ class Binance(Exchange): open_rate: float, # Entry price of position is_short: bool, leverage: float, - trading_mode: TradingMode, mm_ratio: float, + position: float, # Absolute value of position size + trading_mode: TradingMode, collateral: Collateral, 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) taker_fee_rate: Optional[float] = None, # (Gateio & Okex) liability: 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 upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only ) -> Optional[float]: @@ -303,22 +302,20 @@ class Binance(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) # 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 maintenance_amt: (CUM) Maintenance Amount of position :param wallet_balance: (WB) Cross-Margin Mode: crossWalletBalance Isolated-Margin Mode: isolatedWalletBalance - :param position: Absolute value of position size (in base currency) # * Not required by Binance :param taker_fee_rate: :param liability: :param interest: - :param position_assets: # * Only required for Cross :param mm_ex_1: (TMM) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index b74fbfe1d..eb7b58a9c 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -2019,16 +2019,15 @@ class Exchange: open_rate: float, # Entry price of position is_short: bool, leverage: float, - trading_mode: TradingMode, mm_ratio: float, + position: float, # Absolute value of position size + trading_mode: TradingMode, collateral: Optional[Collateral] = Collateral.ISOLATED, 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) taker_fee_rate: Optional[float] = None, # (Gateio & Okex) liability: 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 upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only ) -> Optional[float]: @@ -2097,28 +2096,26 @@ class Exchange: taker_fee_rate, liability, interest, - position_assets, mm_ex_1, upnl_ex_1, ) def liquidation_price_helper( self, - open_rate: float, + open_rate: float, # Entry price of position is_short: bool, leverage: float, - trading_mode: TradingMode, mm_ratio: float, + position: float, # Absolute value of position size + trading_mode: TradingMode, collateral: Collateral, - maintenance_amt: Optional[float] = None, - position: Optional[float] = None, - wallet_balance: Optional[float] = None, - taker_fee_rate: Optional[float] = None, - liability: Optional[float] = None, - interest: Optional[float] = None, - position_assets: Optional[float] = None, - mm_ex_1: Optional[float] = 0.0, - upnl_ex_1: Optional[float] = 0.0, + 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]: raise OperationalException(f"liquidation_price is not implemented for {self.name}") diff --git a/freqtrade/exchange/gateio.py b/freqtrade/exchange/gateio.py index e2dbf35c7..7cdd27175 100644 --- a/freqtrade/exchange/gateio.py +++ b/freqtrade/exchange/gateio.py @@ -57,16 +57,15 @@ class Gateio(Exchange): open_rate: float, # Entry price of position is_short: bool, leverage: float, - trading_mode: TradingMode, mm_ratio: float, + position: float, # Absolute value of position size + trading_mode: TradingMode, collateral: Collateral, 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) taker_fee_rate: Optional[float] = None, # (Gateio & Okex) liability: 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 upnl_ex_1: Optional[float] = 0.0, # (Binance) Cross only ) -> Optional[float]: @@ -77,21 +76,19 @@ class Gateio(Exchange): :param open_rate: 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: + :param trading_mode: SPOT, MARGIN, FUTURES, etc. :param collateral: Either ISOLATED or CROSS :param maintenance_amt: # * Not required by Gateio :param wallet_balance: Cross-Margin Mode: crossWalletBalance Isolated-Margin Mode: isolatedWalletBalance - :param position: Absolute value of position size (in base currency) :param taker_fee_rate: # * Not required by Gateio :param liability: :param interest: - :param position_assets: :param mm_ex_1: :param upnl_ex_1: """ diff --git a/freqtrade/exchange/okex.py b/freqtrade/exchange/okex.py index f847f1180..0222f3b41 100644 --- a/freqtrade/exchange/okex.py +++ b/freqtrade/exchange/okex.py @@ -33,18 +33,17 @@ class Okex(Exchange): open_rate: float, # Entry price of position is_short: bool, leverage: float, - trading_mode: TradingMode, mm_ratio: float, + position: float, # Absolute value of position size + trading_mode: TradingMode, collateral: Collateral, - maintenance_amt: Optional[float] = None, # Not required - position: Optional[float] = None, # Not required - wallet_balance: Optional[float] = None, # Not required - taker_fee_rate: Optional[float] = None, # * required - liability: Optional[float] = None, # * required - interest: Optional[float] = None, # * required - position_assets: Optional[float] = None, # * required (Might be same as position) - mm_ex_1: Optional[float] = 0.0, # Not required - upnl_ex_1: Optional[float] = 0.0, # Not required + 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]: """ 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 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: 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 position: # * Not required by Okex :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 position_assets: Total position assets – on-hold by pending order :param mm_ex_1: # * Not required by Okex :param upnl_ex_1: # * Not required by Okex """