get-rates API improved

- get-rates API will now give a countDown timer
- this will be time at which next price update will happen unless a trade occurs
- Update: _constants.js for previous update
This commit is contained in:
sairajzero 2022-05-07 00:03:36 +05:30
parent d3c5682994
commit 54470b42d7
4 changed files with 27 additions and 9 deletions

View File

@ -1,7 +1,6 @@
module.exports = { module.exports = {
app: { app: {
BLOCKCHAIN_REFRESH_INTERVAL: 1 * 60 * 60 * 1000, //1 hr BLOCKCHAIN_REFRESH_INTERVAL: 1 * 60 * 60 * 1000, //1 hr
PERIOD_INTERVAL: 15 * 60 * 1000 // 15 min
}, },
request: { request: {
SIGN_EXPIRE_TIME: 5 * 60 * 1000, //5 mins SIGN_EXPIRE_TIME: 5 * 60 * 1000, //5 mins
@ -9,6 +8,9 @@ module.exports = {
INVALID_SERVER_MSG: "INCORRECT_SERVER_ERROR" //Should be reflected in public backend script INVALID_SERVER_MSG: "INCORRECT_SERVER_ERROR" //Should be reflected in public backend script
}, },
market: { market: {
PERIOD_INTERVAL: 5 * 60 * 1000, //5 min,
WAIT_TIME: 2 * 60 * 1000, //2 mins,
LAUNCH_SELLER_TAG: "launch-seller",
MAXIMUM_LAUNCH_SELL_CHIPS: 250000, MAXIMUM_LAUNCH_SELL_CHIPS: 250000,
TRADE_HASH_PREFIX: "z1", TRADE_HASH_PREFIX: "z1",
TRANSFER_HASH_PREFIX: "z0" TRANSFER_HASH_PREFIX: "z0"

View File

@ -695,6 +695,9 @@ module.exports = {
get rates() { get rates() {
return coupling.price.currentRates; return coupling.price.currentRates;
}, },
get priceCountDown() {
return coupling.price.lastTimes;
},
addBuyOrder, addBuyOrder,
addSellOrder, addSellOrder,
cancelOrder, cancelOrder,

View File

@ -207,5 +207,11 @@ module.exports = {
}, },
get currentRates() { get currentRates() {
return Object.assign({}, currentRate); return Object.assign({}, currentRate);
},
get lastTimes() {
let countDown = {};
for (let asset in lastTime)
countDown[asset] = lastTime[asset] + MIN_TIME;
return countDown;
} }
} }

View File

@ -400,16 +400,23 @@ function GetRates(req, res) {
res.status(INVALID.e_code).send(INVALID_SERVER_MSG); res.status(INVALID.e_code).send(INVALID_SERVER_MSG);
else { else {
let asset = req.query.asset, let asset = req.query.asset,
rates = market.rates; rates = market.rates,
countDown = market.priceCountDown;
if (asset) { if (asset) {
if (asset in rates) if (asset in rates)
res.send(rates[asset].toString()); res.send({
asset: asset,
rate: rates[asset],
countDown: countDown[asset]
});
else else
res.status(INVALID.e_code).send("Invalid asset parameter"); res.status(INVALID.e_code).send("Invalid asset parameter");
} else } else
res.send(rates); res.send({
rates,
countDown
});
} }
} }
function GetRateHistory(req, res) { function GetRateHistory(req, res) {