init
This commit is contained in:
0
backend/thirdparty/trading212/__init__.py
vendored
Normal file
0
backend/thirdparty/trading212/__init__.py
vendored
Normal file
3
backend/thirdparty/trading212/admin.py
vendored
Normal file
3
backend/thirdparty/trading212/admin.py
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
6
backend/thirdparty/trading212/apps.py
vendored
Normal file
6
backend/thirdparty/trading212/apps.py
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class Trading212Config(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'trading212'
|
||||
0
backend/thirdparty/trading212/migrations/__init__.py
vendored
Normal file
0
backend/thirdparty/trading212/migrations/__init__.py
vendored
Normal file
3
backend/thirdparty/trading212/models.py
vendored
Normal file
3
backend/thirdparty/trading212/models.py
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
11
backend/thirdparty/trading212/serializers.py
vendored
Normal file
11
backend/thirdparty/trading212/serializers.py
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# 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()
|
||||
3
backend/thirdparty/trading212/tests.py
vendored
Normal file
3
backend/thirdparty/trading212/tests.py
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
6
backend/thirdparty/trading212/urls.py
vendored
Normal file
6
backend/thirdparty/trading212/urls.py
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.urls import path
|
||||
from .views import YourTrading212View # Replace with actual view class
|
||||
|
||||
urlpatterns = [
|
||||
path('your-endpoint/', YourTrading212View.as_view(), name='trading212-endpoint'),
|
||||
]
|
||||
37
backend/thirdparty/trading212/views.py
vendored
Normal file
37
backend/thirdparty/trading212/views.py
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
# thirdparty/trading212/views.py
|
||||
import os
|
||||
import requests
|
||||
from decouple import config
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from .serializers import Trading212AccountCashSerializer
|
||||
|
||||
from drf_spectacular.utils import extend_schema
|
||||
|
||||
class Trading212AccountCashView(APIView):
|
||||
permission_classes = [IsAuthenticated]
|
||||
|
||||
@extend_schema(
|
||||
summary="Get Trading212 account cash",
|
||||
responses=Trading212AccountCashSerializer
|
||||
)
|
||||
def get(self, request):
|
||||
api_key = os.getenv("API_KEY_TRADING212")
|
||||
headers = {
|
||||
"Authorization": f"Bearer {api_key}",
|
||||
"Accept": "application/json",
|
||||
}
|
||||
|
||||
url = "https://api.trading212.com/api/v0/equity/account/cash"
|
||||
|
||||
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)
|
||||
|
||||
data = resp.json()
|
||||
serializer = Trading212AccountCashSerializer(data=data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
return Response(serializer.data)
|
||||
Reference in New Issue
Block a user