|
|
|
@ -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()
|
|
|
|
|
|
|
|
|
@ -59,8 +58,6 @@ class Money(object):
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
@ -287,7 +285,6 @@ class Money(object):
|
|
|
|
|
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
|
|
|
|
|
async def get_total(self, aggregators, platforms, trades=False):
|
|
|
|
@ -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,
|
|
|
|
|