Fix formatting issues
This commit is contained in:
@@ -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,20 +46,18 @@ 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
|
||||
|
||||
|
||||
|
||||
# def setup_loops(self):
|
||||
# """
|
||||
# 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")
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user