{"size": 1083, "ext": "js", "max_stars_repo_path": "src/lib/stock.js", "max_stars_repo_name": "timmson/mbt-feed-svc", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/lib/stock.js", "max_issues_repo_name": "timmson/mbt-feed-svc", "max_issues_repo_issues_event_min_datetime": "2017-04-28T11:09:52.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-25T12:25:32.000Z", "max_forks_repo_path": "src/lib/stock.js", "max_forks_repo_name": "timmson/mbt-feed-svc", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 61, "max_forks_count": null, "avg_line_length": 22.5625, "max_line_length": 75, "alphanum_fraction": 0.6158818098}
class Stock {

	constructor(moexApi, yahooApi) {
		this.moexApi = moexApi;
		this.yahooApi = yahooApi;
	}

	getMessage() {
		return new Promise(((resolve, reject) => {
			Promise.all([
				this.getTickerPriceFromMoex("USD000UTSTOM"),
				this.getTickerPriceFromYahoo("^GSPC"),
				this.getTickerPriceFromMoex("VTBE", "USD")
			]).then((result) => {
				resolve([
					"💰" + result[0].toFixed(2),
					"🇺🇸" + (result[1]).toFixed(2),
					"🇨🇳" + (result[2]).toFixed(4)
				].join(", ")
				);
			}).catch((err) => reject(err));
		}));
	}

	getTickerPriceFromMoex(ticker, currency) {
		return new Promise(async (resolve, reject) => {
			try {
				let security = await this.moexApi.securityMarketData(ticker, currency);
				resolve(parseFloat(security.node.last));
			} catch (e) {
				reject(e);
			}
		});
	}

	getTickerPriceFromYahoo(ticker) {
		return new Promise(async (resolve, reject) => {
			try {
				let securityPrice = await this.yahooApi.getCurrentPrice(ticker);
				resolve(parseFloat(securityPrice));
			} catch (e) {
				reject(e);
			}
		});
	}
}

module.exports = Stock;