Make more fields optional and fix crash

This commit is contained in:
2022-11-29 07:20:39 +00:00
parent b3bacde8df
commit 2b13802009
2 changed files with 11 additions and 9 deletions

View File

@@ -33,15 +33,17 @@ class TradeAction(LoginRequiredMixin, OTPRequiredMixin, View):
return HttpResponseBadRequest()
template_name = f"wm/{type}.html"
unique = str(uuid.uuid4())[:8]
db_info = Trade.get_by_id_or_order(trade_id, request.user)
if db_info is None:
return HttpResponseBadRequest("Trade not found.")
if db_info.order_id is not None:
try:
if db_info.order_id == db_info.response["id"]:
db_info.order_id = str(int(db_info.order_id) + 1)
db_info.save()
# Fix old data
if "id" in db_info.order_id:
db_response_id = db_info.order_id["id"]
if db_info.order_id == db_response_id:
db_info.order_id = str(int(db_info.order_id) + 1)
db_info.save()
live_info = db_info.account.client.get_trade(db_info.order_id)
except GenericAPIError as e:
live_info = {"error": e}