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

Package detail

trading-vue-js

C4512.6kMIT1.0.2

Hackable charting lib for traders

trading, vue, charts, crypto, visualization, reactive, algo-trading, finviz, trading-systems

readme

trading-vue logo

TradingVue.js npm license build size Gitter DONATE

TradingVue.js is a hackable charting lib for traders. You can draw literally ANYTHING on top of candlestick charts.

Why

If you create trading software - this lib is probably for you. If you like to make custom indicators and think out of the box - this lib is most likely for you. And if you miss usability of TradingView.com in other open-source libraries and can't stand it - you are definetly in the right place!


White preview

Features

  • Scrolling & zooming as we all like
  • Simple API for making new overlays
  • Custom drawing tools
  • Non-time based charts (e.g. Renko)
  • One overlay === one .vue component
  • Fully reactive
  • Fully responsive
  • Customizable colors and fonts
  • Quite fast (works even with 3 mil candles)
  • Scripts (make your own indicators)

Demo & Docs

Demo | Getting Started | API Book | Built-in Overlays | Examples | 101 Project | llll Gitter | FAQ | FREE Overlay Pack | Free XP Pack | Playground

To run the examples, download the repo & npm run test

Install

NPM

npm i trading-vue-js

In browser

<script src="trading-vue.min.js"></script>

How to use

Minimal working example:

<template>
<trading-vue :data="this.$data"></trading-vue>
</template>
<script>

import TradingVue from 'trading-vue-js'

export default {
    name: 'app',
    components: { TradingVue },
    data() {
        return {
            ohlcv: [
                [ 1551128400000, 33,  37.1, 14,  14,  196 ],
                [ 1551132000000, 13.7, 30, 6.6,  30,  206 ],
                [ 1551135600000, 29.9, 33, 21.3, 21.8, 74 ],
                [ 1551139200000, 21.7, 25.9, 18, 24,  140 ],
                [ 1551142800000, 24.1, 24.1, 24, 24.1, 29 ],
            ]
        }
    }
}

</script>

Core philosophy

The core philosophy is Data -> Screen Mapping (DSM). The library provides you with functions that map your data (it could be anything) to screen coordinates. The lib does all the dirty work behind the scenes: scrolling, scaling, reactivity, etc.

 layout.t2screen(t) // time -> x
 layout.$2screen($) // price -> y
 layout.t_magnet(t) // time -> nearest candle x
 layout.screen2$(y) // y -> price
 layout.screen2t(x) // x -> time

Using these functions and the standard js canvas API, you can do magic.

Data structure

PRO TIP: chart is mandatory if you want to see something other than a white screen

IMPORTANT: All data must be sorted by time (in ascending order). The main OHLCV must not contain duplicate timestamps.

Full version of DataStructure

{
    "chart": {   // Mandatory
        "type": "<Chart Type, e.g. Candles>",
        "data": [
            [timestamp, open, high, low, close, volume],
            ...
        ],
        "settings": { } // Settings (depending on Chart Type)
    },
    "onchart": [ // Displayed ON the chart
        {
            "name": "<Indicator name>",
            "type": "<e.g. EMA, SMA>",
            "data": [
                [timestamp, ... ], // Arbitrary length
                ...
            ],
            "settings": { } // Arbitrary settings format
        },
        ...
    ],
    "offchart": [ // Displayed BELOW the chart
        {
            "name": "<Indicator name>",
            "type": "<e.g. RSI, Stoch>",
            "data": [
                [timestamp, ... ], // Arbitrary length
                ...
            ],
            "settings": { } // Arbitrary settings format
        },
        ...
    ]
}

The process of adding a new indicator is simple: first you define your own data format (should be timestamped though) and display settings. For example, EMA data might look like this:

 {
     "name": "EMA, 25",
     "type": "EMA",
     "data": [
         [ 1551128400000, 3091 ],
         [ 1551132000000, 3112 ],
         [ 1551135600000, 3105 ]
     ],
     "settings": {
         "color": "#42b28a"
     }
 },

Example of a simple overlay class

And then you make a new overlay class to display that data on the grid:

import { Overlay } from 'trading-vue-js'

export default {
    name: 'EMA',
    mixins: [Overlay],
    methods: {
        draw(ctx) {
            const layout = this.$props.layout
            ctx.strokeStyle = this.color
            ctx.beginPath()

            for (var p of this.$props.data) {

                // t2screen & $2screen - special functions that
                // map your data coordinates to grid coordinates
                let x = layout.t2screen(p[0])
                let y = layout.$2screen(p[1])

                ctx.lineTo(x, y)
            }

            ctx.stroke()
        },
        use_for() { return ['EMA'] },
        data_colors() { return [this.color] }
    },
    computed: {
        color() {
            return this.$props.settings.color
        }
    }
}

That's why the title doesn't lie: you can draw ANYTHING.

Grin

trading-vue logo

Code | click your 🐁

Roadmap

  • Docs
  • Tests
  • Solve known issues (marked as 'TODO: IMPORTANT') [PARTIALLY]
  • Performance improvements
  • Data-manipulation helpers
  • Add more built-in overlays
  • Add toolbar (drawing tools)
  • Custom loayout / layout persistence[POST-RELEASE]
  • Fix and improve mobile version
  • Version 1.0.0 here

