豆粕m2409:连续10天在10日均线下方,30天内有20天在均线下方
import axios from 'axios'; import fs from 'fs-extra'; const instance = axios.create(); const api={ //获取纯碱实时价格 async getSaRealPrice(){ const res=await instance.get('https://futsseapi.eastmoney.com/list/variety/115/22?callback=aaa_callback&orderBy=zdf&sort=desc&pageSize=20&pageIndex=0&callbackName=aaa_callback&token=58b2fa8f54638b60b87d69b31969089c&field=dm%2Csc%2Cname%2Cp%2Czsjd%2Czde%2Czdf%2Cf152%2Co%2Ch%2Cl%2Czjsj%2Cvol%2Ccje%2Cwp%2Cnp%2Cccl&blockName=callback&_='+(new Date().getTime())) const func=new Function('aaa_callback','return '+res.data) const data=func(function(item){return item}) return data; }, //获取纯碱每日价格 async getSaDayPrice(code){ const url=`https://finance.pae.baidu.com/selfselect/getstockquotation?all=1&code=${code}&isIndex=false&isBk=false&isBlock=false&isFutures=true&isStock=false&newFormat=1&ktype=1&market_type=ab&group=quotation_futures_kline&finClientType=pc` const res=await instance.get(url) return res.data.Result.newMarketData; }, async test(){ const url="https://d.10jqka.com.cn/v6/line/49_884022/01/last60.js?hexin-v=A-idlXgdGjnHFDa9SGwcVWfkv93_EU0tLnUhsaIZNGNW_YbDSiEcq36F8CLx" const res=await instance.post(url) console.log(res.data) const func=new Function('aaa_callback','return '+res.data) const data=func(function(item){return item}) return data; } } async function getSrc(){ const codeMap={ '纯碱':['SA409','SA410','SA411','SA412','SA501','SA502','SA503','SA504','SA505','SA506','SA507'], '菜粕':['RM409','RM411','RM501','RM503','RM505','RM507'], '豆粕':['m2409','m2411','m2412','m2501','m2503','m2505','m2507'], } const nameMap=[] const codeLists=[] for(let name in codeMap){ codeMap[name].forEach(function (code){ nameMap[code]=name codeLists.push(code) }) } const effectiveTime=12*60*60*1000 const nTime=Date.now() const paiMingList=[] let codesLen=codeLists.length for(let i=0;i<codesLen;i++){ const code=codeLists[i]; const filepath='src/'+code+'.json' let data if(fs.existsSync(filepath)&&nTime-effectiveTime<fs.statSync(filepath).mtime.getTime()){ data=fs.readJsonSync(filepath) }else{ data=await api.getSaDayPrice(code) console.log(code,data) fs.outputJsonSync(filepath,data) } const dLen=30;//统计最近30天 const lists=data.marketData.split(';').map(str=>str.split(',')) const list20=lists.splice(lists.length-dLen,lists.length).reverse() let down=0 let up=0 let cLen=0 list20.forEach((item,i)=>{ const high=Number(item[data.headers.indexOf('最高')]) const low=Number(item[data.headers.indexOf('最低')]) const ma10avgprice=Number(item[data.headers.indexOf('ma10均价')]) if(low>ma10avgprice){ if(up===i){ cLen=up+1 } up++ }else if(high<ma10avgprice){ if(down===i){ cLen=down+1 } down++ } }) paiMingList.push({ code, dLen, cLen, order:cLen+Math.max(up,down), ma10avgprice:up>down?up:-down }) } paiMingList.sort(function (a,b){ return b.order-a.order }) const obj=paiMingList[0] console.log(`${nameMap[obj.code]}${obj.code}:连续${obj.cLen}天在10日均线${obj.ma10avgprice>0?'上':'下'}方,${obj.dLen}天内有${Math.abs(obj.ma10avgprice)}天在均线${obj.ma10avgprice>0?'上':'下'}方`) console.log(paiMingList) } getSrc() export default api;
标签:code,const,品种,item,搜索,obj,期货,return,data From: https://www.cnblogs.com/caoke/p/18352708