diff --git a/core/views/hooks.py b/core/views/hooks.py index 0de764a..79e2ac2 100644 --- a/core/views/hooks.py +++ b/core/views/hooks.py @@ -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") diff --git a/core/views/signals.py b/core/views/signals.py index 1b67fae..b95ef1b 100644 --- a/core/views/signals.py +++ b/core/views/signals.py @@ -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"]