Coverage for django_napse/api/wallets/serializers/currency_serializer.py: 91%
11 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
1from rest_framework import serializers
3from django_napse.core.models import Currency
4from django_napse.core.models.bots.controller import Controller
7class CurrencySerializer(serializers.ModelSerializer):
8 value = serializers.SerializerMethodField(read_only=True)
10 class Meta:
11 model = Currency
12 fields = [
13 "mbp",
14 "ticker",
15 "amount",
16 "value",
17 ]
18 read_only_fields = fields
20 def get_value(self, instance):
21 return instance.amount * Controller.get_asset_price(
22 exchange_account=instance.wallet.exchange_account,
23 base=instance.ticker,
24 )