Skip to content

Commit

Permalink
Merge pull request #413 from tlff/stock
Browse files Browse the repository at this point in the history
fix: 计算股票收益只计算自选的股票
  • Loading branch information
giscafer authored Feb 2, 2024
2 parents e3dfb07 + 96f1ec0 commit ece0375
Show file tree
Hide file tree
Showing 9 changed files with 4,308 additions and 4,110 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@
"@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^2.30.0",
"@typescript-eslint/parser": "^2.30.0",
"@vscode/test-electron": "^2.3.9",
"cross-env": "^7.0.3",
"eslint": "^6.8.0",
"glob": "^7.1.6",
Expand Down
28 changes: 14 additions & 14 deletions src/_test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import * as path from 'path';

import { runTests } from 'vscode-test';
import { runTests } from '@vscode/test-electron';

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');

// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}

main();
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
2 changes: 1 addition & 1 deletion template-packages/leek-center/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"scripts": {
"prebuild": "yarn --frozen-lockfile",
"start": "node scripts/start.js",
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider && cross-env GENERATE_SOURCEMAP=false node scripts/build.js",
"build": "cross-env NODE_OPTIONS=--openssl-legacy-provider GENERATE_SOURCEMAP=false node scripts/build.js",
"build2": "if \"%OS%\" == \"Windows_NT\" then (SET NODE_OPTIONS=--openssl-legacy-provider && cross-env GENERATE_SOURCEMAP=false node scripts/build.js) else (export NODE_OPTIONS=--openssl-legacy-provider && cross-env GENERATE_SOURCEMAP=false node scripts/build.js)",
"test": "node scripts/test.js"
},
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
Loading

0 comments on commit ece0375

Please sign in to comment.