Skip to content

Commit

Permalink
feat: 基金持仓明细和持仓股票涨跌情况
Browse files Browse the repository at this point in the history
  • Loading branch information
giscafer committed Sep 10, 2020
1 parent 5d08eba commit 50a7599
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 94 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

## [1.5.4]

- feat: 基金持仓明细和持仓股票涨跌情况

## [1.5.3]

- chore: 停牌股票标记误判取消了
Expand Down
32 changes: 31 additions & 1 deletion development.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,28 @@ http://fund.eastmoney.com/f10/jbgk_001632.html
http://fundgz.1234567.com.cn/js/001632.js?rt=1596338178723
```

### 基金持仓股票涨跌情况

```
https://push2.eastmoney.com/api/qt/ulist.np/get?fltt=2&invt=2&fields=f2,f3,f12,f14,f9&secids=0.000661,1.603259,0.300142,0.300122,0.002007,0.300601,1.600201,0.300529,0.300676,1.600867,&_=1599742806408
```

html 数据

```
http://fundf10.eastmoney.com/FundArchivesDatas.aspx?type=jjcc&code=161726&topline=10&year=&month=&rt=0.3585181467435923
```

页面逻辑

```
http://j5.dfcfw.com/js/f10/f10_min_20200220153807.js
```

### 爬取净值接口

```
// 历史净值
http://fund.eastmoney.com/f10/F10DataApi.aspx?type=lsjz&code=001632&page=1&&sdate=2020-07-31
Expand All @@ -27,40 +46,49 @@ https://hq.sinajs.cn/list=hk00700
// 比如诺安成长混合
http://fundgz.1234567.com.cn/js/320007.js?callback=a
// 天天基金app
// 天天基金 app
https://fundmobapi.eastmoney.com/FundMNewApi/FundMNFInfo?pageIndex=1&pageSize=50&plat=Android&appType=ttjj&product=EFund&Version=1&deviceid=ssdfsdfsdf&Fcodes=320007,161726
```

### 图片

```
// 走势图片、[沪深拼音]/time/[图片大小]/[股票代码]
http://img1.money.126.net/chart/hs/time/210x140/1399001.png
```

### 基金代码列表

```
http://fund.eastmoney.com/js/fundcode_search.js
```

### 基金排行榜

```
http://vip.stock.finance.sina.com.cn/fund_center/data/jsonp.php/IO.XSRV2.CallbackList['hLfu5s99aaIUp7D4']/NetValueReturn_Service.NetValueReturnOpen?page=1&num=40&sort=form_year&asc=0&ccode=&type2=0&type3=
```

### 基金走势图

```
// 近期走势
https://image.sinajs.cn/newchart/v5/fund/nav/ss/150206.gif
```

## 开发

```
// 官方插件文档介绍
https://code.visualstudio.com/api/extension-guides/overview
Expand Down Expand Up @@ -206,3 +234,5 @@ http://blog.haoji.me/vscode-plugin-overview.html
请求方式:POST

参数列表:version=6.2.4&plat=Android&appType=ttjj&FCODE=005919&onFundCache=3&keeeeeyparam=FCODE&deviceid=656c09923c567b89bb44801020bc59ab%7C%7Ciemi_tluafed_me&igggggnoreburst=true&product=EFund&MobileKey=656c09923c567b89bb44801020bc59ab%7C%7Ciemi_tluafed_me

