```plantuml @startuml title Exchange Connection Logic Flow start :User Lands on Client Page; if ("Is User New?") then (Yes) :Attempt to Connect to Default Exchange (Public-Only); if ("Default Exchange Supports Public Connection?") then (Yes) :Connect Default Exchange in Public-Only Mode; note right: Scenario A else (No) :Failed to Connect Default Exchange; stop endif else (No) :Retrieve Previously Connected Exchanges and Modes; :Reconnect to Default Exchange based on Previous Mode; endif :User Chooses to Connect an Exchange; if ("Exchange is Already Connected?") then (Yes) if ("User Provides New API Keys?") then (Yes) :Compare New API Keys with Existing Ones; if ("Keys Differ?") then (Yes) :Update API Keys in Database; :Re-instantiate Exchange Object with New Keys; :Attempt Authentication; if ("Authentication Successful?") then (Yes) :Status = api_keys_updated; note right: Scenarios C, F, G else (No) :Status = failure; note right: Scenarios E endif else (No) :Status = already_connected; note right: Scenario D endif else (No) :Check Current Connection Mode; if ("Currently in Authenticated Mode?") then (Yes) :Status = already_connected; else (No) :Status = connected_public_only; note right: Scenarios B, D endif endif else (No) :User Provides API Keys?; if ("Exchange Requires API Keys?") then (Yes) if ("API Keys Provided?") then (Yes) :Attempt to Connect and Authenticate Exchange; if ("Authentication Successful?") then (Yes) :Status = success; note right: Scenarios C, F else (No) :Status = failure; note right: Scenario E endif else (No) :Alert User to Provide API Keys; stop endif else (No) :Attempt to Connect to Exchange in Public-Only Mode; if ("Connection Successful?") then (Yes) :Status = connected_public_only; note right: Scenarios B else (No) :Status = failure; note right: Scenario B endif endif endif :Return Status to Client; if ("Status = success or api_keys_updated") then (Yes) :Client Reloads Page to Reflect Changes; else (No) if ("Status = connected_public_only or already_connected") then (Yes) :Client Shows Informational Message; else (No) :Client Shows Error Message; endif endif stop @enduml ```