-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add FIAT exchange for addresses and tx, tx improvements
- Loading branch information
1 parent
dc5adb7
commit c4502a0
Showing
10 changed files
with
136 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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,64 @@ | ||
const _ = require('lodash'); | ||
const mongoose = require( 'mongoose' ); | ||
const fetch = require("node-fetch"); | ||
const https = require('https'); | ||
const Market = require( '../db.js' ).Market; | ||
|
||
// 10 minutes | ||
const quoteInterval = 10 * 60 * 1000; | ||
|
||
const getQuote = async () => { | ||
const options = { | ||
timeout: 10000 | ||
} | ||
const URL = `https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol=${config.settings.symbol}&CMC_PRO_API_KEY=${config.CMC_API_KEY}`; | ||
|
||
try { | ||
let requestUSD = await fetch(URL); | ||
let requestBTC = await fetch(URL + '&convert=BTC'); | ||
let quoteUSD = await requestUSD.json(); | ||
let quoteBTC = await requestBTC.json(); | ||
console.log(quoteUSD) | ||
|
||
quoteObject = { | ||
symbol: config.settings.symbol, | ||
timestamp: Math.round(new Date(quoteUSD.status.timestamp).getTime() / 1000), | ||
quoteBTC: quoteBTC.data.CLO.quote.BTC.price, | ||
quoteUSD: quoteUSD.data.CLO.quote.USD.price, | ||
} | ||
|
||
new Market(quoteObject).save( ( err, market, count ) => { | ||
console.log(market) | ||
if ( typeof err !== 'undefined' && err ) { | ||
process.exit(9); | ||
} else { | ||
console.log('DB successfully written for market quote.'); | ||
} | ||
}); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
} | ||
|
||
|
||
var config = { nodeAddr: 'localhost', gethPort: 8545, bulkSize: 100 }; | ||
try { | ||
var local = require('../config.json'); | ||
_.extend(config, local); | ||
console.log('config.json found.'); | ||
} catch (error) { | ||
if (error.code === 'MODULE_NOT_FOUND') { | ||
var local = require('../config.example.json'); | ||
_.extend(config, local); | ||
console.log('No config file found. Using default configuration... (config.example.json)'); | ||
} else { | ||
throw error; | ||
process.exit(1); | ||
} | ||
} | ||
|
||
getQuote() | ||
|
||
setInterval(() => { | ||
getQuote() | ||
}, quoteInterval); |
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