Skip to content

Commit

Permalink
feat: 🎸 all price of tokens of aelf version1;
Browse files Browse the repository at this point in the history
  • Loading branch information
hzz780 committed Sep 3, 2020
1 parent 2fe9fce commit 1b18429
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
42 changes: 42 additions & 0 deletions app/controller/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,48 @@ class TokenController extends Controller {
}
}

async getPricesTokensOfAelf() {
const {
ctx
} = this;

const {
type = 'USD'
} = ctx.request.query;

try {

const tokenList = await ctx.service.token.getTokenList({
limit: 2000,
page: 0
});

// TODO: valid token pool. if the same name in public market.
// For Example: LOT, DISK, NET is now in public market.
const validPool = [ 'ELF', 'AEUSD' ];
const pairs = [];
tokenList.forEach(token => {
if (/^AE/.test(token.symbol) && token.symbol !== 'AEUSD') {
pairs.push({
fsym: token.symbol.replace(/^AE/, ''),
tsyms: type
});
} else if (validPool.includes(token.symbol)) {
pairs.push({
fsym: token.symbol,
tsyms: type
});
}
});

const result = await ctx.service.token.getPrices(pairs);

formatOutput(ctx, 'get', result);
} catch (error) {
formatOutput(ctx, 'error', error, 422);
}
}

}

module.exports = TokenController;
3 changes: 2 additions & 1 deletion app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ module.exports = app => {

router.get('/api/token/txs', controller.token.getTxs);
router.get('/api/token/price', controller.token.getPrice);
router.get('/api/token/prices', controller.token.getPrices);
router.get('/api/token/prices-tokens-of-aelf', controller.token.getPricesTokensOfAelf);
router.post('/api/token/prices', controller.token.getPrices);

router.post('/api/vote/addTeamDesc', controller.vote.addTeamDesc);
router.get('/api/vote/getTeamDesc', controller.vote.getTeamDesc);
Expand Down
12 changes: 12 additions & 0 deletions app/service/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ class TokenService extends BaseService {
});
}));
}

async getTokenList(options) {
const aelf0 = this.ctx.app.mysql.get('aelf0');
const {
limit = 1000,
page = 0,
} = options;

const offset = page * limit;
const sql = 'select * from contract_aelf20 order by id desc limit ? offset ?';
return this.selectQuery(aelf0, sql, [ limit, offset ]);
}
}

module.exports = TokenService;

0 comments on commit 1b18429

Please sign in to comment.