Progress in details: https://github.com/tvjsx/trading-vue-js/projects/1

Changelog

See CHANGELOG.md

Development & Building

Install devDependencies

npm install

Run development enviroment (hot)

npm run dev

Server is running on http://localhost:8080

Run in a CDN-like mode

npm run cdn

Server is running on http://localhost:8080

Build the bundle

npm run build

Visual testing

npm run test

Server is running on http://localhost:8080

Automatic testing

npm run auto-test

Contributing

  1. Fork ( https://github.com/tvjsx/trading-vue-js/fork )
  2. Create your feature branch (git checkout -b cool-new-feature)
  3. Commit your changes (git commit -am 'Let's rock smth')
  4. Push to the branch (git push origin cool-new-feature)
  5. Create a new Pull Request

Please read the guidelines in CONTRIBUTING.md

changelog

Changelog

All notable changes to this project will be documented in this file.

[0.10.0] - 2020-12-07

  • The first package of mobile improvements
  • Enhances skins
  • Small modifications of scripts execution
  • Improvements of Interfaces (aka inline overlay UI)
  • Script fixes (update onchart/offchart OVs)
  • New aggtype: copy (fast aggregation through copying)
  • CSS tranforms support (transition)
  • Overlay name templates, e.g. "RSI, $length"
  • Fixed loading animation for some cases

[0.9.0] - 2020-11-17

  • Scripts: advanced samplers (sym() function)
  • Implemented Dataset ops (update, merge, remove)
  • Countless small bug fixes as always
  • Scripts: add onclose()
  • Fixed auto-scroll (when new candle is added)
  • Scripts: offchart/onchart updates
  • DC: aggtool v2 (completely rewritten)
  • Custom legend buttons (your custom icon)
  • Tool groups
  • Scroll wheel modes: prevent, pass, click
  • WebWorker RAM limit
  • LineTool: add Ray mode
  • Legend buttons handlers [EXT]

[0.8.0] - 2020-10-15

  • Timezones (initial support)
  • Extended shader props
  • Show/hide scalebars (via chart-config sizes)
  • Chart section resizing [Ext]
  • Linked charts [Ext]
  • Shift + drag => Measure
  • Various bug kills and memory leak demolitions
  • Scripts: onrange exec, node.js SE exec (opt)
  • Scripts: added support of 'tf', 'range'
  • Updated RangeTool
  • Datasets, very first try
  • 30% build size decrease

[0.7.0] - 2020-9-15

  • Extensions (widgets, colorpacks & skins v1)
  • Pins & toolbar bug fixes
  • WebWorker modules (emitted from extension)
  • Std lib injections (though WW modules)
  • Improved fn argument parsing for scripts
  • Splines overlay: skipNaN mode
  • Scripts: multi-tf TA, how cool is that?
  • Scripts: hl2, hlc3, ohlc4 and potentially more in the futr
  • Script: SE hooks for backtester mod (if you like)
  • Hooks on the internal events (now only for Chart.vue)
  • Fixed legend values (when grid.id is custom)
  • DC: some improvements & new settings
  • lz-string compression for the WW code. Supr fast

[0.6.0] - 2020-8-15

  • Scripts (early state)
  • DC faster update()
  • DC tick aggregation
  • Improved offchart overlayz performance
  • Multiple bug fixes
  • +30 Std overlayz (MACD, DMI, Stoch ...)
  • Overlay loading state (animation)
  • TradingLite-like zoom mode
  • Better IB mode + Illuminati test

[0.5.0] - 2020-5-5

Changes

  • Index-based rendering mode (hides weekend gaps + sup Renko)
  • Log-scale mode
  • Interfaces (preview)
  • Performance fixes
  • Zoom to the current candle mode
  • Pixel-perfect candles, candle wicks
  • Offchart drawing tools
  • Price level
  • Custom grid heights
  • Sidear & Botbar inline shaders
  • Added RangeTool
  • Forced chart timeframe (overwrites the auto-detected one)
  • Updated DataCube

[0.4.0] - 2019-11-2

Changes

  • Multiple bug fixes and improvements
  • Legend buttons
  • New/updated overlays (Segment, Splitters, Candles)
  • Data Structure v1.1
  • Mac support (Trackpad + Retina)
  • New API functions: setRange(), goto(), getCursor() etc.
  • Better timeline
  • New interval detection algo
  • DataCube
  • Tool overlay extension
  • Drawing tools (Line, Extended Line)

[0.3.0] - 2019-5-17

Changes

  • Multiple bug fixes (legend, slicelib, cursor)
  • New overlays: Trades, Channel, Splines
  • Added visual testing suite
  • Mouse events for overlays
  • Several fixes that made charts sharper and slicker
  • Hackable chart config. Heck, how can the most hackable lib be without it?

[0.2.0] - 2019-3-27

Changes

  • Added y-range transform for overlays
  • Performance boost with fancy slice lib
  • Implemented z-index ordering
  • Vertical scaling implementation v1
  • Added data masking feature, now you can include strings
  • Several smaller fixes