TradingView udf模式

第一步:申請(qǐng)tv

官網(wǎng)地址:免費(fèi)股票圖表、行情和交易觀點(diǎn) — TradingView(需要以公司名義申請(qǐng))

第二步:相關(guān)資料

文檔:https://b.aitrade.ga/books/tradingview/book/How-To-Connect-My-Data.html

官網(wǎng)demo:https://github.com/tradingview/charting-library-examples

官網(wǎng)demo是目前tv所支持的添祸,下載適合你的

第三步:運(yùn)行項(xiàng)目(以vue為例)

申請(qǐng)的tv 會(huì)在你的github上懦窘,把對(duì)應(yīng)的文件放在demo對(duì)應(yīng)的地方

類似于下圖

直接npm install 安裝完運(yùn)行即可看到

第四步:tv配置項(xiàng)代碼

1.預(yù)覽地址:https://k.zg1.top/

2.配置項(xiàng)代碼:vue 為例

<script>

import { widget } from '../charting_library.min';

function getLanguageFromURL() {

? const regex = new RegExp('[\\?&]lang=([^&#]*)');

? const results = regex.exec(window.location.search);

? return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' '));

}

// window.location.search.split("=")[2]? BTC/USDT

export default {

? name: 'TVChartContainer',

? props: {

? ? symbol: {

? ? ? default: window.location.search.split("=")[2] || "BTC/USDT",

? ? ? type: String,

? ? },

? ? interval: {

? ? ? default: '15',

? ? ? type: String,

? ? },

? ? containerId: {

? ? ? default: 'tv_chart_container',

? ? ? type: String,

? ? },

? ? datafeedUrl: {

? ? ? default: 'https://zg.top/api/v2/market/tradingview',

? ? ? type: String,

? ? },

? ? libraryPath: {

? ? ? default: '/charting_library/',

? ? ? type: String,

? ? },

? ? // chartsStorageUrl: {

? ? //? default: 'https://saveload.tradingview.com',

? ? //? type: String,

? ? // },

? ? chartsStorageApiVersion: {

? ? ? default: '1.1',

? ? ? type: String,

? ? },

? ? clientId: {

? ? ? default: 'tradingview.com',

? ? ? type: String,

? ? },

? ? // userId: {

? ? //? default: 'public_user_id',

? ? //? type: String,

? ? // },

? ? fullscreen: {

? ? ? default: true,

? ? ? type: Boolean,

? ? },

? ? autosize: {

? ? ? default: true,

? ? ? type: Boolean,

? ? },

? ? custom_css_url:{

? ? ? default: '/chart.css',

? ? ? type: String,

? ? },

? ? overrides:{

? ? ? 'paneProperties.background': '#162431', // 蠟燭樣式

? ? ? 'mainSeriesProperties.candleStyle.upColor': '#64ae74',

? ? ? 'mainSeriesProperties.candleStyle.downColor': '#df5f61',

? ? ? // 燭心

? ? ? 'mainSeriesProperties.candleStyle.drawWick': true,

? ? ? // 燭心顏色

? ? ? 'mainSeriesProperties.candleStyle.wickUpColor': '#64ae74',

? ? ? 'mainSeriesProperties.candleStyle.wickDownColor': '#df5f61',

? ? ? // 邊框

? ? ? 'mainSeriesProperties.candleStyle.drawBorder': true,

? ? ? 'mainSeriesProperties.candleStyle.borderUpColor': '#64ae74',

? ? ? 'mainSeriesProperties.candleStyle.borderDownColor': '#df5f61',

? ? ? // 網(wǎng)格

? ? ? 'paneProperties.vertGridProperties.style': 0,

? ? ? 'paneProperties.horzGridProperties.color':'#FFFFFF',

? ? ? 'paneProperties.vertGridProperties.color': '#FFFFFF',

? ? ? "volumePaneSize":"large",

? ? ? // 坐標(biāo)軸和刻度標(biāo)簽顏色

? ? ? 'scalesProperties.lineColor': '#252525',

? ? ? 'scalesProperties.textColor': '#8a8a8a',

? ? ? 'paneProperties.legendProperties.showLegend': false,

? ? ? 'paneProperties.topMargin': 20,

? ? },

? ? studiesOverrides: {

? ? ? "volume.volume.color.0": "#00FFFF",

? ? ? "volume.volume.color.1": "#0000FF",

? ? ? "volume.volume.transparency": 70,

? ? ? "volume.volume ma.color": "#FF0000",

? ? ? "volume.volume ma.transparency": 30,

? ? ? "volume.volume ma.linewidth": 5,

? ? ? "volume.show ma": true,

? ? ? "bollinger bands.median.color": "#33FF88",

? ? ? "bollinger bands.upper.linewidth": 7,

? ? ? type: Object,

? ? }

? },

? tvWidget: null,

? mounted() {

? ? const widgetOptions = {

? ? ? symbol: this.symbol,

? ? ? // BEWARE: no trailing slash is expected in feed URL

? ? ? // theme: 'White',

? ? ? theme: 'Dark',

? ? ? timezone:"Asia/Shanghai",

? ? ? datafeed: new window.Datafeeds.UDFCompatibleDatafeed(this.datafeedUrl),

? ? ? interval: this.interval,

? ? ? container_id: this.containerId,

? ? ? library_path: this.libraryPath,

? ? ? locale: getLanguageFromURL() || 'zh',

? ? ? disabled_features: [

? ? ? ? 'use_localstorage_for_settings',

? ? ? ? "volume_force_overlay",//柱狀分離

? ? ? ? "timeframes_toolbar",//底部時(shí)間軸

? ? ? ? "header_symbol_search",//頭部搜索

? ? ? ? "legend_context_menu",

? ? ? ? "header_screenshot",//相機(jī)

? ? ? ? "header_settings",//設(shè)置

? ? ? ? "header_saveload",//保存

? ? ? ? "header_fullscreen_button",//全屏

? ? ? ? 'display_market_status',//休市

? ? ? ? "header_undo_redo",//返回按鈕

? ? ? ? "header_compare",//對(duì)比

? ? ? ? "header_indicators",//指標(biāo)

? ? ? ? "header_chart_type",//K線圖切換

? ? ? ? // "header_resolutions",//時(shí)間切換

? ? ? ? 'main_series_scale_menu',


? ? ? ],

? ? ? enabled_features: [

? ? ? ? 'study_templates',

? ? ? ? // 'hide_left_toolbar_by_default',//當(dāng)用戶第一次打開圖表時(shí)弃甥,隱藏左側(cè)工具欄

? ? ? ? 'show_dom_first_time',//當(dāng)用戶第一次打開圖表時(shí)顯示 DOM 面板

? ? ? ? 'hide_last_na_study_output',//隱藏最后的 n/a 指標(biāo)輸出數(shù)據(jù)

? ? ? ? // "timeframes_toolbar",

? ? ? ],

? ? ? // charts_storage_url: this.chartsStorageUrl,

? ? ? charts_storage_api_version: this.chartsStorageApiVersion,

? ? ? client_id: this.clientId,

? ? ? user_id: this.userId,

? ? ? fullscreen: this.fullscreen,

? ? ? autosize: this.autosize,

? ? ? overrides:this.overrides,


? ? ? studies_overrides: this.studiesOverrides,

? ? ? custom_css_url:this.custom_css_url,

? ? ? customFormatters: {

? ? ? ? timeFormatter: {

? ? ? ? ? format: function(date) {

? ? ? ? ? ? var _format_str = '%h:%m';

? ? ? ? ? ? return _format_str.replace('%h', date.getUTCHours(), 2). replace('%m', date.getUTCMinutes(), 2). replace('%s', date.getUTCSeconds(), 2); }

? ? ? ? },

? ? ? ? dateFormatter: {

? ? ? ? ? format: function(date) {

? ? ? ? ? ? return date.getUTCFullYear() + '/' + (date.getUTCMonth()+1) + '/' + date.getUTCDate();

? ? ? ? ? ? }

? ? ? ? }

? ? ? }

? ? };

? ? const tvWidget = new widget(widgetOptions);

? ? this.tvWidget = tvWidget;

? ? tvWidget.onChartReady(() => {

? ? ? // tvWidget.chart().createStudy('MACD', false, false, [10,20])

? ? ? //設(shè)置各種均線

? ? ? tvWidget.chart().createStudy('Moving Average', false, false, [5],null,{"Plot.color":'#34a9ff'})

? ? ? tvWidget.chart().createStudy('Moving Average', false, false, [10],null,{"Plot.color":'#ffb620'})

? ? ? tvWidget.chart().createStudy('Moving Average', false, false, [30],null,{"Plot.color":'#8750ff'})

? ? ? tvWidget.chart().createStudy('Moving Average', false, false, [60],null,{"Plot.color":'#ff688f'})


? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '1min');


? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.remove('clickBtn');

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().setResolution('1', function onReadyCallback() {});

? ? ? ? });

? ? ? ? button.textContent = '1min';

? ? ? });

? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '5min');

? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.remove('clickBtn');

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().setResolution('5', function onReadyCallback() {});

? ? ? ? });

? ? ? ? button.textContent = '5min';

? ? ? });

? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '15min');

? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().setResolution('15', function onReadyCallback() {});

? ? ? ? });

? ? ? ? button.textContent = '15min';

? ? ? });

? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '30min');

? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().setResolution('30', function onReadyCallback() {});

? ? ? ? });

? ? ? ? button.textContent = '30min';

? ? ? });

? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '1hour');

? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().setResolution('60', function onReadyCallback() {});

? ? ? ? });

? ? ? ? button.textContent = '1hour';

? ? ? });

? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '1D');

? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().setResolution('1D', function onReadyCallback() {});

? ? ? ? });

? ? ? ? button.textContent = '1D';

? ? ? });

? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '1week');

? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().setResolution('7D', function onReadyCallback() {});

? ? ? ? });

? ? ? ? button.textContent = '1week';

? ? ? });

? ? ? tvWidget.headerReady().then(function() {

? ? ? ? var button = tvWidget.createButton();

? ? ? ? button.setAttribute('title', '指標(biāo)');

? ? ? ? button.addEventListener('click', function() {

? ? ? ? ? // button.classList.add('clickBtn');

? ? ? ? ? tvWidget.chart().executeActionById("insertIndicator")

? ? ? ? });

? ? ? ? button.textContent = '指標(biāo)';

? ? ? });


