Refactor and add base USD and withdrawal triggers

master
Mark Veidemanis 2 years ago
parent 7f088d15c2
commit 96858da88a
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -20,7 +20,7 @@ from django.contrib.auth.views import LogoutView
from django.urls import include, path
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

@ -763,7 +763,7 @@ class LocalPlatformClient(ABC):
return all(actioned)
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}"
log.info(logmessage)
title = "Releasing escrow"
@ -782,10 +782,10 @@ class LocalPlatformClient(ABC):
await notify.sendmsg(self.instance.user, logmessage, title=title)
return
# Parse the escrow release response
message = rtrn["message"]
# message_long = rtrn["response"]["data"]["message"]
self.irc.sendmsg(f"{dumps(message)}")
# # Parse the escrow release response
# message = rtrn["message"]
# # message_long = rtrn["response"]["data"]["message"]
# self.irc.sendmsg(f"{dumps(message)}")
async def update_trade_tx(self, reference, txid):
"""
@ -1180,7 +1180,8 @@ class LocalPlatformClient(ABC):
return False
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.
# We will disable ads we can't support.
@ -1200,9 +1201,11 @@ class LocalPlatformClient(ABC):
# 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:
# asset = ad[0]

@ -3,7 +3,6 @@ from pyotp import TOTP
from core.clients.base import BaseClient
from core.clients.platform import LocalPlatformClient
from core.lib.money import Money
class AgoraClient(LocalPlatformClient, BaseClient):
@ -57,7 +56,7 @@ class AgoraClient(LocalPlatformClient, BaseClient):
return False
# 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
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)
return
if not profit_usd >= float(settings.Money.WithdrawLimit):
if not profit_usd >= self.instance.withdrawal_trigger:
# Not enough profit to withdraw
return
@ -106,15 +105,16 @@ class AgoraClient(LocalPlatformClient, BaseClient):
send_cast = {
"address": None,
"amount": half_rounded,
"password": settings.Agora.Pass,
"password": self.instance.password,
"otp": otp_code.now(),
}
send_cast["address"] = settings.XMR.Wallet1
rtrn1 = await self.api.wallet_send_xmr(**send_cast)
return # TODO
# send_cast["address"] = settings.XMR.Wallet1
# rtrn1 = await self.api.wallet_send_xmr(**send_cast)
send_cast["address"] = settings.XMR.Wallet2
rtrn2 = await self.api.wallet_send_xmr(**send_cast)
# send_cast["address"] = settings.XMR.Wallet2
# rtrn2 = await self.api.wallet_send_xmr(**send_cast)
self.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}")
self.ux.notify.notify_withdrawal(half_rounded)
# self.irc.sendmsg(f"Withdrawal: {rtrn1['success']} | {rtrn2['success']}")
# self.ux.notify.notify_withdrawal(half_rounded)

@ -114,6 +114,8 @@ class PlatformForm(RestrictedFormMixin, ModelForm):
"max_trade_size_usd",
"accept_within_usd",
"no_reference_amount_check_max_usd",
"base_usd",
"withdrawal_trigger",
"enabled",
)
help_texts = {
@ -134,6 +136,8 @@ class PlatformForm(RestrictedFormMixin, ModelForm):
"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.",
"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.",
}

@ -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)
platform_ad_ids = models.JSONField(default=dict)
base_usd = models.FloatField(default=2800)
withdrawal_trigger = models.FloatField(default=200)
enabled = models.BooleanField(default=True)
def __str__(self):

@ -6,7 +6,6 @@ from mixins.views import (
ObjectCreate,
ObjectDelete,
ObjectList,
ObjectRead,
ObjectUpdate,
)
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.forms import AdForm
from core.models import Ad
from core.util import logs
from core.views.helpers import synchronize_async_helper
class AdNuke(LoginRequiredMixin, OTPRequiredMixin, View):
template_name = "mixins/partials/notify.html"
@ -30,6 +29,7 @@ class AdNuke(LoginRequiredMixin, OTPRequiredMixin, View):
context = {"class": "success", "message": "Nuking ads"}
return render(request, self.template_name, context)
class AdDist(LoginRequiredMixin, OTPRequiredMixin, View):
template_name = "mixins/partials/notify.html"

@ -1,8 +1,4 @@
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,
ObjectCreate,
ObjectDelete,

Loading…
Cancel
Save