Likhtar - Custom Adapter

Use custom adapter to retirieve OHLC data

Demo

Code


      let Vue = Likhtar.vue;
      Vue.config.productionTip = false;
      Vue.component(Likhtar.app.name, Likhtar.app);

      let idSerializer = function (...args) { return args.join("-"); };

      let adapter = function() {
        return {
          getData: function (venue,symbol,_from,_to,granularity) {
            let interval = null;
            switch (granularity) {
              case "1m": interval = Likhtar.d3.timeMinute; break;
              case "5m": interval = Likhtar.d3.timeMinute.every(5); break;
              case "15m": interval = Likhtar.d3.timeMinute.every(15); break;
              case "1h": interval = Likhtar.d3.timeHour; break;
              case "1d": interval = Likhtar.d3.timeDay; break;
              default: interval = Likhtar.d3.timeMinute; break;
            }
            let generator = Likhtar.fc
            .randomFinancial()
            .startPrice(8000)
            .interval(interval);
            return { data: generator(40), id: idSerializer(venue, symbol) }
          }
        }
      }

      let chartApp = new Vue({
        el: '#app',
        data: {
          symbols: "MyExchange:BTCUSD,MyExchange:ETHUSD",
          granularity: "1m",
          adapter: adapter(),
          series: [{
            id: idSerializer("MyExchange", "BTCUSD"),
            type: "line"
          }]
        }
      });