Make more fields optional and fix crash
This commit is contained in:
parent
b3bacde8df
commit
2b13802009
|
@ -541,8 +541,8 @@ class OrderTransaction(BaseModel):
|
|||
requestID: str
|
||||
time: str
|
||||
type: str
|
||||
instrument: str
|
||||
units: str
|
||||
instrument: str | None
|
||||
units: str | None
|
||||
timeInForce: str | None
|
||||
positionFill: str | None
|
||||
reason: str
|
||||
|
@ -588,11 +588,11 @@ class TradeDetailsTrade(BaseModel):
|
|||
state: str
|
||||
currentUnits: str
|
||||
realizedPL: str
|
||||
closingTransactionIDs: list[str]
|
||||
closingTransactionIDs: list[str] | None
|
||||
financing: str
|
||||
dividendAdjustment: str
|
||||
closeTime: str
|
||||
averageClosePrice: str
|
||||
closeTime: str | None
|
||||
averageClosePrice: str | None
|
||||
clientExtensions: ClientExtensions | None
|
||||
|
||||
|
||||
|
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue