wallet amount for futures
This commit is contained in:
parent
fd936e26ae
commit
f67e0bd6dd
@ -342,7 +342,7 @@ class Exchange:
|
|||||||
|
|
||||||
def get_pair_base_currency(self, pair: str) -> str:
|
def get_pair_base_currency(self, pair: str) -> str:
|
||||||
"""
|
"""
|
||||||
Return a pair's quote currency
|
Return a pair's base currency
|
||||||
"""
|
"""
|
||||||
return self.markets.get(pair, {}).get('base', '')
|
return self.markets.get(pair, {}).get('base', '')
|
||||||
|
|
||||||
@ -1158,6 +1158,39 @@ class Exchange:
|
|||||||
balances.pop("total", None)
|
balances.pop("total", None)
|
||||||
balances.pop("used", None)
|
balances.pop("used", None)
|
||||||
|
|
||||||
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
|
|
||||||
|
open_orders_response: List[dict] = self._api.fetch_open_orders()
|
||||||
|
open_orders: dict = {}
|
||||||
|
for order in open_orders_response:
|
||||||
|
symbol: str = order['symbol']
|
||||||
|
open_orders[symbol] = order
|
||||||
|
|
||||||
|
positions: List[dict] = self._api.fetch_positions()
|
||||||
|
for position in positions:
|
||||||
|
symbol = position['symbol']
|
||||||
|
market: dict = self.markets[symbol]
|
||||||
|
size: float = self._contracts_to_amount(symbol, position['contracts'])
|
||||||
|
side: str = position['side']
|
||||||
|
if size > 0:
|
||||||
|
|
||||||
|
if symbol in open_orders:
|
||||||
|
order_amount: float = open_orders[symbol]['remaining']
|
||||||
|
else:
|
||||||
|
order_amount = 0
|
||||||
|
|
||||||
|
if side == 'short':
|
||||||
|
currency: str = market['quote']
|
||||||
|
else:
|
||||||
|
currency = market['base']
|
||||||
|
|
||||||
|
if currency in balances:
|
||||||
|
balances[currency] = {
|
||||||
|
'free': size - order_amount,
|
||||||
|
'used': order_amount,
|
||||||
|
'total': size,
|
||||||
|
}
|
||||||
|
|
||||||
return balances
|
return balances
|
||||||
except ccxt.DDoSProtection as e:
|
except ccxt.DDoSProtection as e:
|
||||||
raise DDosProtection(e) from e
|
raise DDosProtection(e) from e
|
||||||
|
@ -1338,7 +1338,6 @@ class FreqtradeBot(LoggingMixin):
|
|||||||
trade_base_currency = self.exchange.get_pair_base_currency(pair)
|
trade_base_currency = self.exchange.get_pair_base_currency(pair)
|
||||||
wallet_amount = self.wallets.get_free(trade_base_currency)
|
wallet_amount = self.wallets.get_free(trade_base_currency)
|
||||||
logger.debug(f"{pair} - Wallet: {wallet_amount} - Trade-amount: {amount}")
|
logger.debug(f"{pair} - Wallet: {wallet_amount} - Trade-amount: {amount}")
|
||||||
# TODO-lev: Get wallet amount + value of positions
|
|
||||||
if wallet_amount >= amount or self.trading_mode == TradingMode.FUTURES:
|
if wallet_amount >= amount or self.trading_mode == TradingMode.FUTURES:
|
||||||
# A safe exit amount isn't needed for futures, you can just exit/close the position
|
# A safe exit amount isn't needed for futures, you can just exit/close the position
|
||||||
return amount
|
return amount
|
||||||
|
Loading…
Reference in New Issue
Block a user