简体   繁体   English

如何将交易视图集成到电子中

[英]How to integrate trading view into electron

I wanted to build trading apps using electron JS and using the TradingView library but I got stuck on how to implement it.我想使用电子JS 和 TradingView 库来构建交易应用程序,但我被困在如何实现它上。 I also created a new blank project to implement it, but still result.我还创建了一个新的空白项目来实现它,但仍然有结果。

Is there anyone has ever implement TradingView to electron and could give me solution to this?有没有人曾经对电子实施过 TradingView 并可以给我解决方案?

Blank app result空白应用结果

在此处输入图像描述

Error in console控制台错误

 <!DOCTYPE html> <html> <head> <script type="text/javascript" src="https://demo_chart.tradingview.com/charting_library/charting_library.min.js"></script> <script type="text/javascript" src="https://demo_chart.tradingview.com/datafeeds/udf/dist/polyfills.js"></script> <script type="text/javascript" src="https://demo_chart.tradingview.com/datafeeds/udf/dist/bundle.js"></script> <script type="text/javascript"> function getParameterByName(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); } TradingView.onready(function() { var widget = window.tvWidget = new TradingView.widget({ // debug: true, // uncomment this line to see Library errors and warnings in the console fullscreen: true, symbol: 'AAPL', interval: 'D', container_id: "tv_chart_container", // BEWARE: no trailing slash is expected in feed URL datafeed: new Datafeeds.UDFCompatibleDatafeed("https://demo_feed.tradingview.com"), library_path: "charting_library/", locale: getParameterByName('lang') || "en", disabled_features: ["use_localstorage_for_settings"], enabled_features: ["study_templates"], charts_storage_url: 'http://saveload.tradingview.com', charts_storage_api_version: "1.1", client_id: 'tradingview.com', user_id: 'public_user_id', theme: getParameterByName('theme'), }); }); </script> </head> <body style="margin:0px;"> <div id="tv_chart_container"></div> </body> </html>


Never used electron so using this opportunity to try it out myself.从来没有使用过电子,所以利用这个机会自己尝试一下。 This is the steps I took.这是我采取的步骤。

Look at the documentation https://electronjs.org/docs/tutorial/first-app查看文档https://electronjs.org/docs/tutorial/first-app

1) created a folder called electron-test 1) 创建了一个名为 electron-test 的文件夹

2) run command npm init in that folder 2)在该文件夹中运行命令 npm init

3) modify package.json to be this 3) 将 package.json 修改为这样

{
  "name": "electron-test",
  "version": "1.0.0",
  "description": "",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "",
  "license": "ISC",
  "dependencies": {}
}

4) create main.js 4)创建main.js

const { app, BrowserWindow } = require("electron");

function createWindow() {
  // Create the browser window.
  win = new BrowserWindow({ width: 800, height: 600 });

  // and load the index.html of the app.
  win.loadFile("index.html");
}

app.on("ready", createWindow);

5) create index.html 5) 创建 index.html

6) run command npm install electron 6) 运行命令 npm install electron

7) run command npm start 7) 运行命令 npm start

This is the result这是结果

在此处输入图像描述

Is there anyone has ever implement TradingView to electron and could give me solution to this?有没有人曾经对电子实施过 TradingView 并可以给我解决方案?

Well I don't have solution to the error, but I have found my way out to build an tradingView+ElectronJs app.好吧,我没有解决该错误的方法,但我找到了构建一个 tradingView+ElectronJs 应用程序的方法。

In short, you can start with TradingView Charting Library Integration Examples , from which you can choose the kind of integration template to start with(I just use react-javascript to start my app).And I just take this template for example.简而言之,您可以从TradingView Charting Library Integration Examples开始,您可以从中选择要开始的集成模板类型(我只是使用 react-javascript 来启动我的应用程序)。我只是以这个模板为例。

After follow How to start to configure the app properly.按照如何开始正确配置应用程序后。 You should first install election to your app(which means run npm install --save electron in the directory root), then add the main.js to your directory root, and configure your package.json and main.js properly.您应该首先将选举安装到您的应用程序(这意味着在目录根目录中运行npm install --save electron ),然后将 main.js 添加到您的目录根目录,并正确配置您的 package.json 和 main.js。 Blow is my package.json and main.js code. Blow 是我的 package.json 和 main.js 代码。

package.json包.json

{
"name": "knownsec-fed",
"version": "0.1.0",
"private": true,
"main": "main.js", // 配置启动文件
"homepage":".", // 
"dependencies": {
  "electron": "^1.7.10",
  "react": "^16.2.0",
  "react-dom": "^16.2.0",
  "react-scripts": "1.1.0"
},
"scripts": {
  "start": "react-scripts start",
  "build": "react-scripts build",
  "test": "react-scripts test --env=jsdom",
  "eject": "react-scripts eject",
  "electron-start": "electron ." // start electron app
}

} }

main.js main.js

    const {app, BrowserWindow} = require('electron')
    const path = require('path')
    const url = require('url')

    let mainWindow

    function createWindow () {

    mainWindow = new BrowserWindow({width: 800, height: 600})

      /**
        mainWindow.loadURL(url.format({
          pathname: path.join(__dirname, 'index.html'),
          protocol: 'file:',
          slashes: true
        }))
      */

      mainWindow.loadURL('http://localhost:3000/');


      // mainWindow.webContents.openDevTools()


      mainWindow.on('closed', function () {
        mainWindow = null
      })
    }

    app.on('ready', createWindow)

    app.on('window-all-closed', function () {
      if (process.platform !== 'darwin') {
        app.quit()
      }
    })

    app.on('activate', function () {
      if (mainWindow === null) {
        createWindow()
      }
    })

to start the electron app, first run npm start to start react then run npm run electron-start to start electron app and then all thing done.要启动电子应用程序,首先运行npm start开始反应,然后运行npm run electron-start启动电子应用程序,然后所有事情都完成了。

When you open Object with widget, your widget trying to find static folder from wrong path.当您使用小部件打开对象时,您的小部件试图从错误的路径中查找静态文件夹。 Just connect library in widget option like this:只需在小部件选项中连接库,如下所示:

我的代码图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM