Skip to content

Commit

Permalink
add orders in bot_serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenepix committed Jan 18, 2024
1 parent 8ceb1fc commit b068a75
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 17 additions & 1 deletion django_napse/api/bots/serializers/bot_serializers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from rest_framework import serializers
from rest_framework.fields import empty

from django_napse.api.orders.serializers import OrderSerializer
from django_napse.api.wallets.serializers import WalletSerializer
from django_napse.core.models import Bot, BotHistory, ConnectionWallet
from django_napse.core.models import Bot, BotHistory, ConnectionWallet, Order


class BotSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -56,6 +57,7 @@ class BotDetailSerializer(serializers.ModelSerializer):

statistics = serializers.SerializerMethodField(read_only=True)
wallet = serializers.SerializerMethodField(read_only=True)
orders = serializers.SerializerMethodField(read_only=True)

class Meta:
model = Bot
Expand Down Expand Up @@ -131,3 +133,17 @@ def _update_merged_wallet(index: int, currency: str, merged_wallet) -> None:
_update_merged_wallet(index, currency, merged_wallet)

return merged_wallet

def get_orders(self, instance):
if self.space is None:
return OrderSerializer(
Order.objects.filter(connection__bot=instance),
many=True,
).data
return OrderSerializer(
Order.objects.filter(
connection__bot=instance,
connection__owner__owner=self.space.wallet,
),
many=True,
).data
1 change: 0 additions & 1 deletion django_napse/api/orders/serializers/order_serializer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from rest_framework import serializers

from django_napse.core.models import Order
from django_napse.core.models.bots.controller import Controller
from django_napse.utils.constants import SIDES


Expand Down

0 comments on commit b068a75

Please sign in to comment.