|
|
@@ -6,37 +6,40 @@ export function activate() {
|
|
|
const oneItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 9998);
|
|
|
const twoItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 9997);
|
|
|
|
|
|
- setInterval(() => {
|
|
|
- oneItem.color = 'rgba( 255,255,255,0.4)';
|
|
|
- twoItem.color = 'rgba( 255,255,255,0.4)';
|
|
|
- axios.all([
|
|
|
- axios.post('https://webapi.huilv.cc/api/trend/yaho', { pinzhong: 'CNYUSD', longs: 'd1' }),
|
|
|
- axios.get('https://futsseapi.eastmoney.com/list/variety/101/1?orderBy=zdf&sort=desc&pageSize=12&pageIndex=0&token=1101ffec61617c99be287c1bec3085ff&field=name,dm,zdf,p'),
|
|
|
- axios.get('https://push2.eastmoney.com/api/qt/stock/get?fields=f58,f734,f107,f57,f43,f59,f169,f170,f152,f177,f111,f46,f60,f44,f45,f86,f47,f19,f532,f161,f171,f48,f39,f49,f50&secid=118.AU9999')
|
|
|
- ]).then(axios.spread((rate, interGold, gold) => {
|
|
|
- const { data: { obj } } = rate; //汇率
|
|
|
- const { data: { list } } = interGold; // 国际金
|
|
|
- const { data: { data: { f60, f19 } } } = gold; // 国内
|
|
|
-
|
|
|
- // 国际
|
|
|
- const rateItem = 1 / obj[obj.length - 1].huilv; //汇率转换
|
|
|
- const { p, zdf } = list.find((el: { dm: string; }) => el.dm === 'GC00Y') || { p: 0, zdf: 0 };
|
|
|
- const oneGold = Math.floor(p * rateItem / 31.1035 * 100) / 100 || 0; // 国际金转换
|
|
|
- const oneTxt = `COMEX黄金: ${oneGold}(${zdf}%)`;
|
|
|
+ axios.get('https://87.futsseapi.eastmoney.com/sse/101_GC00Y_qt?token=1101ffec61617c99be287c1bec3085ff&field=name,sc,dm,p,zsjd,zdf,zde,utime,o,zjsj,qrspj,h,l,mrj,mcj,vol,cclbh,zt,dt,np,wp,ccl,rz,cje,mcl,mrl,jjsj,j,lb,zf', {
|
|
|
+ headers: { Accept: 'text/text/event-stream' }, responseType: 'stream'
|
|
|
+ }).then(res => {
|
|
|
+ const eventStream = res.data;
|
|
|
+ let O = 0
|
|
|
+ eventStream.on('data', (chunk: Uint8Array) => {
|
|
|
+ oneItem.color = 'rgba( 255,255,255,0.4)';
|
|
|
+ twoItem.color = 'rgba( 255,255,255,0.4)';
|
|
|
+ // 国际金
|
|
|
+ const str = chunk.toString().split('\n')
|
|
|
+ if (!str[0]) return
|
|
|
+ const jsonStr = str[0].replace(/^data:/, '');
|
|
|
+ if (!jsonStr) return
|
|
|
+ const data = JSON.parse(jsonStr);
|
|
|
+ if (!data) return
|
|
|
+ const { zdf, zde, p, o } = data.qt
|
|
|
+ if (!zdf || !zde || !p) return
|
|
|
+ if (o) O = o
|
|
|
+ // 当前:p 营收: zde 营收率: zdf 昨收:o
|
|
|
+ const oneTxt = `国际黄金: ${p}/${O} (${zde} ${zdf}%)`;
|
|
|
oneItem.color = zdf > 0 ? 'red' : 'green';
|
|
|
oneItem.text = oneTxt;
|
|
|
|
|
|
- // 国内
|
|
|
- const twoGold = Math.floor(f19) / 100 || 0; // 国内金转换
|
|
|
- const twoNum = Math.floor((f19 - f60)) / 100 || 0; //营收
|
|
|
- const twoRate = Math.floor((f19 - f60) / f19 * 10000) / 100 || 0; //营收率
|
|
|
- const twoTxt = `国内AU999: ${twoGold}(${twoNum > 0 ? '+' + twoNum : twoNum} ${twoRate > 0 ? '+' + twoRate + '%' : twoRate + '%'})`;
|
|
|
- twoItem.color = twoNum > 0 ? 'red' : 'green';
|
|
|
- twoItem.text = twoTxt;
|
|
|
+ // 国内金
|
|
|
+ axios.get('https://push2.eastmoney.com/api/qt/stock/get?fields=f58,f734,f107,f57,f43,f59,f169,f170,f152,f177,f111,f46,f60,f44,f45,f86,f47,f19,f532,f161,f171,f48,f39,f49,f50&secid=118.AU9999').then(red => {
|
|
|
+ const { data: { data: { f43, f169, f170, f60 } } } = red; // 国内
|
|
|
+ // 当前:f43 营收: f169 营收率: f170 昨收:f60
|
|
|
+ const twoTxt = `国内AU999: ${Math.floor(f43) / 100}/${Math.floor(f60) / 100} (${Math.floor(f169) / 100} ${Math.floor(f170) / 100}%)`;
|
|
|
+ twoItem.color = f169 > 0 ? 'red' : 'green';
|
|
|
+ twoItem.text = twoTxt;
|
|
|
+ })
|
|
|
+ })
|
|
|
+ })
|
|
|
|
|
|
- console.log(666, p, rateItem, oneGold, twoGold);
|
|
|
- }));
|
|
|
- }, 1000);
|
|
|
oneItem.show();
|
|
|
twoItem.show();
|
|
|
}
|