binance-historical
Version:
Download historical klines from binance api
89 lines (88 loc) • 3.08 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.runCommand = runCommand;
const prompts_1 = __importDefault(require("prompts"));
const klines_1 = require("./klines");
const utils_1 = require("./utils");
const commander_1 = require("commander");
const questions = [
{
type: 'text',
name: 'pair',
message: 'Pair that you want to track:',
initial: 'ETHUSDT',
},
{
type: 'select',
name: 'interval',
message: 'The interval:',
choices: [
{ title: '1 minute', value: '1m' },
{ title: '3 minutes', value: '3m' },
{ title: '5 minutes', value: '5m' },
{ title: '15 minutes', value: '15m' },
{ title: '30 minutes', value: '30m' },
{ title: '1 hour', value: '1h' },
{ title: '2 hours', value: '2h' },
{ title: '4 hours', value: '4h' },
{ title: '6 hours', value: '6h' },
{ title: '8 hours', value: '8h' },
{ title: '12 hours', value: '12h' },
{ title: '1 day', value: '1d' },
{ title: '3 days', value: '3d' },
{ title: '1 week', value: '1w' },
],
initial: 7,
},
{
type: 'date',
name: 'startDate',
message: 'The starting date of the interval:',
initial: new Date(),
},
{
type: 'date',
name: 'endDate',
message: 'The ending date of the interval:',
initial: new Date(),
},
{
type: 'text',
name: 'fileName',
message: 'The path of the file that will be saved:',
initial: `${process.cwd()}/`,
},
];
async function promptUser() {
const { pair, interval, startDate, endDate, fileName } = await (0, prompts_1.default)(questions);
return { pair, interval, startDate, endDate, fileName };
}
async function processUserInformations() {
const { pair, interval, startDate, endDate, fileName } = await promptUser();
if (!pair || !interval || !startDate || !endDate || !fileName) {
console.log('Missing informations 😭');
return;
}
const kLines = await (0, klines_1.getKline)(pair, interval, startDate, endDate).catch((error) => {
console.error(error);
});
if (kLines) {
(0, utils_1.saveKline)(fileName +
`${pair}_${interval}_${(0, utils_1.formatDate)(startDate)}_${(0, utils_1.formatDate)(endDate)}.json`, kLines);
console.log('Done 🎉');
}
}
async function runCommand() {
const program = new commander_1.Command();
program
.name('binance-historical')
.description('Utility to download historical klines from binance');
program
.command('download')
.description('Download a JSON file which contains historical klines from binance api')
.action(() => processUserInformations());
program.parse();
}