Skip to content

Commit

Permalink
start using npx standard style
Browse files Browse the repository at this point in the history
  • Loading branch information
loaiabdalslam committed Jul 17, 2019
1 parent d8f445f commit cbdb7a1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 30 deletions.
File renamed without changes.
44 changes: 44 additions & 0 deletions helper/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const SECS_IN_DAY = 86400

function convertPriceArrayToMap (priceArray) {
const map = new Map()
for (let price of priceArray) {
const time = secsToDate(price.time)
map.set(startOfDay(time).valueOf(), Object.assign({}, price, { time }))
}
return map
}

// simple linear interpolation
function getPriceFromOHLC (priceData, time) {
const { open, /* high, low, */ close } = priceData

const startTime = startOfDay(time)
const diffSecs = (time - startTime) / 1000

const diffPrice = close - open
const price = (diffPrice * diffSecs / SECS_IN_DAY) + open

return price
}

function cloneDate (date) {
return new Date(date.getTime())
}

function secsToDate (secs) {
return new Date(secs * 1000)
}

// return UTC start of day
function startOfDay (date) {
let cd = cloneDate(date)
cd.setUTCHours(0, 0, 0, 0)
return cd
}

module.exports = {
convertPriceArrayToMap,
getPriceFromOHLC,
startOfDay
}
52 changes: 22 additions & 30 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
const { sympolPrice } = require('./price');
const {
get
} = require('./fetch');
const link = 'https://min-api.cryptocompare.com/data/';
const { sympolPrice } = require("./price")
const { get } = require("./helper/fetch")
const link = "https://min-api.cryptocompare.com/data/";

module.exports = {

MKT: function(api) {
// This Function for initialize the api
this.apikey = () => {
return `apikey=${api}`
}

// this Function for initialize the query
this.price = (dict) => {
return sympolPrice(dict)

}

// this Function fireup exchange query for make request using your api and your query and return promise reponse
// you can access reponse data with then((response)=>Json.stringify(response.data))

this.exchange = (dict) => {
let request = link + this.price(dict) + this.apikey()
return get(request);
}


}

MKT: function (api) {
// This Function for initialize the api
this.apikey = () => {
return `apikey=${api}`
}

// this Function for initialize the query
this.price = dict => {
return sympolPrice(dict)
}

// this Function fireup exchange query for make request using your api and your query and return promise reponse
// you can access reponse data with then((response)=>Json.stringify(response.data))

this.exchange = dict => {
const request = link + sympolPrice(dict) + this.apikey()
return get(request)
}
}
}

0 comments on commit cbdb7a1

Please sign in to comment.