Skip to content

Commit

Permalink
Merge pull request #490 from c-rick/master
Browse files Browse the repository at this point in the history
feat: add biance trend
  • Loading branch information
giscafer authored Oct 22, 2024
2 parents 7c5a249 + e8cd3e7 commit 31ca045
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 20 deletions.
8 changes: 8 additions & 0 deletions src/registerCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import stockTrend from './webview/stockTrend';
import stockTrendPic from './webview/stockTrendPic';
import tucaoForum from './webview/tucaoForum';
import { StatusBar } from './statusbar/statusBar';
import binanceTrend from './webview/binanceTrend';

export function registerViewEvent(
context: ExtensionContext,
Expand Down Expand Up @@ -364,6 +365,13 @@ export function registerViewEvent(
binanceProvider.changeOrder();
});

/* 点击交易对 */
context.subscriptions.push(
commands.registerCommand('leek-fund.binanceItemClick', (code, name) =>
binanceTrend(name)
)
);

/**
* Forex command
*/
Expand Down
44 changes: 24 additions & 20 deletions src/shared/leekTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ export class LeekTreeItem extends TreeItem {
this._itemType = isStock ? TreeItemType.STOCK : TreeItemType.FUND;
}

const isStockItem = this._itemType === TreeItemType.STOCK;
const isFundItem = this._itemType === TreeItemType.FUND;
const isBinanceItem = this._itemType === TreeItemType.BINANCE;
const isForex = this._itemType === TreeItemType.FOREX;

