Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

nuxt-tradingview

volkanakkus933MIT1.3.3TypeScript support: included

TradingView Widgets for Nuxt 3

nuxt, nuxt3, nuxt-3, tradingview, widgets, chart, stocks, market, crypto, forex, trading, finance, module, vue, vue3, nuxt-module, nuxt-component, typescript, front-end

readme

nuxt-tradingview-social-card

Nuxt TradingView

npm version npm downloads License Nuxt

Use the TradingView Widgets in your Nuxt Application

Features

  • 🧺 Multiple Widgets in Single Page
  • 🍧 No Registration or API for TradingView
  • 🌴 Optional Widget Inclusion (For Reducing Bundle Size)
  • 🍽️ Customizable Component Names with Prefix Option

✨  Release Notes

Documentation

We've prepared detailed documentation and playground which you can find here, but you can also refer to the examples below.

Additionally, you can check the Tradingview Docs for more information and configuration about the widgets.

Quick Setup

  1. Add nuxt-tradingview dependency to your project
# Using yarn
yarn add nuxt-tradingview

# Using npm
npm install nuxt-tradingview

# Using pnpm
pnpm add nuxt-tradingview
  1. Add nuxt-tradingview to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-tradingview'
  ]
})

That's it! You can now use TradingView Widgets in your Nuxt app ✨

Widgets Built-in

When you add this module, the following widget components are automatically imported into the project:

  • Chart
  • CompanyProfile
  • CryptoHeatMap
  • CryptoMarket
  • EconomicCalendar
  • ForexCrossRates
  • ForexHeatMap
  • FundamentalData
  • MarketData
  • MarketOverview
  • MiniChart
  • Screener
  • SingleTicker
  • StockMarket
  • StockHeatMap
  • SymbolInfo
  • SymbolOverview
  • TechnicalAnalysis
  • Ticker
  • TickerTape
  • TopStories

Examples

The built-in widgets have default options based on Tradingview. If you did not define any options, the default options will be applied. Check available options on the Tradingview Docs

Basic Usage

Example of using all widgets with default options:

<template>
  <Chart />
  <CryptoMarket />
  <TopStories/>
  <Screener/>
</template>

Configuring the widgets with options according to Tradingview Docs:

<template>
  <Chart
    :options="{
      theme: 'dark',
      autosize: true,
      symbol: 'NASDAQ:AAPL',
      timezone: 'Etc/UTC',
    }"
  />
</template>

Or, you can pass a ref variable into it:

<template>
  <Chart :options="chartOptions" />
</template>

<script setup lang="ts">
const chartOptions = ref({
  theme: 'dark',
  autosize: true,
  symbol: 'NASDAQ:AAPL',
  timezone: 'Etc/UTC',
})
</script>

Multiple Widgets

If you want to use the same widgets multiple times on a single page, you should define a unique class for each widget.

<template>
  <Chart class="apple-chart"/>
  <Chart class="nvidia-chart"/>
</template>

For example, in a for loop, you can use the key as a unique class:

<template>
  <div v-for="symbol in symbols" :key="symbol">
    <SingleTicker :class="`ticker-${symbol}`" :options="{ symbol }" />
  </div>
</template>

<script setup lang="ts">
const symbols = ref(['FX:EURUSD', 'FX:GBPUSD', 'FX:USDJPY']);
</script>

Dynamic Color Mode

For dynamic color mode support, you can integrate your color mode plugin or @nuxtjs/color-mode module to the widget options with the theme or colorTheme property.

And for re-render the widget with every color change, you should also bind the color mode to the :key attribute in the template.

Example below is using the @nuxtjs/color-mode module:

<template>
  <div>
    <Chart :key="$colorMode.value" :options="options" />
  </div>
</template>

<script lang="ts" setup>
const { $colorMode } = useNuxtApp();

const options = computed(() => ({
  theme: $colorMode.value, // it must be 'light' or 'dark'
  width: '100%',
  height: '400',
  symbol: 'NASDAQ:AAPL',
  ...
}));
</script>

Module Options

