mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-21 08:11:36 +02:00
feat: add current price and other info to DCA strategy detail
This commit is contained in:
@@ -7,7 +7,7 @@ from django.template.defaultfilters import date
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from apps.currencies.utils.convert import convert
|
||||
from apps.currencies.utils.convert import convert, get_exchange_rate
|
||||
|
||||
|
||||
class DCAStrategy(models.Model):
|
||||
@@ -133,6 +133,18 @@ class DCAStrategy(models.Model):
|
||||
"amounts_bought": amounts_bought,
|
||||
}
|
||||
|
||||
def current_price(self):
|
||||
exchange_rate = get_exchange_rate(
|
||||
from_currency=self.payment_currency,
|
||||
to_currency=self.target_currency,
|
||||
date=timezone.localtime(timezone.now()),
|
||||
)
|
||||
|
||||
if exchange_rate:
|
||||
return exchange_rate.effective_rate, exchange_rate.date
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
class DCAEntry(models.Model):
|
||||
strategy = models.ForeignKey(
|
||||
|
||||
Reference in New Issue
Block a user