|
|
|
@ -620,11 +620,61 @@ class Agora(object):
|
|
|
|
|
"""
|
|
|
|
|
payload = {"tradeId": contact_id, "password": settings.Agora.Pass}
|
|
|
|
|
rtrn = self.agora._api_call(api_method=f"contact_release/{contact_id}", http_method="POST", query_values=payload)
|
|
|
|
|
|
|
|
|
|
# Check if we can withdraw funds
|
|
|
|
|
self.withdraw_funds()
|
|
|
|
|
|
|
|
|
|
return rtrn
|
|
|
|
|
|
|
|
|
|
def withdraw_funds(self):
|
|
|
|
|
"""
|
|
|
|
|
Withdraw excess funds to our XMR/BTC wallets.
|
|
|
|
|
"""
|
|
|
|
|
# wallet_xmr =
|
|
|
|
|
pass
|
|
|
|
|
totals_all = self.tx.get_total()
|
|
|
|
|
|
|
|
|
|
wallet_xmr, _ = totals_all[2]
|
|
|
|
|
|
|
|
|
|
# Get the wallet balances in USD
|
|
|
|
|
total_usd = totals_all[0][1]
|
|
|
|
|
|
|
|
|
|
profit_usd = total_usd - float(settings.Money.BaseUSD)
|
|
|
|
|
|
|
|
|
|
# Get the XMR -> USD exchange rate
|
|
|
|
|
xmr_usd = self.cg.get_price(ids="monero", vs_currencies=["USD"])
|
|
|
|
|
|
|
|
|
|
# Convert the USD total to XMR
|
|
|
|
|
profit_usd_in_xmr = float(profit_usd) / xmr_usd["monero"]["usd"]
|
|
|
|
|
|
|
|
|
|
# Check profit is above zero
|
|
|
|
|
if not profit_usd >= 0:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if not float(wallet_xmr) > profit_usd_in_xmr:
|
|
|
|
|
# Not enough funds to withdraw
|
|
|
|
|
self.log.error(
|
|
|
|
|
"Not enough funds to withdraw {profit}, as wallet only contains {wallet}", profit=profit_usd_in_xmr, wallet=wallet_xmr
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if not profit_usd >= float(settings.Money.WithdrawLimit):
|
|
|
|
|
# Not enough profit to withdraw
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
half = profit_usd_in_xmr / 2
|
|
|
|
|
|
|
|
|
|
half_rounded = round(half, 8)
|
|
|
|
|
|
|
|
|
|
# Set up the format for calling wallet_send_xmr
|
|
|
|
|
send_cast = {
|
|
|
|
|
"address": None,
|
|
|
|
|
"amount": half_rounded,
|
|
|
|
|
"password": settings.Agora.Pass,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
send_cast["address"] = settings.XMR.Wallet1
|
|
|
|
|
rtrn1 = self.agora.wallet_send_xmr(**send_cast)
|
|
|
|
|
|
|
|
|
|
send_cast["address"] = settings.XMR.Wallet2
|
|
|
|
|
rtrn2 = self.agora.wallet_send_xmr(**send_cast)
|
|
|
|
|
|
|
|
|
|
return (rtrn1["success"], rtrn2["success"])
|
|
|
|
|