import BaseApiCodeTransform from "@stocks/base/transforms/api-code" ; import { ERROR_API_CODE } from "@utils/constant" ; import { COMMON_SH , COMMON_SZ , COMMON_HK , COMMON_US } from "@stocks/base/utils/constant" ; import { XUEQIU_SZ , XUEQIU_SH , XUEQIU_HK , XUEQIU_US } from "@stocks/xueqiu/utils/constant" ; /**
 * 【雪球】股票代码转换统一代码
 */ class XueqiuApiCodeTransform extends BaseApiCodeTransform { param code public transform ( code ) { if ( code . includes ( XUEQIU_SZ ) ) { return this . SZTransform ( code ) ; } if ( code . includes ( XUEQIU_SH ) ) { return this . SHTransform ( code ) ; } if ( code . includes ( XUEQIU_HK ) ) { return this . HKTransform ( code ) ; } return this . USTransform ( code ) ; } param codes public transforms ( codes ) { return super . transforms ( codes ) ; } param code public SZTransform ( code ) { if ( ! code . includes ( XUEQIU_SZ ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SZ + code . replace ( XUEQIU_SZ , "" ) ; } param code public SHTransform ( code ) { if ( ! code . includes ( XUEQIU_SH ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_SH + code . replace ( XUEQIU_SH , "" ) ; } param code public HKTransform ( code ) { if ( ! code . includes ( XUEQIU_HK ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_HK + code . replace ( XUEQIU_HK , "" ) ; } param code public USTransform ( code ) { if ( code . includes ( XUEQIU_SZ ) || code . includes ( XUEQIU_SH ) || code . includes ( XUEQIU_HK ) ) { throw new Error ( ERROR_API_CODE ) ; } return COMMON_US + code . replace ( XUEQIU_US , "" ) ; } } export default XueqiuApiCodeTransform ;