babaTEEpe commited on
Commit
deadefe
·
verified ·
1 Parent(s): f58fa10

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -3
app.py CHANGED
@@ -630,9 +630,29 @@ async def callback(request: Request, code: str = None):
630
  acc_list_res = ProtoOAGetAccountListByAccessTokenRes()
631
  acc_list_res.ParseFromString(proto_msg.payload)
632
  if acc_list_res.ctidTraderAccount:
633
- account_id = str(acc_list_res.ctidTraderAccount[0].ctidTraderAccountId)
634
- detected_env = try_env
635
- logger.info(f"Found account ID: {account_id} on {try_env} server")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636
 
637
  ssl_sock.close()
638
  if account_id:
 
630
  acc_list_res = ProtoOAGetAccountListByAccessTokenRes()
631
  acc_list_res.ParseFromString(proto_msg.payload)
632
  if acc_list_res.ctidTraderAccount:
633
+ logger.info(f"Accounts returned from token ({len(acc_list_res.ctidTraderAccount)} accounts):")
634
+ for a in acc_list_res.ctidTraderAccount:
635
+ is_live = getattr(a, "isLive", False)
636
+ logger.info(f" - Account ID: {a.ctidTraderAccountId}, isLive: {is_live}, broker: {getattr(a, 'brokerName', 'N/A')}")
637
+
638
+ # Filter based on CTRADER_ENV
639
+ matched_acc = None
640
+ for a in acc_list_res.ctidTraderAccount:
641
+ is_live = getattr(a, "isLive", False)
642
+ env_type = "live" if is_live else "demo"
643
+ if env_type == CTRADER_ENV:
644
+ matched_acc = a
645
+ break
646
+
647
+ if matched_acc:
648
+ selected_acc = matched_acc
649
+ logger.info(f"Successfully matched account matching CTRADER_ENV={CTRADER_ENV}: {selected_acc.ctidTraderAccountId}")
650
+ else:
651
+ selected_acc = acc_list_res.ctidTraderAccount[0]
652
+ logger.info(f"No account matching CTRADER_ENV={CTRADER_ENV} found. Using first available: {selected_acc.ctidTraderAccountId}")
653
+
654
+ account_id = str(selected_acc.ctidTraderAccountId)
655
+ detected_env = "live" if getattr(selected_acc, "isLive", False) else "demo"
656
 
657
  ssl_sock.close()
658
  if account_id: