• As we all know, we write code to make money in essence. Since writing code is the bread and butter of our work, could it be the bread and butter of our other side businesses? I pondered for a long time and thought yes.
  • As a front-end developer, of course, it is necessary to use front-end development methods to select appropriate funds. It happened that our group had a share about Deno this quarter, so I chose Deno to climb the fund data. Of course, we won’t talk about Deno installation here.

So let’s go to the body

  • How to choose the right fund, according to my friend
    • Buy fund to want to see long-term point, want to see the yield of 3 years above, such ability sees the stability of this fund.
    • The size of the fund should be as large as possible. On the one hand, a fund of too small size shows its weak fund-raising ability, which means that the fund is not recognized by the public. On the other hand, a fund of large size can only buy companies with large market capitalization, which greatly reduces the risk. Fund managers who can manage large funds must also be made up of the fittest.
    • The fund established for a long time, in fact, the number of funds on the market has been far greater than the number of stocks, and the fund will not be closed because of performance or closed because of the development of the company, buy established for a long time is also to stability, after all, the first risk, the second return
    • Fund managers stay longer, because a large part of the fund’s return is tied to the fund manager, after all, buying a fund is buying a fund manager
  • Now we already have the target, that is, the fund that meets the above conditions. I choose the fund company with a return rate of more than 100% in the past three years, which has been established for more than 7 years, with a capital scale of more than 1 billion, and whose fund manager has been in office for more than 3 years.
  • As a snowball experienced users, I picked out the cone fund to crawl sites, web site address is: danjuanfunds.com/rank/perfor…

  • This page can be ranked by return, we can filter by the last three years, look at the last three years return rankings interface looks like this
Const SIZE = 500; // Top 500 const page = 1; const TYPE = 1 const order_by = '3y' const url = `https://danjuanfunds.com/djapi/v3/filter/fund?type=${TYPE}&order_by=${order_by}&size=${SIZE}&page=${page}`Copy the code
  • Since Deno comes with fetch, there is no need to introduce fetch specifically. The code of the request interface is as follows:
Const fundIdList = [] fetch(URL, headers).then(function(res) {return res.json(); }). Then (function(myJson) {const resData = myjson.data resdata.items. ForEach ((item,index) => {// Select fund id if return >100% in recent 3 years  (Number(item.yield) >= 100) { fundIdList.push(item.fd_code); }})});Copy the code
  • After selected the best fund id, let’s go to the query fund id details, details of the page address is this: danjuanfunds.com/funding/011… The interface address is this: danjuanfunds.com/djapi/fund/…

  • Then we can request data from the above list of ids. The code for requesting fund details looks like this:
Const getFundDetail = (id) = > {const url = {id} ` ` https://danjuanfunds.com/djapi/fund/$/ return/interface fetch(url).then(function(res) { return res.json(); }); }Copy the code
  • We loop to request the fund details in the fund list with the following code:
Const getAllFundData = async () => {// Get all fund ID await getFundList(); For (let I = 0; i < fundIdList.length; i++) { const id = fundIdList[i] const myJson = await getFundDetail(id) const managerDetail = await getManagerDetail(id) Const managerList = managerDetail. Data. Manager_list. Length && managerDetail. Data. Manager_list [0] / / fund manager to manage the time const keepTime = managerList.achievement_list.filter((item) => { return item.fund_code === id })[0]? .post_date const fundDetail = getFilterData({... MyJson, keepTime}) const. Total = fundDetail totalMoney. Split (' $'); // Const fundTime = 1000 * 60 * 60 * 24 * 30 * 12 * 7 const manegeTime = 1000 * 60 * 60 * 24 * 30 * 12 * 3 const nowTime = new Date().getTime() const startTime = new Date(fundDetail.startDate).getTime() const keepTimeStamp = new Date(keepTime).getTime() if (nowTime - startTime > fundTime && total[0] && total[0] > 10 && nowTime - keepTimeStamp > manegeTime) { goodFundList.push(fundDetail) } } writeJson('./fundData.json', GoodFundList) const endTime = new Date().gettime () console.log('-----deno-- time spent after file ', endtime-startTime)}Copy the code
  • Obtain fund manager method as follows
Const getManagerDetail = (id) = > {const url = {id} ` ` https://danjuanfunds.com/djapi/fund/detail/$/ return/interface fetch(url).then(function(res) { return res.json(); }); }Copy the code
  • Filtering fund data methods:
/** */ const getFilterData = (myJson) => {const resData = myJson. Data const startDate = resData.found_date // Start time const code = resData.fd_code // code const manager = resData.manager_name // Fund manager const totalMoney = resData.totShare Fd_full_name // Fund name const company = resData.keeper_name // company name const fundDerived = Fund_derived // returns const unitNav = fundDerived. Unit_nav // Historical cumulative returns const keepTime = myJson. KeepTime // Manage time const  fundDetail = { startDate,code,manager,totalMoney,fullName,company,unitNav, fundDerived,keepTime } return fundDetail }Copy the code
  • Finally, of course, the data we crawled into the file, so that we can view the fund data:
Function writeJson(path, data) {try {const endTime = new Date().getTime() console.log('-----deno-- take time ', endTime - startTime) Deno.writeTextFileSync(path, JSON.stringify(data)); return "Written to " + path; } catch (e) { return e.message; }}Copy the code
  • Finally, the fundData will be written into funddata. json file, and then I recommend using online json to excel, which can make the data to be climbed more concise and clear. The website address: uutool.cn/json2excel/

The funds that finally came out looked like this:

  • Warm prompt
    • Funds are risky and should be bought with caution
    • Crawler’s suggestion is not too frequent, the other party’s website is also a risk
    • Can adjust the screening fund conditions according to their preferences, of course, you can set a yield of 1000%

Finally, there is a link to the code, for those of you who don’t have Deno installed, along with the Node version crawler

  • Github address: github.com/wayofwade/d…