Different group/tag priority for sell and buy

This commit is contained in:
sairajzero 2021-11-02 03:39:07 +05:30
parent c14f10eade
commit d435157bd2

View File

@ -15,14 +15,16 @@ function addTag(floID, tag) {
function getBestPairs(currentRate) { function getBestPairs(currentRate) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
DB.query("SELECT tag FROM TagList ORDER BY priority").then(result => { DB.query("SELECT tag, sellPriority, buyPriority FROM TagList").then(result => {
let tags = result.map(r => r.tag) //Sorted in Ascending (ie, stack; pop for highest) //Sorted in Ascending (ie, stack; pop for highest)
resolve(new bestPair(tags, currentRate)); let tags_buy = result.sort((a, b) => a.buyPriority > b.buyPriority).map(r => r.tag);
let tags_sell = result.sort((a, b) => a.sellPriority > b.sellPriority).map(r => r.tag);
resolve(new bestPair(currentRate, tags_buy, tags_sell));
}).catch(error => reject(error)) }).catch(error => reject(error))
}) })
} }
const bestPair = function(tags, currentRate) { const bestPair = function(currentRate, tags_buy, tags_sell) {
this.get = () => new Promise((resolve, reject) => { this.get = () => new Promise((resolve, reject) => {
Promise.all([getBuyOrder(), getSellOrder()]).then(results => { Promise.all([getBuyOrder(), getSellOrder()]).then(results => {
@ -99,7 +101,7 @@ const bestPair = function(tags, currentRate) {
reject(false); reject(false);
}); });
getSeller.cache = { getSeller.cache = {
tags: Array.from(tags) tags: tags_sell
}; };
const getBuyOrder = () => new Promise((resolve, reject) => { const getBuyOrder = () => new Promise((resolve, reject) => {
@ -150,7 +152,7 @@ const bestPair = function(tags, currentRate) {
reject(false); reject(false);
}); });
getBuyOrder.cache = { getBuyOrder.cache = {
tags: Array.from(tags) //Maybe diff for buy and sell ? tags: tags_buy
}; };
} }