Fix formatting issues

master
Mark Veidemanis 2 years ago
parent be9f9e7363
commit 0477e55361
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -1,5 +1,7 @@
from abc import ABC
import orjson
from core.lib import db, notify
# from core.lib.money import money
@ -159,19 +161,20 @@ class AggregatorClient(ABC):
return None
return stored_trade_reference.pop()
async def can_alt_lookup(self, amount, currency, reference):
amount_usd = self.money.to_usd(amount, currency)
# Amount is reliable here as it is checked by find_trade,
# so no need for stored_trade["amount"]
if float(amount_usd) > float(settings.Agora.AcceptableAltLookupUSD):
message = (
f"Amount exceeds max for {reference}"
f"Currency: {currency} | Amount: {amount}"
)
title = "Amount exceeds max for {reference}"
await notify.sendmsg(self.instance.user, message, title=title)
return False
return True
# TODO: pass platform here
# async def can_alt_lookup(self, amount, currency, reference):
# amount_usd = self.money.to_usd(amount, currency)
# # Amount is reliable here as it is checked by find_trade,
# # so no need for stored_trade["amount"]
# if float(amount_usd) > float(settings.Agora.AcceptableAltLookupUSD):
# message = (
# f"Amount exceeds max for {reference}"
# f"Currency: {currency} | Amount: {amount}"
# )
# title = "Amount exceeds max for {reference}"
# await notify.sendmsg(self.instance.user, message, title=title)
# return False
# return True
async def amount_currency_lookup(self, amount, currency, txid, reference):
log.info(f"No reference in DB refs for {reference}")
@ -288,7 +291,7 @@ class AggregatorClient(ABC):
}
db.r.hmset(f"tx.{txid}", to_store)
log.info(f"Transaction processed: {dumps(to_store, indent=2)}")
log.info(f"Transaction processed: {orjson.dumps(to_store, indent=2)}")
self.irc.sendmsg(
(
f"AUTO Incoming transaction on {subclass}: {txid} {amount}{currency} "
@ -347,10 +350,10 @@ class AggregatorClient(ABC):
):
return
platform = stored_trade["subclass"]
platform_buyer = stored_trade["buyer"]
# platform_buyer = stored_trade["buyer"]
# Check sender - we don't do anything with this yet
# sender_valid = self.antifraud.check_valid_sender(
# sender_valid = antifraud.check_valid_sender(
# reference, platform, sender, platform_buyer
# )
# log.info(f"Trade {reference} buyer {platform_buyer} valid: {sender_valid}")

@ -108,6 +108,7 @@ class AgoraClient(LocalPlatformClient, BaseClient):
"password": self.instance.password,
"otp": otp_code.now(),
}
print("SENDING", send_cast)
return # TODO
# send_cast["address"] = settings.XMR.Wallet1

@ -90,8 +90,6 @@ class AgoraDesk:
status_code = response_raw.status
else:
# response = httpx.get(url=api_call_url, headers=headers, params=query_values)
# response = treq.get(api_call_url, headers=headers, params=query_values)
cast["params"] = query_values
async with aiohttp.ClientSession() as session:
async with session.get(api_call_url, **cast) as response_raw:

@ -1,5 +1,5 @@
# Project imports
from core.lib import db, notify
from core.lib import db # , notify
from core.util import logs
log = logs.get_logger("antifraud")
@ -53,19 +53,19 @@ class AntiFraud(object):
self.ux.notify.notify_sender_name_mismatch(
reference, platform_buyer, bank_sender
)
title = "Sender name mismatch"
message = (
f"Sender name mismatch for {reference}:\n"
f"Platform buyer: {platform_buyer}"
f"Bank sender: {bank_sender}"
)
# title = "Sender name mismatch"
# message = (
# f"Sender name mismatch for {reference}:\n"
# f"Platform buyer: {platform_buyer}"
# f"Bank sender: {bank_sender}"
# )
# await notify.sendmsg(self.instance.) # TODO
return False
async def check_tx_sender(self, tx, reference):
"""
Check whether the sender of a given transaction is authorised based on the previous
transactions of the username that originated the trade reference.
Check whether the sender of a given transaction is authorised based on the
previous transactions of the username that originated the trade reference.
:param tx: the transaction ID
:param reference: the trade reference
"""
@ -103,7 +103,8 @@ class AntiFraud(object):
# auth_url = auth_url.replace("https://", "") # hack
# post_message(
# trade_id,
# f"Hi! To continue the trade, please complete the verification form: {auth_url}",
# f"Hi! To continue the trade, please complete the verification form:
# {auth_url}",
# )

