This commit is contained in:
2025-11-07 17:43:37 +01:00
parent c3f837b90f
commit a645c87020
47 changed files with 238 additions and 2203 deletions

View File

@@ -3,4 +3,7 @@ from django.apps import AppConfig
class GopayConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'gopay'
# Must be the full dotted path to this app package
name = 'thirdparty.gopay'
# Optional short label used in DB table names and admin
label = 'gopay'

View File

@@ -1,11 +1,2 @@
# thirdparty/trading212/serializers.py
from rest_framework import serializers
class Trading212AccountCashSerializer(serializers.Serializer):
blocked = serializers.FloatField()
free = serializers.FloatField()
invested = serializers.FloatField()
pieCash = serializers.FloatField()
ppl = serializers.FloatField()
result = serializers.FloatField()
total = serializers.FloatField()

View File

@@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

View File

@@ -1,6 +1,7 @@
from django.urls import path
from .views import Trading212AccountCashView # Replace with actual view class
from .views import Trading212AccountCashView, Trading212SummaryView
urlpatterns = [
path('your-endpoint/', Trading212AccountCashView.as_view(), name='trading212-endpoint'),
path('equity/cash/', Trading212AccountCashView.as_view(), name='trading212-cash'),
path('equity/summary/', Trading212SummaryView.as_view(), name='trading212-summary'),
]

View File

@@ -1,38 +1,58 @@
# thirdparty/trading212/views.py
import os
import base64
import logging
import requests
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticated
from .serializers import Trading212AccountCashSerializer
from rest_framework.permissions import IsAuthenticated, AllowAny
from django.conf import settings
from django.core.cache import cache
from drf_spectacular.utils import extend_schema
logger = logging.getLogger(__name__)
api_key = os.getenv("ID_API_KEY_TRADING212")
api_secret = os.getenv("API_KEY_TRADING212")
base_url = "https://live.trading212.com"
class Trading212AccountCashView(APIView):
permission_classes = [IsAuthenticated]
permission_classes = [AllowAny]
authentication_classes = []
@extend_schema(
tags=["trading212"],
summary="Get Trading212 account cash",
responses=Trading212AccountCashSerializer
summary="Get Trading212 account cash"
)
def get(self, request):
api_key = os.getenv("API_KEY_TRADING212")
headers = {
"Authorization": f"Bearer {api_key}",
"Accept": "application/json",
}
url = f"{base_url}/api/v0/equity/account/cash"
url = "https://api.trading212.com/api/v0/equity/account/cash"
response = requests.get(url, auth=(api_key, api_secret))
try:
resp = requests.get(url, headers=headers, timeout=10)
resp.raise_for_status()
except requests.RequestException as exc:
return Response({"error": str(exc)}, status=400)
logger.info("Trading212 Account Cash Response:")
logger.info(response)
data = resp.json()
serializer = Trading212AccountCashSerializer(data=data)
serializer.is_valid(raise_exception=True)
return Response(serializer.data)
data = response.json()
return Response(data)
class Trading212SummaryView(APIView):
permission_classes = [AllowAny]
authentication_classes = []
@extend_schema(
tags=["trading212"],
summary="Get Trading212 account summary"
)
def get(self, request):
url = f"{base_url}/api/v0/equity/portfolio"
response = requests.get(url, auth=(api_key, api_secret))
logger.info("Trading212 Account Summary Response:")
logger.info(response)
data = response.json()
return Response(data)