Make callbacks handle signals

This commit is contained in:
Mark Veidemanis 2022-12-01 19:32:50 +00:00
parent 4527a9d04b
commit bdae8ab093
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 17 additions and 2 deletions

View File

@ -10,7 +10,7 @@ from rest_framework.views import APIView
from core.forms import HookForm
from core.lib import market
from core.lib.schemas.drakdoo_s import DrakdooCallback
from core.models import Callback, Hook
from core.models import Callback, Hook, Signal
from core.util import logs
from core.views import ObjectCreate, ObjectDelete, ObjectList, ObjectUpdate
@ -88,16 +88,29 @@ class HookAPI(APIView):
except Hook.DoesNotExist:
return HttpResponseBadRequest("Hook does not exist.")
# Try getting the signal
try:
signal = Signal.objects.get(signal=hook_resp.title)
except Signal.DoesNotExist:
return HttpResponseBadRequest("Signal does not exist.")
# For uptime checks/testing
if data["exchange"].lower() == "n/a":
log.debug("HookAPI callback: exchange is N/A, skipping")
return HttpResponse("OK")
# Set the signal relation
data["signal"] = signal
# Create the callback object
callback = Callback.objects.create(hook=hook, **data)
callback.save()
market.process_callback(callback)
# Bump received count
hook.received = hook.received + 1
signal.received = signal.received + 1
hook.save()
signal.save()
return HttpResponse("OK")

View File

@ -12,7 +12,9 @@ class SignalList(LoginRequiredMixin, ObjectList):
list_template = "partials/signal-list.html"
model = Signal
page_title = "List of signals. Linked to hooks and strategies."
page_subtitle = "Link signals you have defined in Drakdoo to their corresponding hooks."
page_subtitle = (
"Link signals you have defined in Drakdoo to their corresponding hooks."
)
list_url_name = "signals"
list_url_args = ["type"]