Skip to content

Commit

Permalink
fix: 计算股票收益只计算自选的股票
Browse files Browse the repository at this point in the history
  • Loading branch information
tlf committed Feb 1, 2024
1 parent aba2446 commit e1d8768
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .vscode/bookmarks.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"path": "src/explorer/stockService.ts",
"bookmarks": [
{
"line": 66,
"line": 77,
"column": 2,
"label": ""
}
Expand Down
11 changes: 10 additions & 1 deletion src/explorer/stockService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ export default class StockService extends LeekService {
super();
this.context = context;
}

/**
* 获取自选,去掉大盘数据
* @returns
*/
getSelfSelected() {
const s =
'sh000001,sh000300,sh000016,sh000688,usr_ixic,usr_dji,usr_inx,nf_IF0,nf_IH0,nf_IC0,nf_IM0,hf_OIL,hf_CHA50CFD';
const maps = s.split(',');
return this.stockList.filter((item) => !maps.includes(item.info.code));
}
async getToken(): Promise<string> {
if (this.token !== '') return this.token;

Expand Down
7 changes: 5 additions & 2 deletions src/statusbar/Profit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class ProfitStatusBar {
unitPrice: number;
};
} = globalState.stockPrice;
const stockList = data.stockList;
const stockList = data.getSelfSelected();
type StockInfoType = {
id: string;
name: string;
Expand Down Expand Up @@ -159,8 +159,11 @@ export class ProfitStatusBar {
const allIncomeToday = stockInfo.reduce((prev, cur) => {
return prev + Number(cur.incomeToday);
}, 0);
const allIncomeTotal = stockInfo.reduce((prev, cur) => {
return prev + Number(cur.incomeTotal);
}, 0);
// Use the year, month, and day variables as needed
this.stockBarItem.text = `${PREFIX} ${allIncomeToday}`;
this.stockBarItem.text = `${PREFIX} ${allIncomeTotal} | ${allIncomeToday}`;
// this.stockBarItem.color = fundProfit >= 0 ? this.riseColor : this.fallColor;
this.stockBarItem.tooltip =
`「股票收益统计」 ${date}\r\n \r\n` +
Expand Down
2 changes: 1 addition & 1 deletion src/webview/setStockPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function setStockPrice(stockService: StockService) {
}

function stockDataHandler(stockService: StockService) {
const fundList: LeekTreeItem[] = cloneDeep(stockService.stockList);
const fundList: LeekTreeItem[] = cloneDeep(stockService.getSelfSelected());
console.log('list', fundList);
const amountObj: any = globalState.stockPrice || {};
const list = fundList.map((item: LeekTreeItem) => {
Expand Down
12 changes: 6 additions & 6 deletions template/stock-price.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@
收益率↓
</button>
<div class="main">
<h2 style="text-align: center; color: #409eff">
<!-- <h2 style="text-align: center; color: #409eff">
持仓股数 <span id="totalMoney"></span>
</h2>
</h2> -->

<p style="font-size: 12px; color: #696666; text-align: center">
<!-- <p style="font-size: 12px; color: #696666; text-align: center">
现在填写金额按昨日净值计算,所以今日加仓的建议明日更新持仓金额
</p>
</p> -->
<div class="list"></div>
<div class="footer">
<button
Expand All @@ -164,14 +164,14 @@ <h2 style="text-align: center; color: #409eff">
</button>
<div class="info"></div>
<div class="operate rm">
<span style="color: #50ba99; cursor: pointer" class="text2image"
<!-- <span style="color: #50ba99; cursor: pointer" class="text2image"
>持仓图片分享</span
>&nbsp;&nbsp;&nbsp;&nbsp;<span
style="color: #50ba99; cursor: pointer"
class="text2image"
data-type="shouyi"
>收益图片分享</span
>
> -->
</div>
</div>
</div>
Expand Down

0 comments on commit e1d8768

Please sign in to comment.