import { Box, Span, Strong, Text, Underline, useUiHost } from "../../../ui"; import { colors } from "../../../theme/colors"; import { t, tf } from "../../../i18n"; import { ExternalLink, type ListViewItem } from "../../ui"; import { getBrokerLabel } from "./utils"; /** Opens the setup link below the steps; the wizard binds it. */ export const BROKER_GUIDE_KEY = "o"; const IBKR_FLEX_GUIDE_URL = "https://www.ibkrguides.com/clientportal/performanceandstatements/flex.htm"; const IBKR_GATEWAY_DOWNLOAD_URL = "https://www.interactivebrokers.com/en/trading/ibgateway-stable.php"; /** The link the setup step shows for this broker and connection mode, if any. */ export function brokerSetupGuideUrl( brokerId: string, brokerValues: Record>, ): string | null { if (brokerId !== "ibkr") return null; return brokerValues[brokerId]?.connectionMode === "gateway" ? IBKR_GATEWAY_DOWNLOAD_URL : IBKR_FLEX_GUIDE_URL; } /** The link with its key after it, the way a button shows its shortcut. */ function GuideLink({ url }: { url: string }) { return ( {` ${BROKER_GUIDE_KEY}`} ); } export function BrokerSetupPanel({ choices, selectedBrokerId, brokerValues, }: { choices: ListViewItem[]; selectedBrokerId: string; brokerValues: Record>; }) { const brokerLabel = getBrokerLabel(choices, selectedBrokerId); const connectionMode = brokerValues[selectedBrokerId]?.connectionMode; const isGateway = connectionMode === "gateway"; const desktop = useUiHost().kind === "desktop-web"; return ( {selectedBrokerId === "ibkr" && !isGateway && ( <> {t("You'll need these details from IBKR Account Management:")} {t("1. Go to ")}{t("Performance & Reports > Flex Queries")} {t("2. Create an Activity Flex Query: Open Positions, Select All")} {t("3. Note the ")}{t("Query ID")}{t(" (numeric)")} {t("4. Click the gear by ")}{t("Flex Web Service")}{t(" for a ")}{t("Flex Web Service Token")} )} {selectedBrokerId === "ibkr" && isGateway && ( <> {t("You'll need IB Gateway or TWS running locally:")} {t("1. Download and install ")}{t("IB Gateway")}{t(" (or use TWS)")} {t("2. Log in with your IBKR credentials")} {t("3. In ")}{t("Configuration > API > Settings")}{":"} {t(" Enable \"ActiveX and Socket Clients\"")} {t(" Gloomberb can auto-detect local API ports (4001, 4002, 7496, 7497)")} {t(" Use Manual setup only if you need a custom host or exact socket port")} {t("4. Keep it running while using Gloomberb")} )} {selectedBrokerId !== "ibkr" && ( <> {tf("You'll need your {broker} API credentials.", { broker: brokerLabel })} {t("Check your broker's documentation for setup instructions.")} )} ); }