Make more fields optional and fix crash

This commit is contained in:
Mark Veidemanis 2022-11-29 07:20:39 +00:00
parent b3bacde8df
commit 2b13802009
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 11 additions and 9 deletions

View File

@ -541,8 +541,8 @@ class OrderTransaction(BaseModel):
requestID: str requestID: str
time: str time: str
type: str type: str
instrument: str instrument: str | None
units: str units: str | None
timeInForce: str | None timeInForce: str | None
positionFill: str | None positionFill: str | None
reason: str reason: str
@ -588,11 +588,11 @@ class TradeDetailsTrade(BaseModel):
state: str state: str
currentUnits: str currentUnits: str
realizedPL: str realizedPL: str
closingTransactionIDs: list[str] closingTransactionIDs: list[str] | None
financing: str financing: str
dividendAdjustment: str dividendAdjustment: str
closeTime: str closeTime: str | None
averageClosePrice: str averageClosePrice: str | None
clientExtensions: ClientExtensions | None clientExtensions: ClientExtensions | None

View File

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