The module by default will inject all widgets, but you can configure it to inject only the widgets you need. Additionally, you can add a prefix to widget component names to avoid conflicts with other local components.

prefix

To change default widget component names, you can add a prefix into the tradingview section to use every widget with that prefix.

export default defineNuxtConfig({
  tradingview: {
    prefix: 'TV' 
  }
})

Then you can use the components as follows:

<template>
  <TVChart />
  <TVCryptoMarket />
  <TVTopStories/>
  <TVScreener/>
</template>

If prefix is not defined, you can use the components as shown in the documentation.

importOnly

To reduce the bundle size, you can import only the widgets you need. Add an importOnly parameter to the tradingview section to inject only the widgets you need.

export default defineNuxtConfig({
  tradingview: {
    importOnly: ['Chart', 'CryptoMarket', 'TopStories', 'Screener'] 
  }
})

[!NOTE] Make sure to use the exact names of the widgets. Even if you define a prefix, you must use the default name of the widgets. You can find all widget names here.

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Develop the docs
npm run dev:docs

This software is licensed under the MIT License | @volkanakkus | Special thanks to @ehsan-shv 💚

changelog

Changelog

v1.3.3

🩹 Fixes

  • Augment @nuxt/schema rather than nuxt/schema (af34b6e)

compare changes

❤️ Contributors

v1.3.2

🏡 Chore

  • Indicate compatibility with new v4 major (47f70f6)

compare changes

❤️ Contributors

v1.3.1

🚀 Enhancements

  • Set width and height to 100% in options if autosize option is true (c3c5de9)

🩹 Fixes

  • Remove default options if there are any prop options (6cca163)

🏡 Chore

  • Add npm keywords & update playground script to codesandbox (d86d198)

📖 Documentation

  • Update module version to latest (e2886be)
  • Update docs for better clarification (8d3b437)

compare changes

❤️ Contributors

✨ Thanks To:

v1.3.0

🚀 Enhancements

  • Correct the Snaps Widget name to TopStories (802cbf7)
  • Add StockHeatMap Widget (8587834)

🏡 Chore

  • Correct the default options of the widgets according the docs (56d698c)
  • Update lint options (55463ff)

📖 Documentation

  • Playground chaged to codesandbox (ad62b0b)
  • Add the Dynamic Color Mode to docs and README.md (4648b05)
  • Update README.md according to Docs (2fe3c95)
  • Add widget detail pages (7b271cb)
  • Re-arrange the orders of the widgets in 1.overview.md (82f0bf0)
  • Update illustration for color-mode (0957686)
  • Update configuration.md (e6df319)
  • Update color mode options (3606916)
  • Update the Illustration (6a43fda)

compare changes

❤️ Contributors

v1.2.0

🚀 Enhancements

  • Experimental options introduced with anonymousCrossOrigin option to set all crossorigin anonymous (6950d28)

🩹 Fixes

  • Type fixes for PublicRuntimeConfig (b389b78)

💅 Refactors

  • No need for defu while setting runtimeConfig (32888d0)

📖 Documentation

  • Update releases page (0ca10ef)
  • Add importOnly config option to README.md (b393621)
  • Update and enable playground (0ec1ef3)

compare changes

❤️ Contributors

v1.1.0

🚀 Enhancements

  • Add importOnly property to config (362389d)

📖 Documentation

  • Cover Image Added (930d9f3)
  • Initialize docs folder (0df44c9)
  • Playground Added (4e6c96e)
  • Online Docs Initialized with Docus (2538df9)
  • Fix pinceau and string-width package problems (69ef57b)
  • Add the documentation link (0ce9888)
  • Update illustration, playground sections, and add badges for updates (66e86a0)
  • Releases added (7a4073c)
  • Remove unnecessary dependencies (a8f15b3)
  • Update nuxt version to latest (9b78158)

compare changes

❤️ Contributors

v1.0.5

🚀 Enhancements

❤️ Contributors

v0.0.5

📖 Documentation

❤️ Contributors

v0.0.4

🚀 Enhancements

  • All Widgets Added and Prefix Option Defined (b2f4d0b)

❤️ Contributors

v0.0.3

compare changes

v0.0.2