this.type = type;
this.contextValue = contextValue;
let _percent: number | string = Math.abs(percent);
Expand Down Expand Up @@ -119,7 +124,7 @@ export class LeekTreeItem extends TreeItem {

if (showLabel) {
/* `showLabel: true` */
if (this._itemType === TreeItemType.STOCK) {
if (isStockItem) {
const risePercent = isStop ? '停牌' : `${_percent}%`;
if (type === 'nodata') {
text = info.name;
Expand All @@ -130,15 +135,15 @@ export class LeekTreeItem extends TreeItem {
)}「${name}」`; */
text = formatLabelString(
globalState.labelFormat?.['sidebarStockLabelFormat'] ??
DEFAULT_LABEL_FORMAT.sidebarStockLabelFormat,
DEFAULT_LABEL_FORMAT.sidebarStockLabelFormat,
{
...info,
icon: !isIconPath ? iconPath : '',
percent: risePercent,
}
);
}
} else if (this._itemType === TreeItemType.FUND) {
} else if (isFundItem) {
/* text =
`${!isIconPath ? iconPath : ''}${formatTreeText(`${_percent}%`)}「${name}」${
t2 || !(globalState.showEarnings && amount > 0)
Expand All @@ -147,7 +152,7 @@ export class LeekTreeItem extends TreeItem {
}` + `${t2 ? `(${time})` : ''}`; */
text = formatLabelString(
globalState.labelFormat?.['sidebarFundLabelFormat'] ??
DEFAULT_LABEL_FORMAT.sidebarFundLabelFormat,
DEFAULT_LABEL_FORMAT.sidebarFundLabelFormat,
{
...info,
icon: !isIconPath ? iconPath : '',
Expand All @@ -160,20 +165,20 @@ export class LeekTreeItem extends TreeItem {
}
);
// ${earningPercent !== 0 ? ',率:' + earningPercent + '%' : ''}
} else if (this._itemType === TreeItemType.BINANCE) {
} else if (isBinanceItem) {
text = formatLabelString(
globalState.labelFormat?.['sidebarBinanceLabelFormat'] ??
DEFAULT_LABEL_FORMAT.sidebarBinanceLabelFormat,
DEFAULT_LABEL_FORMAT.sidebarBinanceLabelFormat,
{
...info,
icon: !isIconPath ? iconPath : '',
percent: `${_percent}%`,
}
);
} else if (this._itemType === TreeItemType.FOREX) {
} else if (isForex) {
text = formatLabelString(
globalState.labelFormat?.['sidebarForexLabelFormat'] ??
DEFAULT_LABEL_FORMAT.sidebarForexLabelFormat,
DEFAULT_LABEL_FORMAT.sidebarForexLabelFormat,
{
...info,
}
Expand All @@ -182,7 +187,7 @@ export class LeekTreeItem extends TreeItem {
} else {
/* `showLabel: false` */
text =
this._itemType === TreeItemType.STOCK
isStockItem
? `${formatTreeText(`${_percent}%`, 11)}${formatTreeText(price, 15)}${code}」`
: `${formatTreeText(`${_percent}%`)}${code}」`;
}
Expand All @@ -196,8 +201,7 @@ export class LeekTreeItem extends TreeItem {
this.label = text;
}
this.id = info.id || code;

if (this._itemType === TreeItemType.STOCK || this._itemType === TreeItemType.FUND) {
if (isStockItem || isFundItem || isBinanceItem) {
let typeAndSymbol = `${type}${symbol}`;
const isFuture = /nf_/.test(code) || /hf_/.test(code);
if (isFuture) {
Expand All @@ -206,11 +210,12 @@ export class LeekTreeItem extends TreeItem {
this.command = {
title: name, // 标题
command:
this._itemType === TreeItemType.STOCK
isStockItem
? 'leek-fund.stockItemClick'
: 'leek-fund.fundItemClick', // 命令 ID
: isBinanceItem ? 'leek-fund.binanceItemClick'
: 'leek-fund.fundItemClick', // 命令 ID
arguments: [
this._itemType === TreeItemType.STOCK ? '0' + symbol : code, // 基金/股票编码
isStockItem ? '0' + symbol : code, // 基金/股票编码
name, // 基金/股票名称
text,
typeAndSymbol,
Expand All @@ -221,7 +226,7 @@ export class LeekTreeItem extends TreeItem {
}
}

if (this._itemType === TreeItemType.STOCK) {
if (isStockItem) {
const labelText = !showLabel ? name : '';

const isFuture = /nf_/.test(code) || /hf_/.test(code);
Expand All @@ -235,13 +240,12 @@ export class LeekTreeItem extends TreeItem {
} else if (isFuture) {
this.tooltip = `【今日行情】${name} ${code}\n 涨跌:${updown} 百分比:${_percent}%\n 最高:${high} 最低:${low}\n 今开:${open} 昨结:${yestclose}\n 成交量:${volume} 成交额:${amount}`;
} else {
this.tooltip = `【今日行情】${labelText}${typeText}${symbolText}\n 涨跌:${updown} 百分比:${_percent}%\n 最高:${high} 最低:${low}\n 今开:${open} 昨收:${yestclose}\n 成交量:${volume} 成交额:${amount}\n ${
heldAmount ? `持仓数:${volume} 持仓价:${heldPrice}` : ''
}`;
this.tooltip = `【今日行情】${labelText}${typeText}${symbolText}\n 涨跌:${updown} 百分比:${_percent}%\n 最高:${high} 最低:${low}\n 今开:${open} 昨收:${yestclose}\n 成交量:${volume} 成交额:${amount}\n ${heldAmount ? `持仓数:${volume} 持仓价:${heldPrice}` : ''
}`;
}
} else if (this._itemType === TreeItemType.BINANCE) {
} else if (isBinanceItem) {
this.tooltip = `【今日行情】${name}\n 涨跌:${updown} 百分比:${_percent}%\n 最高:${high} 最低:${low}\n 今开:${open} 昨收:${yestclose}\n 成交量:${volume} 成交额:${amount}`;
} else if (this._itemType === TreeItemType.FOREX) {
} else if (isForex) {
this.tooltip = `现汇买入价:${spotBuyPrice}\n现钞买入价:${cashBuyPrice}\n现汇卖出价:${spotSellPrice}\n现钞卖出价:${cashSellPrice}\n中行折算价:${conversionPrice}\n发布日期:${publishDateTime}`;
} else {
this.tooltip = `「${name}」(${code})`;
Expand Down
60 changes: 60 additions & 0 deletions src/webview/binanceTrend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { ViewColumn } from 'vscode';
import ReusedWebviewPanel from './ReusedWebviewPanel';

function binanceTrend(name: string) {
const [token, unit] = name.split('_');
const tabTitle = `${token}${unit} | 现货交易`;

const panel = ReusedWebviewPanel.create('binanceTrendWebview', tabTitle, ViewColumn.One, {
enableScripts: true,
});

panel.webview.html = panel.webview.html = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${tabTitle}</title>
<style>
html.vscode-dark, body.vscode-dark, html.vscode-high-contrast, body.vscode-high-contrast {
filter: invert(100%) hue-rotate(180deg);
}
html, body {
width: 100%;
height: 100%;
min-width: 600px;
min-height: 400px;
padding: 0;
}
</style>
</head>
<body>
<div class="tradingview-widget-container">
<div id="tradingview_chart"></div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
new TradingView.widget({
"width": "100%",
"height": "100%",
"symbol": "BINANCE:${token}${unit}",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "light",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": false,
"withdateranges": true,
"hide_side_toolbar": false,
"allow_symbol_change": true,
"container_id": "tradingview_chart"
});
</script>
</div>
</body>
</html>
`;
}

export default binanceTrend;

0 comments on commit 31ca045

Please sign in to comment.