Refactor and add base USD and withdrawal triggers
This commit is contained in:
parent
7f088d15c2
commit
96858da88a
|
@ -20,7 +20,7 @@ from django.contrib.auth.views import LogoutView
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from two_factor.urls import urlpatterns as tf_urls
|
from two_factor.urls import urlpatterns as tf_urls
|
||||||
|
|
||||||
from core.views import aggregators, banks, base, notifications, platforms, ads
|
from core.views import ads, aggregators, banks, base, notifications, platforms
|
||||||
|
|
||||||
# from core.views.stripe_callbacks import Callback
|
# from core.views.stripe_callbacks import Callback
|
||||||
|
|
||||||
|
|
|
@ -763,7 +763,7 @@ class LocalPlatformClient(ABC):
|
||||||
return all(actioned)
|
return all(actioned)
|
||||||
|
|
||||||
async def release_funds(self, trade_id, reference):
|
async def release_funds(self, trade_id, reference):
|
||||||
stored_trade = await db.get_ref(reference)
|
# stored_trade = await db.get_ref(reference)
|
||||||
logmessage = f"All checks passed, releasing funds for {trade_id} {reference}"
|
logmessage = f"All checks passed, releasing funds for {trade_id} {reference}"
|
||||||
log.info(logmessage)
|
log.info(logmessage)
|
||||||
title = "Releasing escrow"
|
title = "Releasing escrow"
|
||||||
|
@ -782,10 +782,10 @@ class LocalPlatformClient(ABC):
|
||||||
await notify.sendmsg(self.instance.user, logmessage, title=title)
|
await notify.sendmsg(self.instance.user, logmessage, title=title)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Parse the escrow release response
|
# # Parse the escrow release response
|
||||||
message = rtrn["message"]
|
# message = rtrn["message"]
|
||||||
# message_long = rtrn["response"]["data"]["message"]
|
# # message_long = rtrn["response"]["data"]["message"]
|
||||||
self.irc.sendmsg(f"{dumps(message)}")
|
# self.irc.sendmsg(f"{dumps(message)}")
|
||||||
|
|
||||||
async def update_trade_tx(self, reference, txid):
|
async def update_trade_tx(self, reference, txid):
|
||||||
"""
|
"""
|
||||||
|
@ -1180,7 +1180,8 @@ class LocalPlatformClient(ABC):
|
||||||
return False
|
return False
|
||||||
return currency_account_info_map[currency]
|
return currency_account_info_map[currency]
|
||||||
|
|
||||||
# def _distribute_account_details(self, platform, currencies=None, account_info=None):
|
# def _distribute_account_details(self, platform, currencies=
|
||||||
|
# None, account_info=None):
|
||||||
# """
|
# """
|
||||||
# Distribute account details for ads.
|
# Distribute account details for ads.
|
||||||
# We will disable ads we can't support.
|
# We will disable ads we can't support.
|
||||||
|
@ -1200,9 +1201,11 @@ class LocalPlatformClient(ABC):
|
||||||
|
|
||||||
# our_ads = self.enum_ads()
|
# our_ads = self.enum_ads()
|
||||||
|
|
||||||
# supported_ads = [ad for ad in our_ads if ad[3] in supported_currencies]
|
# supported_ads = [ad for ad in our_ads if ad[3] in supported_curr
|
||||||
|
# encies]
|
||||||
|
|
||||||
# not_supported_ads = [ad for ad in our_ads if ad[3] not in supported_currencies]
|
# not_supported_ads = [ad for ad in our_ads if ad[3] not in supporte
|
||||||
|
# d_currencies]
|
||||||
|
|
||||||
# for ad in supported_ads:
|
# for ad in supported_ads:
|
||||||
# asset = ad[0]
|
# asset = ad[0]
|
||||||
|
|
|
@ -3,7 +3,6 @@ from pyotp import TOTP
|
||||||
|
|
||||||
from core.clients.base import BaseClient
|
from core.clients.base import BaseClient
|
||||||
from core.clients.platform import LocalPlatformClient
|
from core.clients.platform import LocalPlatformClient
|
||||||
from core.lib.money import Money
|
|
||||||
|
|
||||||
|
|
||||||
class AgoraClient(LocalPlatformClient, BaseClient):
|
class AgoraClient(LocalPlatformClient, BaseClient):
|
||||||
|
@ -57,7 +56,7 @@ class AgoraClient(LocalPlatformClient, BaseClient):
|
||||||
return False
|
return False
|
||||||
# total_usd += total_trades_usd
|
# total_usd += total_trades_usd
|
||||||
|
|
||||||
profit_usd = total_usd - float(settings.Money.BaseUSD)
|
profit_usd = total_usd - self.instance.base_usd
|
||||||
# Get the XMR -> USD exchange rate
|
# Get the XMR -> USD exchange rate
|
||||||
xmr_usd = self.money.cg.get_price(ids="monero", vs_currencies=["USD"])
|
xmr_usd = self.money.cg.get_price(ids="monero", vs_currencies=["USD"])
|
||||||
|
|
||||||
|
@ -85,7 +84,7 @@ class AgoraClient(LocalPlatformClient, BaseClient):
|
||||||
self.ux.notify.notify_need_topup(profit_usd_in_xmr)
|
self.ux.notify.notify_need_topup(profit_usd_in_xmr)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not profit_usd >= float(settings.Money.WithdrawLimit):
|
if not profit_usd >= self.instance.withdrawal_trigger:
|
||||||
# Not enough profit to withdraw
|
# Not enough profit to withdraw
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -106,15 +105,16 @@ class AgoraClient(LocalPlatformClient, BaseClient):
|
||||||
send_cast = {
|
send_cast = {
|
||||||
"address": None,
|
"address": None,
|
||||||
"amount": half_rounded,
|
"amount": half_rounded,
|
||||||
"password": settings.Agora.Pass,
|
"password": self.instance.password,
|
||||||
"otp": otp_code.now(),
|
"otp": otp_code.now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
send_cast["address"] = settings.XMR.Wallet1
|
return # TODO
|
||||||
rtrn1 = await self.api.wallet_send_xmr(**send_cast)
|
# send_cast["address"] = settings.XMR.Wallet1
|
||||||
|
# rtrn1 = await self.api.wallet_send_xmr(**send_cast)
|
||||||
|
|
||||||
send_cast["address"] = settings.XMR.Wallet2
|
# send_cast["address"] = settings.XMR.Wallet2
|
||||||
rtrn2 = await self.api.wallet_send_xmr(**send_cast)
|
# rtrn2 = await self.api.wallet_send_xmr(**send_cast)
|
||||||
|
|
||||||
self.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}")
|
# self.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}")
|
||||||
self.ux.notify.notify_withdrawal(half_rounded)
|
# self.ux.notify.notify_withdrawal(half_rounded)
|
||||||
|
|
|
@ -114,6 +114,8 @@ class PlatformForm(RestrictedFormMixin, ModelForm):
|
||||||
"max_trade_size_usd",
|
"max_trade_size_usd",
|
||||||
"accept_within_usd",
|
"accept_within_usd",
|
||||||
"no_reference_amount_check_max_usd",
|
"no_reference_amount_check_max_usd",
|
||||||
|
"base_usd",
|
||||||
|
"withdrawal_trigger",
|
||||||
"enabled",
|
"enabled",
|
||||||
)
|
)
|
||||||
help_texts = {
|
help_texts = {
|
||||||
|
@ -134,6 +136,8 @@ class PlatformForm(RestrictedFormMixin, ModelForm):
|
||||||
"max_trade_size_usd": "The maximum trade size in USD.",
|
"max_trade_size_usd": "The maximum trade size in USD.",
|
||||||
"accept_within_usd": "When a trade is wrong by less than this amount, it will be accepted.",
|
"accept_within_usd": "When a trade is wrong by less than this amount, it will be accepted.",
|
||||||
"no_reference_amount_check_max_usd": "When ticked, when no reference was found and a trade is higher than this amount, we will not accept payment even if it is the only one with this amount.",
|
"no_reference_amount_check_max_usd": "When ticked, when no reference was found and a trade is higher than this amount, we will not accept payment even if it is the only one with this amount.",
|
||||||
|
"base_usd": "The amount in USD to keep in the platform.",
|
||||||
|
"withdrawal_trigger": "The amount above the base USD to trigger a withdrawal.",
|
||||||
"enabled": "Whether or not the platform connection is enabled.",
|
"enabled": "Whether or not the platform connection is enabled.",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 4.1.7 on 2023-03-10 15:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0014_ad_account_whitelist'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='platform',
|
||||||
|
name='base_usd',
|
||||||
|
field=models.FloatField(default=2800),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='platform',
|
||||||
|
name='withdrawal_trigger',
|
||||||
|
field=models.FloatField(default=200),
|
||||||
|
),
|
||||||
|
]
|
|
@ -123,6 +123,9 @@ class Platform(models.Model):
|
||||||
last_messages = models.JSONField(default=dict)
|
last_messages = models.JSONField(default=dict)
|
||||||
platform_ad_ids = models.JSONField(default=dict)
|
platform_ad_ids = models.JSONField(default=dict)
|
||||||
|
|
||||||
|
base_usd = models.FloatField(default=2800)
|
||||||
|
withdrawal_trigger = models.FloatField(default=200)
|
||||||
|
|
||||||
enabled = models.BooleanField(default=True)
|
enabled = models.BooleanField(default=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -6,7 +6,6 @@ from mixins.views import (
|
||||||
ObjectCreate,
|
ObjectCreate,
|
||||||
ObjectDelete,
|
ObjectDelete,
|
||||||
ObjectList,
|
ObjectList,
|
||||||
ObjectRead,
|
|
||||||
ObjectUpdate,
|
ObjectUpdate,
|
||||||
)
|
)
|
||||||
from two_factor.views.mixins import OTPRequiredMixin
|
from two_factor.views.mixins import OTPRequiredMixin
|
||||||
|
@ -14,9 +13,9 @@ from two_factor.views.mixins import OTPRequiredMixin
|
||||||
from core.clients.platforms.agora import AgoraClient
|
from core.clients.platforms.agora import AgoraClient
|
||||||
from core.forms import AdForm
|
from core.forms import AdForm
|
||||||
from core.models import Ad
|
from core.models import Ad
|
||||||
from core.util import logs
|
|
||||||
from core.views.helpers import synchronize_async_helper
|
from core.views.helpers import synchronize_async_helper
|
||||||
|
|
||||||
|
|
||||||
class AdNuke(LoginRequiredMixin, OTPRequiredMixin, View):
|
class AdNuke(LoginRequiredMixin, OTPRequiredMixin, View):
|
||||||
template_name = "mixins/partials/notify.html"
|
template_name = "mixins/partials/notify.html"
|
||||||
|
|
||||||
|
@ -30,6 +29,7 @@ class AdNuke(LoginRequiredMixin, OTPRequiredMixin, View):
|
||||||
context = {"class": "success", "message": "Nuking ads"}
|
context = {"class": "success", "message": "Nuking ads"}
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
class AdDist(LoginRequiredMixin, OTPRequiredMixin, View):
|
class AdDist(LoginRequiredMixin, OTPRequiredMixin, View):
|
||||||
template_name = "mixins/partials/notify.html"
|
template_name = "mixins/partials/notify.html"
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.http import HttpResponse
|
|
||||||
from django.shortcuts import render
|
|
||||||
from django.urls import reverse
|
|
||||||
from django.views import View
|
|
||||||
from mixins.views import ( # ObjectRead,
|
from mixins.views import ( # ObjectRead,
|
||||||
ObjectCreate,
|
ObjectCreate,
|
||||||
ObjectDelete,
|
ObjectDelete,
|
||||||
|
|
Loading…
Reference in New Issue