This commit is contained in:
dig 2021-08-30 19:28:39 +02:00
parent a7d41ca69b
commit aaea775364
1 changed files with 51 additions and 14 deletions

View File

@ -9,7 +9,9 @@ import fs from 'fs-extra'
import config from './config.js'
const timeFrames = { '': 1, 'H': 1, 'D': 1, 'W': 7, 'M': 30 }
const timeFrames = '1 5 15 30 1H 2H 4H 1D 2D 1W 1M'.split(' ')
const timeFramesMin = '1 1H 1D'.split(' ')
const timeFrameAggregates = { '': 1, 'H': 1, 'D': 1, 'W': 7, 'M': 30 }
const timeFrameMinutes = { '': 1, 'H': 60, 'D': 60*24, 'W': 60*24*7, 'M': 60*24*30 }
const json2csv = list=> list.map( p=> [p.time, p.close, p.high, p.low, p.open, p.volumefrom, p.volumeto].join() ).join('\n')
@ -20,16 +22,30 @@ const csv2json = csv=> csv.split('\n')
})
const log = (...args)=> obj=> ( console.log( ...args, obj ), obj )
const ccfs2colors = ccfs=> {
let [ exchange, fsym, tsym, period, start, end = '' ] = ccfs.split('/')
, str = exchange.grey + '/'
str += fsym.cyan + '/'
str += tsym.blue + '/'
str += period ? period.magenta + '/' : ''
str += start ? start.yellow + '/' : ''
str += end ? end.yellow + '/' : ''
return str
}
function ccfs2file( ccfs )
{
let start, end
// return loadByPath( ccfs )
return fs.readFile( `${config.dataDir}/${ccfs}-1279324800-1555545600.csv`, 'utf8' ).then( csv2json )
.then( data=> (start = data[0].time, end = data[data.length-1].time, data) )
let start, end, ccPath = ccfs.split('/')
return loadByPath( ccfs )
// return fs.readFile( `${config.dataDir}/${ccfs}-1279324800-1555545600.csv`, 'utf8' ).then( csv2json )
.then( data=> (ccPath[4] = data[0].time, ccPath[5] = data[data.length-1].time, data) )
.then( json2csv )
.then( csv=> {
let file = `${config.dataDir}/${ccfs}-${start}-${end}.csv`
// fs.outputFile( file, csv )
ccPath[4] = `${ccPath[4]}-${ccPath[5]}`
ccPath = ccPath.slice(0,5)
let file = `${config.dataDir}/${ccPath.join('/')}.csv`
fs.outputFile( file, csv )
return file
})
}
@ -51,7 +67,7 @@ export default function main( ccfs )
var job = cron.scheduleJob('*/1 * * * *', ()=> console.log('The answer to life, the universe, and everything! at', new Date) )
}
// esm cryptoSaver:backfill CCCAGG/BTC/USD[[[/1D]/24567788976543]/4578998765]
export function backfill({ 0:ccfs })
{
let ccPath = ccfs.split('/')
@ -59,22 +75,37 @@ export function backfill({ 0:ccfs })
if( ccPath.length == 3 ) // all timeFrames
{
console.log( `Backfilling of all time frames of ${fsym.cyan}/${tsym.blue} on ${exchange.grey} exchange...` )
'1 5 15 30 1H 2H 4H 1D 2D 1W 1M'.split(' ')
console.log( `${ccfs2colors(ccfs)} >Backfilling of all time frames of ${fsym.cyan}/${tsym.blue} on ${exchange.grey} exchange...` )
timeFrames
.map( tf=> ccfs+'/'+tf )
.map( ccfs=> backfill([ccfs]) )
}
if( ccPath.length == 4 ) // one timeFrame, recursive until error
{
console.log( `Backfilling the ${period.magenta} time frame of ${fsym.cyan}/${tsym.blue} on ${exchange.grey} exchange...` )
console.log( `${ccfs2colors(ccfs)} >Backfilling the ${period.magenta} time frame of ${fsym.cyan}/${tsym.blue} on ${exchange.grey} exchange...` )
ccfs2file( ccfs )
.then( log('File saved:') )
.then( file=> log(ccfs+'/'+file.split('-')[1])()|| backfill([ ccfs+'/'+file.split('-')[1] ]) )
.then( file=> log(ccfs+'/'+file.match(/\/*?(\d*)-/)[1])()|| backfill([ ccfs+'/'+file.match(/\/*?(\d*)-/)[1] ]) )
}
if( ccPath.length > 4 ) // from date to date
if( ccPath.length == 5 ) // from date to maximum history
{
console.log( `Backfilling from ${start.yellow} to ${end.yellow} of the ${period.magenta} time frame of ${fsym.cyan}/${tsym.blue} on ${exchange.grey} exchange...` )
console.log( `${ccfs2colors(ccfs)} >Backfilling from ${start.yellow} to max history available of the ${period.magenta} time frame of ${fsym.cyan}/${tsym.blue} on ${exchange.grey} exchange...` )
ccfs2file( ccfs )
.then( log('File saved:') )
.then( file=> {
ccPath[4] = file.match(/\/*?(\d*)-/)[1]
let next = ccPath.join('/')
log('Next ccfs:')(next)
return backfill( [next] )
})
}
if( ccPath.length == 6 ) // from date to date
{
console.log( `${ccfs2colors(ccfs)} >Backfilling from ${start.yellow} to ${end.yellow} of the ${period.magenta} time frame of ${fsym.cyan}/${tsym.blue} on ${exchange.grey} exchange...` )
ccfs2file( ccfs )
.then( log('File saved:') )
}
}
@ -82,3 +113,9 @@ export function validate({ 0:ccfs, aze })
{
console.log( ccfs, aze )
}
export function compile({ 0:ccfs })
{
console.log( `Compile `, ccfs )
}