From 077768975d86b3eb3ad01ade8b7f2a7d3bb826f4 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Fri, 2 Dec 2022 07:20:37 +0000 Subject: [PATCH] Get the right signal name from the callback and fix position close schema --- core/lib/schemas/oanda_s.py | 16 ++++++++-------- core/views/hooks.py | 5 ++++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/lib/schemas/oanda_s.py b/core/lib/schemas/oanda_s.py index 3dd9763..40e5a07 100644 --- a/core/lib/schemas/oanda_s.py +++ b/core/lib/schemas/oanda_s.py @@ -528,20 +528,20 @@ class OrderTransation(BaseModel): type: str instrument: str units: str - timeInForce: str - positionFill: str + timeInForce: str | None + positionFill: str | None reason: str longPositionCloseout: LongPositionCloseout longOrderFillTransaction: dict class PositionClose(BaseModel): - longOrderCreateTransaction: OrderTransaction - longOrderFillTransaction: OrderTransaction - longOrderCancelTransaction: OrderTransaction - shortOrderCreateTransaction: OrderTransaction - shortOrderFillTransaction: OrderTransaction - shortOrderCancelTransaction: OrderTransaction + longOrderCreateTransaction: OrderTransaction | None + longOrderFillTransaction: OrderTransaction | None + longOrderCancelTransaction: OrderTransaction | None + shortOrderCreateTransaction: OrderTransaction | None + shortOrderFillTransaction: OrderTransaction | None + shortOrderCancelTransaction: OrderTransaction | None relatedTransactionIDs: list[str] lastTransactionID: str diff --git a/core/views/hooks.py b/core/views/hooks.py index 79e2ac2..49a83e1 100644 --- a/core/views/hooks.py +++ b/core/views/hooks.py @@ -89,8 +89,11 @@ class HookAPI(APIView): return HttpResponseBadRequest("Hook does not exist.") # Try getting the signal + # AUCAD 3M StochExit: C$2419.64 at OANDA + message_first_half = hook_resp.message.split(":")[0] + signal_name = message_first_half.split(" ")[-1] try: - signal = Signal.objects.get(signal=hook_resp.title) + signal = Signal.objects.get(signal=signal_name) except Signal.DoesNotExist: return HttpResponseBadRequest("Signal does not exist.")