+ def order_precision(self, symbol):
+ self.load_markets()
+ return self.markets[symbol]['precision']['price']
+
+ def transfer_balance(self, currency, amount, from_account, to_account):
+ result = self.privatePostTransferBalance({
+ "currency": currency,
+ "amount": amount,
+ "fromAccount": from_account,
+ "toAccount": to_account,
+ "confirmed": 1})
+ return result["success"] == 1
+
+ def close_margin_position(self, currency, base_currency):
+ """
+ closeMarginPosition({"currencyPair": "BTC_DASH"})
+ fermer la position au prix du marché
+ """
+ symbol = "{}_{}".format(base_currency, currency)
+ self.privatePostCloseMarginPosition({"currencyPair": symbol})
+
+ def tradable_balances(self):
+ """
+ portfolio.market.privatePostReturnTradableBalances()
+ Returns tradable balances in margin
+ 'BTC_DASH': {'BTC': '0.01266999', 'DASH': '0.08574839'},
+ Je peux emprunter jusqu’à 0.08574839 DASH ou 0.01266999 BTC (une position est déjà ouverte)
+ 'BTC_CLAM': {'BTC': '0.00585143', 'CLAM': '7.79300395'},
+ Je peux emprunter 7.7 CLAM pour les vendre contre des BTC, ou emprunter 0.00585143 BTC pour acheter des CLAM
+ """
+
+ tradable_balances = self.privatePostReturnTradableBalances()
+ for symbol, balances in tradable_balances.items():
+ for currency, balance in balances.items():
+ balances[currency] = decimal.Decimal(balance)
+ return tradable_balances
+
+ def margin_summary(self):
+ """
+ portfolio.market.privatePostReturnMarginAccountSummary()
+ Returns current informations for margin
+ {'currentMargin': '1.49680968', -> marge (ne doit pas descendre sous 20% / 0.2)
+ = netValue / totalBorrowedValue
+ 'lendingFees': '0.00000000', -> fees totaux
+ 'netValue': '0.01008254', -> balance + plus-value
+ 'pl': '0.00008254', -> plus value latente (somme des positions)
+ 'totalBorrowedValue': '0.00673602', -> valeur empruntée convertie en BTC.
+ (= sum(amount * ticker[lowerAsk]) pour amount dans marginposition)
+ 'totalValue': '0.01000000'} -> balance (collateral déposé en margin)
+ """
+ summary = self.privatePostReturnMarginAccountSummary()
+
+ return {
+ "current_margin": decimal.Decimal(summary["currentMargin"]),
+ "lending_fees": decimal.Decimal(summary["lendingFees"]),
+ "gains": decimal.Decimal(summary["pl"]),
+ "total_borrowed": decimal.Decimal(summary["totalBorrowedValue"]),
+ "total": decimal.Decimal(summary["totalValue"]),
+ }
+
+ def nonce(self):
+ """
+ Wrapped to allow nonce with other libraries
+ """
+ return self.nanoseconds()
+
+ def fetch_balance(self, params={}):
+ """
+ Wrapped to get decimals
+ """
+ self.load_markets()
+ balances = self.privatePostReturnCompleteBalances(self.extend({
+ 'account': 'all',
+ }, params))
+ result = {'info': balances}
+ currencies = list(balances.keys())
+ for c in range(0, len(currencies)):
+ id = currencies[c]
+ balance = balances[id]
+ currency = self.common_currency_code(id)
+ account = {
+ 'free': decimal.Decimal(balance['available']),
+ 'used': decimal.Decimal(balance['onOrders']),
+ 'total': decimal.Decimal(0.0),
+ }
+ account['total'] = self.sum(account['free'], account['used'])
+ result[currency] = account
+ return self.parse_balance(result)
+