+ pending_pl.setdefault(margin_balance["baseCurrency"], 0)
+ pending_pl[margin_balance["baseCurrency"]] += margin_balance["pl"]
+
+ # J’emprunte 0.12062983 que je revends à 0.06003598 BTC/DASH, soit 0.00724213 BTC.
+ # Sur ces 0.00724213 BTC je récupère 0.00724213*(1-0.0015) = 0.00723127 BTC
+ #
+ # -> ordertrades ne tient pas compte des fees
+ # amount = montant vendu (un seul mouvement)
+ # rate = à ce taux
+ # total = total en BTC (pour ce mouvement)
+ # -> marginposition:
+ # amount = ce que je dois rendre
+ # basePrice = prix de vente en tenant compte des fees
+ # (amount * basePrice = la quantité de BTC que j’ai effectivement
+ # reçue à erreur d’arrondi près, utiliser plutôt "total")
+ # total = la quantité de BTC que j’ai reçue
+ # pl = plus value actuelle si je rachetais tout de suite
+ # -> marginaccountsummary:
+ # currentMargin = La marge actuelle (= netValue/totalBorrowedValue)
+ # totalValue = BTC actuellement en margin (déposé)
+ # totalBorrowedValue = sum (amount * ticker[lowestAsk])
+ # pl = sum(pl)
+ # netValue = BTC actuellement en margin (déposé) + pl
+ # Exemple:
+ # In [38]: m.ccxt.private_post_returnordertrades({"orderNumber": "XXXXXXXXXXXX"})
+ # Out[38]:
+ # [{'amount': '0.11882982',
+ # 'currencyPair': 'BTC_DASH',
+ # 'date': '2018-02-26 22:48:35',
+ # 'fee': '0.00150000',
+ # 'globalTradeID': 348891380,
+ # 'rate': '0.06003598',
+ # 'total': '0.00713406',
+ # 'tradeID': 9634443,
+ # 'type': 'sell'},
+ # {'amount': '0.00180000',
+ # 'currencyPair': 'BTC_DASH',
+ # 'date': '2018-02-26 22:48:30',
+ # 'fee': '0.00150000',
+ # 'globalTradeID': 348891375,
+ # 'rate': '0.06003598',
+ # 'total': '0.00010806',
+ # 'tradeID': 9634442,
+ # 'type': 'sell'}]
+ #
+ # In [51]: m.ccxt.privatePostGetMarginPosition({"currencyPair": "BTC_DASH"})
+ # Out[51]:
+ # {'amount': '-0.12062982',
+ # 'basePrice': '0.05994587',
+ # 'lendingFees': '0.00000000',
+ # 'liquidationPrice': '0.15531479',
+ # 'pl': '0.00000122',
+ # 'total': '0.00723126',
+ # 'type': 'short'}
+ # In [52]: m.ccxt.privatePostGetMarginPosition({"currencyPair": "BTC_BTS"})
+ # Out[52]:
+ # {'amount': '-332.97159188',
+ # 'basePrice': '0.00002171',
+ # 'lendingFees': '0.00000000',
+ # 'liquidationPrice': '0.00005543',
+ # 'pl': '0.00029548',
+ # 'total': '0.00723127',
+ # 'type': 'short'}
+ #
+ # In [53]: m.ccxt.privatePostReturnMarginAccountSummary()
+ # Out[53]:
+ # {'currentMargin': '1.04341991',
+ # 'lendingFees': '0.00000000',
+ # 'netValue': '0.01478093',
+ # 'pl': '0.00029666',
+ # 'totalBorrowedValue': '0.01416585',
+ # 'totalValue': '0.01448427'}
+