Add MarketTicks endpoint /api/ticks. Fix do_accounting.

This commit is contained in:
Reckless_Satoshi 2022-06-21 12:29:07 -07:00
parent e525b84c9e
commit bd70d94d4a
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
4 changed files with 29 additions and 6 deletions

View File

@ -1,5 +1,5 @@
from rest_framework import serializers
from .models import Order
from .models import MarketTick, Order
class ListOrderSerializer(serializers.ModelSerializer):
@ -132,4 +132,18 @@ class ClaimRewardSerializer(serializers.Serializer):
default=None)
class PriceSerializer(serializers.Serializer):
pass
pass
class TickSerializer(serializers.ModelSerializer):
class Meta:
model = MarketTick
fields = (
"timestamp",
"currency",
"volume",
"price",
"premium",
"fee",
)
depth = 1

View File

@ -1,5 +1,5 @@
from django.urls import path
from .views import MakerView, OrderView, UserView, BookView, InfoView, RewardView, PriceView, LimitView, HistoricalView
from .views import MakerView, OrderView, UserView, BookView, InfoView, RewardView, PriceView, LimitView, HistoricalView, TickView
urlpatterns = [
path("make/", MakerView.as_view()),
@ -10,10 +10,10 @@ urlpatterns = [
),
path("user/", UserView.as_view()),
path("book/", BookView.as_view()),
# path('robot/') # Profile Info
path("info/", InfoView.as_view()),
path("price/", PriceView.as_view()),
path("limits/", LimitView.as_view()),
path("reward/", RewardView.as_view()),
path("historical/", HistoricalView.as_view()),
path("ticks/", TickView.as_view()),
]

View File

@ -11,7 +11,7 @@ from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from django.contrib.auth.models import User
from api.serializers import ListOrderSerializer, MakeOrderSerializer, UpdateOrderSerializer, ClaimRewardSerializer, PriceSerializer, UserGenSerializer
from api.serializers import ListOrderSerializer, MakeOrderSerializer, UpdateOrderSerializer, ClaimRewardSerializer, PriceSerializer, UserGenSerializer, TickSerializer
from api.models import LNPayment, MarketTick, OnchainPayment, Order, Currency, Profile
from control.models import AccountingDay, BalanceLog
from api.logics import Logics
@ -975,6 +975,15 @@ class PriceView(CreateAPIView):
return Response(payload, status.HTTP_200_OK)
class TickView(CreateAPIView):
queryset = MarketTick.objects.all()
serializer_class = TickSerializer
def get(self, request):
data = self.serializer_class(self.queryset.all(), many=True, read_only=True).data
return Response(data, status=status.HTTP_200_OK)
class LimitView(ListAPIView):
def get(self, request):

View File

@ -82,7 +82,7 @@ def do_accounting():
for payout_tx in payouts_tx:
escrows_settled += payout_tx.order_paid_TX.trade_escrow.num_satoshis
payouts_paid += payout_tx.sent_satoshis
costs += payout_tx.fee
costs += payout_tx.mining_fee_sats
# account for those orders where bonds were lost