@ -1,18 +1,17 @@
# Twisted imports
import asyncio
import logging
from datetime import datetime
import asyncio
import urllib3
# Other library imports
from core.models import Aggregator, Platform
from aiocoingecko import AsyncCoinGeckoAPISession
from django.conf import settings
from elasticsearch import AsyncElasticsearch
from forex_python.converter import CurrencyRates
# Other library imports
from core.models import Aggregator, Platform
# TODO: secure ES traffic properly
urllib3.disable_warnings()
@ -47,19 +46,17 @@ class Money(object):
"""
if not all([user, nordigen, agora]):
raise Exception
# I hate circular dependencies
self.nordigen = nordigen
self.agora = agora
aggregators = Aggregator.objects.filter(user=user, enabled=True)
platforms = Platform.objects.filter(user=user, enabled=True)
total = await self.get_total(aggregators, platforms, trades=True)
return total
return total
# def setup_loops(self):
# """
@ -113,26 +110,27 @@ class Money(object):
rates = self.cr.get_rates("USD")
return rates
async def get_acceptable_margins(self, platform, currency, amount):
"""
Get the minimum and maximum amounts we would accept a trade for.
:param currency: currency code
:param amount: amount
:return: (min, max)
:rtype: tuple
"""
sets = util.get_settings(platform)
rates = await self.get_rates_all()
if currency == "USD":
min_amount = amount - float(sets.AcceptableUSDMargin)
max_amount = amount + float(sets.AcceptableUSDMargin)
return (min_amount, max_amount)
amount_usd = amount / rates[currency]
min_usd = amount_usd - float(sets.AcceptableUSDMargin)
max_usd = amount_usd + float(sets.AcceptableUSDMargin)
min_local = min_usd * rates[currency]
max_local = max_usd * rates[currency]
return (min_local, max_local)
# TODO: pass platform
# async def get_acceptable_margins(self, platform, currency, amount):
# """
# Get the minimum and maximum amounts we would accept a trade for.
# :param currency: currency code
# :param amount: amount
# :return: (min, max)
# :rtype: tuple
# """
# sets = util.get_settings(platform)
# rates = await self.get_rates_all()
# if currency == "USD":
# min_amount = amount - float(sets.AcceptableUSDMargin)
# max_amount = amount + float(sets.AcceptableUSDMargin)
# return (min_amount, max_amount)
# amount_usd = amount / rates[currency]
# min_usd = amount_usd - float(sets.AcceptableUSDMargin)
# max_usd = amount_usd + float(sets.AcceptableUSDMargin)
# min_local = min_usd * rates[currency]
# max_local = max_usd * rates[currency]
# return (min_local, max_local)
async def get_minmax(self, min_usd, max_usd, asset, currency):
rates = await self.get_rates_all()
@ -246,7 +244,7 @@ class Money(object):
total = sum(total)
return total
async def gather_wallet_balance_xmr(self, platforms):
"""
Gather the total XMR of the specified platforms.
@ -274,19 +272,18 @@ class Money(object):
btc = [float(x["response"]["data"]["total"]["balance"]) for x in btc_pre]
btc = sum(btc)
return btc
def gather_base_usd(self, platforms):
total = 0
for platform in platforms:
total += platform.base_usd
return total
def gather_withdrawal_limit(self, platforms):
total = 0
for platform in platforms:
total += platform.withdrawal_trigger
return total
# TODO: possibly refactor this into smaller functions which don't return as much
# check if this is all really needed in the corresponding withdraw function
@ -334,7 +331,6 @@ class Money(object):
profit = total_usd - total_base_usd
# Convert the total USD price to GBP and SEK
price_sek = rates["SEK"] * total_usd
price_usd = total_usd
@ -353,8 +349,6 @@ class Money(object):
total_profit = total_with_trades - total_base_usd
# cast = (
# (
# price_sek,

@ -3,7 +3,7 @@ import asyncio
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from django.core.management.base import BaseCommand
from core.clients.aggregators.nordigen import NordigenClient
# from core.clients.aggregators.nordigen import NordigenClient
from core.clients.platforms.agora import AgoraClient
from core.models import Aggregator, Platform
from core.util import logs

@ -13,7 +13,6 @@ from mixins.views import (
from two_factor.views.mixins import OTPRequiredMixin
from core.clients.aggregators.nordigen import NordigenClient
from core.forms import AggregatorForm
from core.models import Aggregator
from core.util import logs

@ -121,5 +121,7 @@ class BanksTransactions(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
return self.render_to_response(context)
run = synchronize_async_helper(NordigenClient(aggregator))
transactions = synchronize_async_helper(run.get_transactions(account_id, pending=True))
transactions = synchronize_async_helper(
run.get_transactions(account_id, pending=True)
)
return transactions

@ -1,26 +1,16 @@
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 (
ObjectCreate,
ObjectDelete,
ObjectList,
ObjectRead,
ObjectUpdate,
)
from mixins.views import ObjectRead
from two_factor.views.mixins import OTPRequiredMixin
from core.clients.aggregators.nordigen import NordigenClient
from core.clients.platforms.agora import AgoraClient
from core.util import logs
from core.models import Platform
from core.lib.money import money
from core.util import logs
from core.views.helpers import synchronize_async_helper
log = logs.get_logger(__name__)
class Profit(LoginRequiredMixin, OTPRequiredMixin, ObjectRead):
context_object_name_singular = "profit"
context_object_name = "profit"
@ -28,25 +18,26 @@ class Profit(LoginRequiredMixin, OTPRequiredMixin, ObjectRead):
# detail_template = "partials/profit-info.html"
def get_object(self, **kwargs):
res = synchronize_async_helper(money.check_all(user=self.request.user, nordigen=NordigenClient, agora=AgoraClient))
res = synchronize_async_helper(
money.check_all(
user=self.request.user, nordigen=NordigenClient, agora=AgoraClient
)
)
print("RES", res)
results = {
"Bank balance total": res["total_sinks_usd"],
"Platform balance total": res["total_usd_agora"],
"Open trade value": res["open_trade_value"],
"Total": res["total_with_trades"],
"Profit": res["total_profit"],
"Remaining before withdrawal": res["total_remaining"],
"Total (without open trades)": res["total_usd"],
"Profit (without open trades)": res["profit"],
"Remaining before withdrawal (without open trades)": res["remaining"],
"Base balance required": res["total_base_usd"],
"Amount above base balance to trigger withdrawal":
res["total_withdrawal_limit"],
"Amount above base balance to trigger withdrawal": res[
"total_withdrawal_limit"
],
"Withdrawal trigger": res["withdraw_threshold"],
}
return results
return results

@ -239,7 +239,7 @@ class Money(util.Base):
agora_wallet_xmr = yield self.agora.api.wallet_balance_xmr()
agora_wallet_btc = yield self.agora.api.wallet_balance()
lbtc_wallet_btc = yield self.lbtc.api.wallet_balance()
total_xmr_agora = agora_wallet_xmr["response"]["data"]["total"]["balance"]
total_btc_agora = agora_wallet_btc["response"]["data"]["total"]["balance"]
total_btc_lbtc = lbtc_wallet_btc["response"]["data"]["total"]["balance"]

Loading…
Cancel
Save