<commit_before>const request = require('request')

function getPrice ({timeframe = 1, resolution = '30-min'} = {})
{
	// Get from bitcoin chart
	return new Promise((resolve, reject) => {
		getOHLC(arguments[0])
			.then((OLHCArray)=>{
				return resolve(OLHCArray[OLHCArray.length - 1])
			})
			.catch((error) => {
				console.log("Error:", error)
				return reject(error);
			});
	});
}
	
function getOHLC({timeframe = 1, resolution = '30-min', transpose = false} = {})
{
	return new Promise((resolve, reject) => {
		_getRawBitcoinOHLC(arguments[0])
		.then((arr) => {
			if (!transpose) {
				let OLHCArray = _addToOLHCArray();
				return resolve(
					arr.map((olhc)=> {
					let [t,o,l,h,c,v,w,x] = olhc
					return {
						timestamp: t,
						open: o,
						low: l,
						high: h,
						close: c,
						volume_btc: v,
						volume_cur: w,
						weighted_price: x}
					})
				);
			} else {
				let OLHCArray = _addToOLHCArray();
				arr.map((e) => {
					_addToOLHCArray(e, OLHCArray);
				});
				return resolve(OLHCArray);
			}
		})
		.catch((error) =>
		{
			console.log("Error: getOHLC, _getRawBitcoinOHLC");
			console.log(error);
			return reject(error);
		})
		;
	});
}
	
function getLast(OLHCArray, ticker)
{
	return OLHCArray[OLHCArray.length - 1];
}
	
	
function _getRawBitcoinOHLC({
		timeframe = 1,
		customTime,
		resolution = '30-min'		
	} = {})
{
	return new Promise ((resolve, reject) => {
		let query = {
			m: 'btcoidIDR',
			i: resolution,
			SubmitButton: 'Draw',
			r: timeframe
		}
		if (customTime) {
			{delete query.r}
			[query.c, query.s, query.e] = [1, customTime.startDate, customTime.endDate]
		}
		
		let r = request({
			// Resolution is Daily, Weekly, 30-min, etc
			url: 'https://bitcoincharts.com/charts/chart.json',
			qs: query,
			json: true
		},
		(error, response, body) => {
			if (error || !body) {
				console.log("_getRawBitcoinOLHC");
				return reject(error);
			}
			// Format: Timestamp, Open, High, Low, Close, Volume(BTC), Volume (Currency), Weighted Price
			return resolve(body);
		})
		
	});
}
	
function _addToOLHCArray(element, obj)
{
	if (obj==null)
	{
		obj = {};
		obj.timestamp = [];
		obj.open = [];
		obj.low = [];
		obj.high = [];
		obj.close = [];
		obj.volume = [];
		return obj;
	}
	// open: [...], low: [...], high: [...], close: [...], volume: [...] };
	obj.timestamp.push(element[0]);
	obj.open.push(element[1]);
	obj.low.push(element[2]);
	obj.high.push(element[3]);
	obj.close.push(element[4]);
	obj.volume.push(element[5]);
}
		
module.exports = {
	OHLC: getOHLC,
	lastPrice: getPrice
}<commit_msg>Module exports only if available<commit_after>const request = require('request')

function getPrice ({timeframe = 1, resolution = '30-min'} = {})
{
	// Get from bitcoin chart
	return new Promise((resolve, reject) => {
		getOHLC(arguments[0])
			.then((OLHCArray)=>{
				return resolve(OLHCArray[OLHCArray.length - 1])
			})
			.catch((error) => {
				console.log("Error:", error)
				return reject(error);
			});
	});
}
	
function getOHLC({timeframe = 1, resolution = '30-min', transpose = false} = {})
{
	return new Promise((resolve, reject) => {
		_getRawBitcoinOHLC(arguments[0])
		.then((arr) => {
			if (!transpose) {
				let OLHCArray = _addToOLHCArray();
				return resolve(
					arr.map((olhc)=> {
					let [t,o,l,h,c,v,w,x] = olhc
					return {
						timestamp: t,
						open: o,
						low: l,
						high: h,
						close: c,
						volume_btc: v,
						volume_cur: w,
						weighted_price: x}
					})
				);
			} else {
				let OLHCArray = _addToOLHCArray();
				arr.map((e) => {
					_addToOLHCArray(e, OLHCArray);
				});
				return resolve(OLHCArray);
			}
		})
		.catch((error) =>
		{
			console.log("Error: getOHLC, _getRawBitcoinOHLC");
			console.log(error);
			return reject(error);
		})
		;
	});
}
	
function getLast(OLHCArray, ticker)
{
	return OLHCArray[OLHCArray.length - 1];
}
	
	
function _getRawBitcoinOHLC({
		timeframe = 1,
		customTime,
		resolution = '30-min'		
	} = {})
{
	return new Promise ((resolve, reject) => {
		let query = {
			m: 'btcoidIDR',
			i: resolution,
			SubmitButton: 'Draw',
			r: timeframe
		}
		if (customTime) {
			{delete query.r}
			[query.c, query.s, query.e] = [1, customTime.startDate, customTime.endDate]
		}
		
		let r = request({
			// Resolution is Daily, Weekly, 30-min, etc
			url: 'https://bitcoincharts.com/charts/chart.json',
			qs: query,
			json: true
		},
		(error, response, body) => {
			if (error || !body) {
				console.log("_getRawBitcoinOLHC");
				return reject(error);
			}
			// Format: Timestamp, Open, High, Low, Close, Volume(BTC), Volume (Currency), Weighted Price
			return resolve(body);
		})
		
	});
}
	
function _addToOLHCArray(element, obj)
{
	if (obj==null)
	{
		obj = {};
		obj.timestamp = [];
		obj.open = [];
		obj.low = [];
		obj.high = [];
		obj.close = [];
		obj.volume = [];
		return obj;
	}
	// open: [...], low: [...], high: [...], close: [...], volume: [...] };
	obj.timestamp.push(element[0]);
	obj.open.push(element[1]);
	obj.low.push(element[2]);
	obj.high.push(element[3]);
	obj.close.push(element[4]);
	obj.volume.push(element[5]);
}

// Not always are we running for Node.js
if (module) {
	module.exports = {
		OHLC: getOHLC,
		lastPrice: getPrice
	}
}
{'fraction_non_alphanumeric': 0.1852772466539197, 'fraction_numerical': 0.008413001912045888, 'mean_word_length': 2.933082706766917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '458132', 'n_tokens_mistral': 2374, 'n_tokens_neox': 1960, 'n_words': 391}