def update_signal(request): ''' Updates signal and prior_period_candle for all candle objects. We can use this if we have already loaded candle data but need to update the values on its own. sample: PATCH localhost:8000/update/signal?currency=BTC ''' if request.method == "PATCH": try: # Get currency from request user_currency = request.GET.get('currency', '') # currency is required to be given in request. if user_currency == "": raise TrackException("Please specify a currency in your request.", "Bad Request") my_signal = Signal(user_currency) confirm_message = my_signal.update_signal() except Exception as exc: return JsonResponse({"status_code": 409, "status": "Conflict", "type": type(exc).__name__, "message": exc.__str__()}) else: return JsonResponse({"status_code": 202, "status": "Accepted", "message": confirm_message} ) else: return JsonResponse(bad_request_default)
def update_signal(request, simulation_id=""): ''' Updates signal and prior_period_candle for all candle objects. We can use this if we have already loaded candle data but need to update the values on its own. Note: simulation_id is optional, if none is given, all Simulations will be re-calculated (should be used when we re-load the source, then we need to re-calculate all Sims). sample: PATCH localhost:8000/update/1/signal?currency=BTC ''' if request.method == "PATCH": try: # initiate variables confirm_message = "" # Get currency from request user_currency = request.GET.get('currency', '') # currency is required to be given in request. if user_currency == "": raise TrackException( "Please specify a currency in your request.", "Bad Request") elif simulation_id == "": # If we do not specify a simulation, all will be updated based on the Simulations table. for sim in Simulation.objects.all(): my_signal = Signal(currency=user_currency, simulation_id=sim.id) confirm_message += my_signal.update_signal() else: my_signal = Signal(currency=user_currency, simulation_id=simulation_id) confirm_message = my_signal.update_signal() except Exception as exc: return JsonResponse({ "status_code": 409, "status": "Conflict", "type": type(exc).__name__, "message": exc.__str__() }) else: return JsonResponse({ "status_code": 202, "status": "Accepted", "message": confirm_message }) else: return JsonResponse(bad_request_default)