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

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

@ -90,8 +90,6 @@ class AgoraDesk:
status_code = response_raw.status status_code = response_raw.status
else: 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 cast["params"] = query_values
async with aiohttp.ClientSession() as session: async with aiohttp.ClientSession() as session:
async with session.get(api_call_url, **cast) as response_raw: async with session.get(api_call_url, **cast) as response_raw:

@ -1,5 +1,5 @@
# Project imports # Project imports
from core.lib import db, notify from core.lib import db # , notify
from core.util import logs from core.util import logs
log = logs.get_logger("antifraud") log = logs.get_logger("antifraud")
@ -53,19 +53,19 @@ class AntiFraud(object):
self.ux.notify.notify_sender_name_mismatch( self.ux.notify.notify_sender_name_mismatch(
reference, platform_buyer, bank_sender reference, platform_buyer, bank_sender
) )
title = "Sender name mismatch" # title = "Sender name mismatch"
message = ( # message = (
f"Sender name mismatch for {reference}:\n" # f"Sender name mismatch for {reference}:\n"
f"Platform buyer: {platform_buyer}" # f"Platform buyer: {platform_buyer}"
f"Bank sender: {bank_sender}" # f"Bank sender: {bank_sender}"
) # )
# await notify.sendmsg(self.instance.) # TODO # await notify.sendmsg(self.instance.) # TODO
return False return False
async def check_tx_sender(self, tx, reference): async def check_tx_sender(self, tx, reference):
""" """
Check whether the sender of a given transaction is authorised based on the previous Check whether the sender of a given transaction is authorised based on the
transactions of the username that originated the trade reference. previous transactions of the username that originated the trade reference.
:param tx: the transaction ID :param tx: the transaction ID
:param reference: the trade reference :param reference: the trade reference
""" """
@ -103,7 +103,8 @@ class AntiFraud(object):
# auth_url = auth_url.replace("https://", "") # hack # auth_url = auth_url.replace("https://", "") # hack
# post_message( # post_message(
# trade_id, # 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 # Twisted imports
import asyncio
import logging import logging
from datetime import datetime from datetime import datetime
import asyncio
import urllib3 import urllib3
# Other library imports
from core.models import Aggregator, Platform
from aiocoingecko import AsyncCoinGeckoAPISession from aiocoingecko import AsyncCoinGeckoAPISession
from django.conf import settings from django.conf import settings
from elasticsearch import AsyncElasticsearch from elasticsearch import AsyncElasticsearch
from forex_python.converter import CurrencyRates from forex_python.converter import CurrencyRates
# Other library imports
from core.models import Aggregator, Platform
# TODO: secure ES traffic properly # TODO: secure ES traffic properly
urllib3.disable_warnings() urllib3.disable_warnings()
@ -59,8 +58,6 @@ class Money(object):
return total return total
# def setup_loops(self): # def setup_loops(self):
# """ # """
# Set up the LoopingCalls to get the balance so we have data in ES. # Set up the LoopingCalls to get the balance so we have data in ES.
@ -113,26 +110,27 @@ class Money(object):
rates = self.cr.get_rates("USD") rates = self.cr.get_rates("USD")
return rates return rates
async def get_acceptable_margins(self, platform, currency, amount): # 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 # Get the minimum and maximum amounts we would accept a trade for.
:param amount: amount # :param currency: currency code
:return: (min, max) # :param amount: amount
:rtype: tuple # :return: (min, max)
""" # :rtype: tuple
sets = util.get_settings(platform) # """
rates = await self.get_rates_all() # sets = util.get_settings(platform)
if currency == "USD": # rates = await self.get_rates_all()
min_amount = amount - float(sets.AcceptableUSDMargin) # if currency == "USD":
max_amount = amount + float(sets.AcceptableUSDMargin) # min_amount = amount - float(sets.AcceptableUSDMargin)
return (min_amount, max_amount) # max_amount = amount + float(sets.AcceptableUSDMargin)
amount_usd = amount / rates[currency] # return (min_amount, max_amount)
min_usd = amount_usd - float(sets.AcceptableUSDMargin) # amount_usd = amount / rates[currency]
max_usd = amount_usd + float(sets.AcceptableUSDMargin) # min_usd = amount_usd - float(sets.AcceptableUSDMargin)
min_local = min_usd * rates[currency] # max_usd = amount_usd + float(sets.AcceptableUSDMargin)
max_local = max_usd * rates[currency] # min_local = min_usd * rates[currency]
return (min_local, max_local) # max_local = max_usd * rates[currency]
# return (min_local, max_local)
async def get_minmax(self, min_usd, max_usd, asset, currency): async def get_minmax(self, min_usd, max_usd, asset, currency):
rates = await self.get_rates_all() rates = await self.get_rates_all()
@ -287,7 +285,6 @@ class Money(object):
total += platform.withdrawal_trigger total += platform.withdrawal_trigger
return total return total
# TODO: possibly refactor this into smaller functions which don't return as much # 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 # check if this is all really needed in the corresponding withdraw function
async def get_total(self, aggregators, platforms, trades=False): async def get_total(self, aggregators, platforms, trades=False):
@ -334,7 +331,6 @@ class Money(object):
profit = total_usd - total_base_usd profit = total_usd - total_base_usd
# Convert the total USD price to GBP and SEK # Convert the total USD price to GBP and SEK
price_sek = rates["SEK"] * total_usd price_sek = rates["SEK"] * total_usd
price_usd = total_usd price_usd = total_usd
@ -353,8 +349,6 @@ class Money(object):
total_profit = total_with_trades - total_base_usd total_profit = total_with_trades - total_base_usd
# cast = ( # cast = (
# ( # (
# price_sek, # price_sek,

@ -3,7 +3,7 @@ import asyncio
from apscheduler.schedulers.asyncio import AsyncIOScheduler from apscheduler.schedulers.asyncio import AsyncIOScheduler
from django.core.management.base import BaseCommand 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.clients.platforms.agora import AgoraClient
from core.models import Aggregator, Platform from core.models import Aggregator, Platform
from core.util import logs from core.util import logs

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

@ -121,5 +121,7 @@ class BanksTransactions(LoginRequiredMixin, OTPRequiredMixin, ObjectList):
return self.render_to_response(context) return self.render_to_response(context)
run = synchronize_async_helper(NordigenClient(aggregator)) 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 return transactions

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