-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8f445f
commit cbdb7a1
Showing
3 changed files
with
66 additions
and
30 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
|