https://fundmobapi.eastmoney.com/FundMNewApi/FundMNNBasicInformation?version=6.2.4&plat=Android&appType=ttjj&FCODE=005919&onFundCache=3&keeeeeyparam=FCODE&deviceid=656c09923c567b89bb44801020bc59ab%7C%7Ciemi_tluafed_me&igggggnoreburst=true&product=EFund&MobileKey=656c09923c567b89bb44801020bc59ab%7C%7Ciemi_tluafed_me
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "leek-fund",
"displayName": "韭菜盒子",
"description": "韭菜盒子,VSCode 里也可以看股票 & 基金实时数据,做最好用的养基插件",
"version": "1.5.3",
"version": "1.5.4",
"author": "giscafer <[email protected]>",
"repository": {
"type": "git",
Expand Down Expand Up @@ -119,7 +119,11 @@
},
{
"command": "leek-fund.viewFundHistory",
"title": "持仓信息&历史净值"
"title": "历史净值"
},
{
"command": "leek-fund.viewFundPosition",
"title": "持仓信息"
},
{
"command": "leek-fund.refreshFund",
Expand Down Expand Up @@ -249,13 +253,18 @@
{
"command": "leek-fund.viewFundHistory",
"when": "view == leekFundView.fund",
"group": "group1"
"group": "group2"
},
{
"command": "leek-fund.setFundTop",
"command": "leek-fund.viewFundPosition",
"when": "view == leekFundView.fund",
"group": "group2"
},
{
"command": "leek-fund.setFundTop",
"when": "view == leekFundView.fund",
"group": "group1"
},
{
"command": "leek-fund.setFundTop",
"when": "view == leekFundView.fund",
Expand Down
5 changes: 4 additions & 1 deletion src/registerEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import fundTrend from './webview/fundTrend';
import openNews from './webview/news';
import setAmount from './webview/setAmount';
import stockTrend from './webview/stockTrend';
import fundPosition from './webview/fundPosition';

export function registerViewEvent(
context: ExtensionContext,
Expand Down Expand Up @@ -134,7 +135,9 @@ export function registerViewEvent(
commands.registerCommand('leet-fund.fundItemClick', (code, name) => fundTrend(code, name))
);
// 基金右键历史信息点击
commands.registerCommand('leek-fund.viewFundHistory', (item) => fundHistory(service, item));
commands.registerCommand('leek-fund.viewFundHistory', (item) => fundHistory(item));
// 基金持仓
commands.registerCommand('leek-fund.viewFundPosition', (item) => fundPosition(item));
// 基金排行
commands.registerCommand('leek-fund.viewFundRank', () => fundRank(service));
// 基金走势图
Expand Down
72 changes: 2 additions & 70 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,62 +71,10 @@ export class LeekFundService {
this._barStockList = value;
}

private fundUrl(code: string): string {
const fundUrl = `http://fundgz.1234567.com.cn/js/${code}.js?rt="${new Date().getTime()}`;
return fundUrl;
}
private fundHistoryUrl(code: string): string {
const fundUrl = `http://fund.eastmoney.com/f10/F10DataApi.aspx?type=lsjz&code=${code}&page=1&per=24`;
return fundUrl;
}
private stockUrl(codes: Array<string>): string {
return `https://hq.sinajs.cn/list=${codes.join(',')}`;
}

toggleLabel() {
this.showLabel = !this.showLabel;
}

/*
// 老接口
singleFund(code: string): Promise<FundInfo> {
const url = this.fundUrl(code);
return new Promise((resolve) => {
axios
// @ts-ignore
.get(url, { headers: randHeader() })
.then((rep) => {
const data = JSON.parse(rep.data.slice(8, -2));
const { gszzl, gztime, name } = data;
resolve({ percent: gszzl, code, time: gztime, name });
})
.catch(() => resolve({ percent: 'NaN', name: '接口不支持该基金实时信息', code }));
});
}
async getFundData2(fundCodes: Array<string>, order: number): Promise<Array<LeekTreeItem>> {
console.log('fetching fund data……');
const promiseAll = [];
for (const fundCode of fundCodes) {
promiseAll.push(this.singleFund(fundCode));
}
try {
const result = await Promise.all(promiseAll);
const data = result.map((item) => {
item.showLabel = this.showLabel;
return new LeekTreeItem(item, this.context);
});
this.fundList = sortData(data, order);
// console.log(data);
return this.fundList;
} catch (err) {
console.log(err);
return this.fundList;
}
}
*/

static qryFundMNFInfo(fundCodes: string[]): Promise<any> {
const params: any = {
pageIndex: 1,
Expand Down Expand Up @@ -279,30 +227,14 @@ export class LeekFundService {
}
}

async getFundHistoryByCode(code: string) {
try {
const response = await axios.get(this.fundHistoryUrl(code), {
headers: randHeader(),
});

const idxs = response.data.indexOf('"<table');
const lastIdx = response.data.indexOf('</table>"');
const content = response.data.slice(idxs + 1, lastIdx);
// console.log(idxs, lastIdx, content);
return { code, content };
} catch (err) {
console.log(err);
return { code, content: '历史净值获取失败' };
}
}

async getStockData(codes: Array<string>, order: number): Promise<Array<LeekTreeItem>> {
console.log('fetching stock data…');
if ((codes && codes.length === 0) || !codes) {
return [];
}
const statusBarStocks = this.model.getCfg('leek-fund.statusBarStock');
const url = this.stockUrl(codes);

const url = `https://hq.sinajs.cn/list=${codes.join(',')}`;
try {
const resp = await axios.get(url, {
// axios 乱码解决
Expand Down
52 changes: 35 additions & 17 deletions src/webview/fundHistory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import Axios from 'axios';
import { ViewColumn } from 'vscode';
import { LeekTreeItem } from '../leekTreeItem';
import ReusedWebviewPanel from '../ReusedWebviewPanel';
import { LeekFundService } from '../service';
import { randHeader } from '../utils';

async function fundHistory(service: LeekFundService, item: LeekTreeItem) {
const fundHistoryUrl = (code: string): string => {
return `http://fund.eastmoney.com/f10/F10DataApi.aspx?type=lsjz&code=${code}&page=1&per=49`;
};

async function getFundHistoryByCode(code: string) {
try {
const response = await Axios.get(fundHistoryUrl(code), {
headers: randHeader(),
});

const idxs = response.data.indexOf('"<table');
const lastIdx = response.data.indexOf('</table>"');
const content = response.data.slice(idxs + 1, lastIdx);
// console.log(idxs, lastIdx, content);
return { code, content };
} catch (err) {
console.log(err);
return { code, content: '历史净值获取失败' };
}
}

async function fundHistory(item: LeekTreeItem) {
const { code, name } = item.info;
const res = await service.getFundHistoryByCode(code);
const res = await getFundHistoryByCode(code);
const panel = ReusedWebviewPanel.create(
'fundRankWebview',
`基金持仓&历史净值(${code})`,
'fundHistoryWebview',
`基金历史净值(${code})`,
ViewColumn.One,
{
enableScripts: true,
Expand Down Expand Up @@ -37,24 +59,20 @@ async function fundHistory(service: LeekFundService, item: LeekTreeItem) {
.fund-sstrend{
width:700px;
}
.box {
border-top: 1px solid #bababa;
padding: 10px;
margin-top:20px;
}
</style>
<body>
<br/>
<p style="text-align: center; font-size:18px; width: 400px;margin: 0 auto;">「${name}」持仓信息</p>
<div class="trend"><img
class="fund-sstrend"
src="http://j6.dfcfw.com/charts/StockPos/${code}.png?rt=${new Date().getTime()}"
alt="「${name}」- ${code}"
/>
<p>
<a href="http://fundf10.eastmoney.com/ccmx_${code}.html" target="_blank">查看全部持仓明细>></a>
</p>
</div>
<div class="history">
<p style="text-align: center; font-size:18px; width: 400px;margin: 0 auto;">「${name}」历史净值</p>
<hr />
<div class="box">
${res.content}
</div>
</div>
</body></html>`;
}

Expand Down
Loading

0 comments on commit 50a7599

Please sign in to comment.