Skip to content

Instantly share code, notes, and snippets.

@lengshuiyulangcn
Created May 8, 2017 04:56
Show Gist options
  • Save lengshuiyulangcn/f1b3969e08926cc3a581c090da0a134e to your computer and use it in GitHub Desktop.
Save lengshuiyulangcn/f1b3969e08926cc3a581c090da0a134e to your computer and use it in GitHub Desktop.
an cmd graph of the currency rate
var blessed = require('blessed')
, contrib = require('../index')
const axios = require("axios");
var minY = 11276;
var maxY= 11278;
var screen = blessed.screen()
, transactionsLine = contrib.line(
{ width: 120
, height: 40
, left: 15
, top: 12
, xPadding: 5
, minY: minY
, maxY: maxY
, label: 'USD/JPY'
})
var transactionsData = {
title: 'USD/JPY',
style: {line: 'red'},
x: ['00:00', '00:05', '00:10', '00:15', '00:20', '00:30', '00:40', '00:50', '01:00', '01:10', '01:20', '01:30', '01:40', '01:50', '02:00', '02:10', '02:20', '02:30', '02:40', '02:50', '03:00', '03:10', '03:20', '03:30', '03:40', '03:50', '04:00', '04:10', '04:20', '04:30'],
y: [11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,11270,111270,11270,11270,11270,11270,1270]
}
screen.append(transactionsLine);
transactionsLine.setData(transactionsData);
setInterval(function() {
transactionsData.y.shift();
axios.get('https://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote/?format=json')
.then(function (response) {
let usd_jpy = response.data.list.resources.filter((pair)=>{
return pair.resource.fields.name == "USD/JPY";
})[0];
let current_price = parseFloat(usd_jpy.resource.fields.price)*100;
if( current_price > maxY || current_price < minY ){
maxY = current_price + 3;
minY = current_price - 3;
screen.remove(transactionsLine);
transactionsLine = contrib.line(
{ width: 120
, height: 40
, left: 15
, top: 12
, xPadding: 5
, minY: minY
, maxY: maxY
, label: 'USD/JPY'
});
screen.append(transactionsLine);
}
transactionsData.y.push(parseFloat(usd_jpy.resource.fields.price)*100);
transactionsLine.setData(transactionsData);
screen.render()
})
.catch(function (error) {
console.log(error);
});
}, 2000);
screen.key(['escape', 'q', 'C-c'], function(ch, key) {
return process.exit(0);
});
@lengshuiyulangcn
Copy link
Author

need to checkout this PR.
yaronn/blessed-contrib#98

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment