Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ async function jumpStart(){
dataSourceName: 'binance',
data: [],
enabled: true,
binance:10,
updateSnapshotTime:10,
lastUpdated: 0,
})
DataSourceDataSchema.create({
dataSourceName: 'coinMarketCap',
data: [],
enabled: true,
coinMarketCap: 10,
updateSnapshotTime: 10,
lastUpdated: 0,
})
DataSourceDataSchema.create({
dataSourceName: 'xt',
data: [],
enabled: true,
updateSnapshotTime: 120,
lastUpdated: 0,
})
}
Expand Down
37 changes: 37 additions & 0 deletions src/remoteData.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ async function getMarketData(marketData, dataSource, baseCurrency){
}
}
}
if (dataSource == 'xt'){
let xtDataStored = await DataSourceDataSchema.findOne({ dataSourceName: 'xt' }).exec();
if(xtDataStored.enabled){
let xtData = await getDataXt(marketData, baseCurrency)
if(xtData){}else{console.log("Error retrieving xt.com data")}
}
}
}

/**
Expand Down Expand Up @@ -341,6 +348,35 @@ async function getDataCoinGeckoDirect(marketData, baseCurrency){
}
}

async function getDataXt(marketData, baseCurrency){
// Format input data and output in a known format for the rest of the program
// Check what the base currency is
// https://sapi.xt.com/v4/public/ticker?symbol=pivx_usdt
//
let url = 'https://sapi.xt.com/v4/public/ticker/price?symbols='+ticker+'_usdt'
let data = await getData(url)
if(data.result){
let XtReturnData ={}
XtReturnData['xt'] = {}
XtReturnData.xt['usdt'] = parseFloat(data.result[0].p)
XtReturnData.xt['usd'] = parseFloat(data.result[0].p)
let dataFromDisk = await getMarketDataSource(marketData,"xt")
if(dataFromDisk === undefined){
const xtDataResult = new dataSource("xt",XtReturnData,Math.floor(new Date().getTime() / 1000))
updateOrCreateDataSource(xtDataResult)
}else{
// Update coingecko
updateDataSource(marketData, dataFromDisk, XtReturnData, Math.floor(new Date().getTime() / 1000))
}
// For the old endpoint will be removed soon
return data.result
}else{
console.log("coingecko Error")
console.log(data)
}
}


//Auto check the data
async function autoCheckData(){
// Fetch market data from disk
Expand All @@ -351,6 +387,7 @@ async function autoCheckData(){
await getMarketData(arrMarketData, 'coinGeckoDirect', 'usd')
await getMarketData(arrMarketData, 'binance','usd');
await getMarketData(arrMarketData, 'coinMarketCap','usd');
await getMarketData(arrMarketData, 'xt','usd')
arrMarketData = await readDataSource();
}
// Aggregate the prices from our various sources
Expand Down
1 change: 1 addition & 0 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const dataSourceUpdateTime = { //listed in seconds
coinGeckoDirect: 70,
coinMarketCap: 10,
binance: 10,
xt:120,
}

/** An optional prefix for the service router: useful if plugging in to an existing Express App */
Expand Down