import { TradeTypeEnum } from "@shared/types"; import { IFormatCurrentPair } from "@shared/types/interface"; const defaultOption = { [TradeTypeEnum.Linear]: "BTCUSDT", [TradeTypeEnum.Inverse]: "BTCUSDT", [TradeTypeEnum.Margin]: "BTCUSDT", [TradeTypeEnum.Spot]: "BTCUSDT" }; /** * https://trade.aax.com/zh-TW/perp/btcusdt * https://trade.aax.com/zh-TW/inverse/btcusdt * https://trade.aax.com/zh-TW/spot/btcusdt * https://trade.aax.com/zh-TW/margin/btcusdt * * 获取当前交易对 * @param tradeType 业务线 * @param originName 路由 * @returns */ // 获取当前交易对 export const getCurrentPairForOriginName = (tradeType: TradeTypeEnum, originName?: string): string => { let symbol = defaultOption[tradeType]; const localeKey = `${tradeType}_ORIGIN_NAME`.toUpperCase(); if (!originName) { // 本地存 const localeValue = localStorage.getItem(localeKey); if (localeValue) symbol = localeValue; } else { const originNameSplit = originName?.split("/") || ""; if (originNameSplit.length < 2) { localStorage.setItem(localeKey, symbol); } symbol = originNameSplit[1]; } return symbol.toLocaleUpperCase(); }; /** * 获取当前交易对 * @param tradeType 业务线 * @param symbol 交易对 * @param list 交易对列表 * @returns */ export const getCurrentPair = ({ tradeType, symbol, list }: { tradeType: TradeTypeEnum; symbol: string; list: IFormatCurrentPair[]; }): undefined | IFormatCurrentPair => { return list?.find(item => item.symbol === symbol && tradeType === item.tradeType); };