API for ordered list for sell/buy

- The API for Listing sell/buy orders now returns ordered list of the queue (approx).
- list-buyorders, list-sellorders and list-trades API now accepts optional GET parameter 'asset'.
  . If passed, then orders/trades of only given asset will be returned.
  . If asset is not passed, then returns all asset by default as before.
- list buy/sell order API return max of 100 best orders
- list trade API return max of 1000 recent trades
This commit is contained in:
sairajzero 2022-05-02 22:53:57 +05:30
parent 3c97cb4810
commit 55bd121021
3 changed files with 62 additions and 18 deletions

View File

@ -541,9 +541,9 @@
});
}
exchangeAPI.getBuyList = function() {
exchangeAPI.getBuyList = function(asset = null) {
return new Promise((resolve, reject) => {
fetch_api('/list-buyorders')
fetch_api('/list-buyorders' + (asset ? "?asset=" + asset : ""))
.then(result => responseParse(result)
.then(result => resolve(result))
.catch(error => reject(error)))
@ -551,9 +551,9 @@
});
}
exchangeAPI.getSellList = function() {
exchangeAPI.getSellList = function(asset = null) {
return new Promise((resolve, reject) => {
fetch_api('/list-sellorders')
fetch_api('/list-sellorders' + (asset ? "?asset=" + asset : ""))
.then(result => responseParse(result)
.then(result => resolve(result))
.catch(error => reject(error)))
@ -561,9 +561,9 @@
});
}
exchangeAPI.getTradeList = function() {
exchangeAPI.getTradeList = function(asset = null) {
return new Promise((resolve, reject) => {
fetch_api('/list-trades')
fetch_api('/list-trades' + (asset ? "?asset=" + asset : ""))
.then(result => responseParse(result)
.then(result => resolve(result))
.catch(error => reject(error)))

View File

@ -705,5 +705,8 @@ module.exports = {
},
set assetList(assets) {
assetList = assets;
},
get assetList() {
return assetList
}
};

View File

@ -325,24 +325,65 @@ function GetLoginCode(req, res) {
}
function ListSellOrders(req, res) {
//TODO: Limit size (best)
DB.query("SELECT * FROM SellOrder ORDER BY time_placed")
.then(result => res.send(result))
.catch(error => res.status(INTERNAL.e_code).send("Try again later!"));
if (!serving)
res.status(INVALID.e_code).send(INVALID_SERVER_MSG);
else {
let asset = req.query.asset;
if (asset && !market.assetList.includes(asset))
res.status(INVALID.e_code).send("Invalid asset parameter");
else
DB.query("SELECT SellOrder.floID, SellOrder.asset, GREATEST(SellOrder.minPrice, SellChips.base) AS minPrice, SellOrder.quantity, SellOrder.time_placed FROM SellOrder" +
" INNER JOIN UserBalance ON UserBalance.floID = SellOrder.floID AND UserBalance.token = SellOrder.asset" +
" INNER JOIN SellChips ON SellChips.floID = SellOrder.floID AND SellChips.asset = SellOrder.asset" +
" LEFT JOIN UserTag ON UserTag.floID = SellOrder.floID" +
" LEFT JOIN TagList ON TagList.tag = UserTag.tag" +
" WHERE UserBalance.quantity >= SellOrder.quantity" +
(asset ? " AND SellOrder.asset = ?" : "") +
" GROUP BY SellOrder.id" +
" ORDER BY TagList.sellPriority DESC, SellChips.locktime ASC, SellOrder.time_placed ASC" +
" LIMIT 100", [asset || null])
.then(result => res.send(result))
.catch(error => res.status(INTERNAL.e_code).send("Try again later!"));
}
}
function ListBuyOrders(req, res) {
//TODO: Limit size (best)
DB.query("SELECT * FROM BuyOrder ORDER BY time_placed")
.then(result => res.send(result))
.catch(error => res.status(INTERNAL.e_code).send("Try again later!"));
if (!serving)
res.status(INVALID.e_code).send(INVALID_SERVER_MSG);
else {
let asset = req.query.asset;
if (asset && !market.assetList.includes(asset))
res.status(INVALID.e_code).send("Invalid asset parameter");
else
DB.query("SELECT BuyOrder.floID, BuyOrder.asset, BuyOrder.maxPrice, BuyOrder.quantity, BuyOrder.time_placed FROM BuyOrder" +
" INNER JOIN UserBalance ON UserBalance.floID = BuyOrder.floID AND UserBalance.token = ?" +
" LEFT JOIN UserTag ON UserTag.floID = BuyOrder.floID" +
" LEFT JOIN TagList ON TagList.tag = UserTag.tag" +
" WHERE UserBalance.quantity >= BuyOrder.maxPrice * BuyOrder.quantity" +
(asset ? " AND BuyOrder.asset = ?" : "") +
" GROUP BY BuyOrder.id" +
" ORDER BY TagList.buyPriority DESC, BuyOrder.time_placed ASC" +
" LIMIT 100", [floGlobals.currency, asset || null])
.then(result => res.send(result))
.catch(error => res.status(INTERNAL.e_code).send("Try again later!"));
}
}
function ListTradeTransactions(req, res) {
//TODO: Limit size (recent)
DB.query("SELECT * FROM TradeTransactions ORDER BY tx_time DESC")
.then(result => res.send(result))
.catch(error => res.status(INTERNAL.e_code).send("Try again later!"));
if (!serving)
res.status(INVALID.e_code).send(INVALID_SERVER_MSG);
else {
let asset = req.query.asset;
if (asset && !market.assetList.includes(asset))
res.status(INVALID.e_code).send("Invalid asset parameter");
else
DB.query("SELECT * FROM TradeTransactions" +
(asset ? " WHERE asset = ?" : "") +
" ORDER BY tx_time DESC LIMIT 1000", [asset || null])
.then(result => res.send(result))
.catch(error => res.status(INTERNAL.e_code).send("Try again later!"));
}
}
function GetRates(req, res) {