UNPKG

dm-web-react

Version:

The DM web client with React.

298 lines (264 loc) 9.82 kB
import { InterestRateType, InvestmentAdviceType, RatingType, OwnerType, IndustryType, InternalRatingType, BondRangeType, } from "../models/enum/bondFilterTypes"; import { interestRateOptions, creditOptions } from "../components/BondFilter/filterOptions"; import { BondFilter } from "../store/states/bondFilter"; import { TodayDealTable } from "../store/states/todayDealTable"; import { Direction as TableSortDirection } from "../../../components/Table"; // 排序字段 map const sortFieldMap = { id: "id", // ID tenor: "tenorDays", // 剩余期限 code: "code", // 债券代码 shortName: "shortName", // 债券简称 yield: "yield", // 成交价(收益率) fairValue: "fairValue", // 中债估值 dealSubChinaBond: "dealSubChinaBond", // 成交-中债(yield - fairValue) macd: "macd", // 久期 ratingList: "issRatingUiOpt", // 主/债/展望 brokerShortName: "brokerShortName", // 经纪商 updateTime: "updateTime", // 更新时间 instInvestmentAdvice: "instInvestmentAdvice", // 投资建议 instRating: "instRating", // 内部评级 pd: "pdNum", // DM量化评分 pdRating: "pdNum", // DM量化评分 worstPd: "worstPdNum", // 历史最高风险 yieldToMaturity: "yieldToMaturity", // 中证估值 dealSubChinaSecurities: "dealSubChinaSecurities", // 成交-中证(yield - yieldToMaturity) statusValue: "statusValue", // 成交类型1:done 2:gvn 3:tkn 4:other }; // 排序方向 枚举 const enum SortDirection { ASC = "asc", DESC = "desc", } /** * 获取今日成交 table 的 api 请求参数 */ export default (filter: BondFilter & TodayDealTable) => { const params: any = {}; // 搜索框 if (filter.searchBondList.length) { params.bondUniCodes = filter.searchBondList; } // 债券范围 if (filter.groupId !== BondRangeType.All) { params.groupId = filter.groupId; // 投资组合 id } // 有效报价 if (filter.isEffectiveQuotedPrice) { params.quoteStatus = 0; // 正常 } else { params.quoteStatus = 2; // 全部 } // // 是否 双边报价 // if (filter.isBilaterallyQuotedPrice) { // params.underlyingPrice = 1; // } else { // params.underlyingPrice = 0; // } // // bid // if (filter.bidValue) { // params.bidYield = filter.bidValue; // params.bidYieldDirection = filter.bidCondition; // } // // ofr // if (filter.ofrValue) { // params.bidYield = filter.ofrValue; // params.ofrYieldDirection = filter.ofrCondition; // } // // bid - 中债 // if (filter.bidChinaBondValue) { // params.bidSubChinaBond = filter.bidChinaBondValue; // params.bidSubChinaBondDirection = filter.bidChinaBondCondition; // } // // ofr // if (filter.chinaBondOfrValue) { // params.chinaBondSubOfr = filter.chinaBondOfrValue; // params.chinaBondSubOfrDirection = filter.chinaBondOfrCondition; // } // 债券类型 if (filter.interestRateValues.length || filter.creditValues.length) { const interestRateValues = []; interestRateValues.push(...filter.interestRateValues); // interestRateValues.push( // ...(filter.interestRateValues.length === 0 // ? interestRateOptions.map(interestRateOption => interestRateOption.value) // : filter.interestRateValues) // ); const creditValues = []; creditValues.push(...filter.creditValues); // creditValues.push(...(filter.creditValues.length === 0 ? creditOptions.map(creditOption => creditOption.value) : filter.creditValues)); // 过滤 "国开" 和 "非国开" 的情况 // 国开:yes 非国开:yes if (interestRateValues.indexOf(InterestRateType.CD) > -1 && interestRateValues.indexOf(InterestRateType.NCD) > -1) { interestRateValues.splice(interestRateValues.indexOf(InterestRateType.NCD), 1); } // 国开:yes 非国开:no else if (interestRateValues.indexOf(InterestRateType.CD) > -1 && interestRateValues.indexOf(InterestRateType.NCD) === -1) { params.filterChinaDevelopment = true; } // 国开:no 非国开:yes else if (interestRateValues.indexOf(InterestRateType.CD) === -1 && interestRateValues.indexOf(InterestRateType.NCD) > -1) { params.filterChinaDevelopment = false; // 国开 和 非国开 都是 InterestRateTypes.CD 的值 interestRateValues.push(InterestRateType.CD); interestRateValues.splice(interestRateValues.indexOf(InterestRateType.NCD), 1); } params.dmBondTypes = [...interestRateValues, ...creditValues]; } else { // 当都为全部时,把所有值传给后台 const interestRateValues = interestRateOptions.map(interestRateOption => interestRateOption.value); const creditValues = creditOptions.map(creditOption => creditOption.value); interestRateValues.splice(interestRateValues.indexOf(InterestRateType.NCD), 1); params.dmBondTypes = [...interestRateValues, ...creditValues]; } // 期限 if (filter.startTime && filter.endTime) { params.startTime = filter.startTime; params.endTime = filter.endTime; } if (filter.tenorValues.length) { params.tenors = filter.tenorValues; } // 债项评级 if (filter.bondRatingValues.length) { params.bondRatings = []; params.bondRatings.push(...filter.bondRatingValues); if (params.bondRatings.indexOf(RatingType.Other) > -1) { params.bondRatings.push(...[RatingType.AMinus, RatingType.AMinus1]); } } // 主体评级 if (filter.issuerRatingValues.length) { params.issRatings = []; params.issRatings.push(...filter.issuerRatingValues); if (params.issRatings.indexOf(RatingType.Other) > -1) { params.issRatings.push(...[RatingType.AMinus, RatingType.AMinus1]); } } // 隐含评级 if (filter.implicitRatingValues.length) { params.impliedRatings = []; params.impliedRatings.push(...filter.implicitRatingValues); if (params.impliedRatings.indexOf(RatingType.Other) > -1) { params.impliedRatings.push(...[RatingType.AMinus, RatingType.AMinus1]); } } // DM评分 if (filter.dmScoreValues.length) { params.pds = filter.dmScoreValues; } // 内部评级 if (filter.internalRatingValues.length) { const internalRatingValues = []; internalRatingValues.push(...filter.internalRatingValues); // 暂无内部评级 if (internalRatingValues.indexOf(InternalRatingType.None) > -1) { // 把 "暂无内部评级" 去掉 internalRatingValues.splice(internalRatingValues.indexOf(InternalRatingType.None), 1); params.instRatingsFlag = true; } if (internalRatingValues.length) { params.instRatings = filter.internalRatingValues; } } // 投资建议 if (filter.investmentAdviceValues.length) { const investmentAdviceValues = []; investmentAdviceValues.push(...filter.investmentAdviceValues); // 暂无投资建议 if (investmentAdviceValues.indexOf(InvestmentAdviceType.None) > -1) { // 把 "暂无投资建议" 去掉 investmentAdviceValues.splice(investmentAdviceValues.indexOf(InvestmentAdviceType.None), 1); params.instInvestmentAdvicesFlag = true; } if (investmentAdviceValues.length) { params.instInvestmentAdvices = filter.investmentAdviceValues; } } // 企业类型 if (filter.ownerTypeValues.length) { params.ownerTypes = filter.ownerTypeValues; // 把 其他 换成 3,4,5,7[,0] (0?) if (params.ownerTypes.indexOf(OwnerType.Other) > -1) { params.ownerTypes[params.ownerTypes.indexOf(OwnerType.Other)] = 3; params.ownerTypes.push(4); params.ownerTypes.push(5); params.ownerTypes.push(7); params.ownerTypes.push(0); // ? } } // 上市类型 if (filter.listTypeValue.length > 0) { params.listPar = filter.listTypeValue[0]; } // 概念(是否城投债) if (filter.conceptValue.length > 0) { params.munInvest = filter.conceptValue[0]; } // 市场 if (filter.marketValues.length) { params.markets = filter.marketValues; } // 行业 if (filter.industryValues.length) { const industryValues = []; industryValues.push(...filter.industryValues); if (industryValues.indexOf(IndustryType.None) > -1) { industryValues.splice(industryValues.indexOf(IndustryType.None), 1); params.induIdsFlag = true; } if (industryValues.length) { params.induIds = filter.industryValues; } } // 区域 if (filter.areaCodeValues.length) { params.areaCodes = filter.areaCodeValues; } // 担保 if (filter.guaranteeValues.length === 1) { params.isGuarPars = filter.guaranteeValues; } // 募集 if (filter.raiseValues.length === 1) { params.raisingWays = filter.raiseValues; } // 票面 if (filter.couponValues.length === 1) { params.rateTypePars = filter.couponValues; } // 条款 if (filter.termValue.length > 0) { params.isHaveRight = filter.termValue[0]; } // 经纪商类型 if (filter.todayDealBrokersValues.length) { params.brokerTypeList = filter.todayDealBrokersValues; } // 排序 if (filter.sorts.length) { filter.sorts.forEach(sort => { let sortDirection; if (sort.direction === TableSortDirection.ASC) { sortDirection = SortDirection.ASC; } else if (sort.direction === TableSortDirection.DESC) { sortDirection = SortDirection.DESC; } if (sortDirection === SortDirection.ASC || sortDirection === SortDirection.DESC) { // 接口不支持多字段排序,这里暂时覆盖前面循环的排序 !!!!!!!!!!!!!!! params.sort = `${sortFieldMap[sort.field]}:${sortDirection}`; } }); } params.source = 1; // 1:经纪商成交 2:交易所成交 3:CFETS params.type = 7; // 1,利率债,2,信用债3,NCD,4,城投债,5,筛选6,投资组合,7,经纪商行情 return params; };