? ? });


? },

? destroyed() {

? ? if (this.tvWidget !== null) {

? ? ? this.tvWidget.remove();

? ? ? this.tvWidget = null;

? ? }

? },


}

</script>

<style lang="scss" scoped>

.TVChartContainer {

? height: calc(100vh - 80px);

}

</style>

3.后臺(tái)數(shù)據(jù)參照預(yù)覽地址的后臺(tái)

4.調(diào)整好合并到你自己的項(xiàng)目里去,這個(gè)就看大家自己的了

最后建議大家一定要多看文檔拆融。

歡迎大家點(diǎn)贊關(guān)注宰僧。謝謝啦!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末您市,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子役衡,更是在濱河造成了極大的恐慌茵休,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,183評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件手蝎,死亡現(xiàn)場離奇詭異榕莺,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)棵介,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門钉鸯,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人邮辽,你說我怎么就攤上這事唠雕。” “怎么了吨述?”我有些...
    開封第一講書人閱讀 168,766評(píng)論 0 361
  • 文/不壞的土叔 我叫張陵岩睁,是天一觀的道長。 經(jīng)常有香客問我揣云,道長捕儒,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,854評(píng)論 1 299
  • 正文 為了忘掉前任邓夕,我火速辦了婚禮刘莹,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘焚刚。我一直安慰自己点弯,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,871評(píng)論 6 398
  • 文/花漫 我一把揭開白布矿咕。 她就那樣靜靜地躺著蒲拉,像睡著了一般肃拜。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上雌团,一...
    開封第一講書人閱讀 52,457評(píng)論 1 311
  • 那天燃领,我揣著相機(jī)與錄音,去河邊找鬼锦援。 笑死猛蔽,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的灵寺。 我是一名探鬼主播曼库,決...
    沈念sama閱讀 40,999評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼略板!你這毒婦竟也來了毁枯?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,914評(píng)論 0 277
  • 序言:老撾萬榮一對(duì)情侶失蹤叮称,失蹤者是張志新(化名)和其女友劉穎种玛,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體瓤檐,經(jīng)...
    沈念sama閱讀 46,465評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡赂韵,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,543評(píng)論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了挠蛉。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片祭示。...
    茶點(diǎn)故事閱讀 40,675評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖谴古,靈堂內(nèi)的尸體忽然破棺而出质涛,到底是詐尸還是另有隱情,我是刑警寧澤掰担,帶...
    沈念sama閱讀 36,354評(píng)論 5 351
  • 正文 年R本政府宣布蹂窖,位于F島的核電站,受9級(jí)特大地震影響恩敌,放射性物質(zhì)發(fā)生泄漏瞬测。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,029評(píng)論 3 335
  • 文/蒙蒙 一纠炮、第九天 我趴在偏房一處隱蔽的房頂上張望月趟。 院中可真熱鬧,春花似錦恢口、人聲如沸孝宗。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽因妇。三九已至问潭,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間婚被,已是汗流浹背狡忙。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評(píng)論 1 274
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留址芯,地道東北人灾茁。 一個(gè)月前我還...
    沈念sama閱讀 49,091評(píng)論 3 378
  • 正文 我出身青樓,卻偏偏與公主長得像谷炸,于是被迫代替她去往敵國和親北专。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,685評(píng)論 2 360

推薦閱讀更多精彩內(nèi)容