Skip to content

Commit

Permalink
Fix: fixes spot sign calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
pustovitDmytro committed Aug 4, 2022
1 parent 98049e8 commit 0407988
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/workers/binanceSpotRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default async function (job) {
const innerPn = new ProgressNotifier([ 0.3, 0.95 ], pn);
const sign = user.type === 'LESS' ? 1 : -1;

const matching = results.filter(item => user.asset === item.asset && (user.limit - item.price) * sign <= 0);
const matching = results.filter(item => (user.asset === item.asset) && ((item.price - user.limit) * sign <= 0));

const userResult = { user, matching: matching.length };

if (matching.length > 0) {
Expand Down
32 changes: 27 additions & 5 deletions tests/workers/binanceSpotRequest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ before(async function () {
test('binanceSpotRequest', async function () {
const data = {
users : [
{ limit: 200, tgChat: 103, asset: 'BNBBUSD' },
{ limit: 40, tgChat: 104, asset: 'UAHUSDT', type: 'MORE' }
{ limit: 400, tgChat: 103, asset: 'BNBBUSD', type: 'LESS' },
{ limit: 42, tgChat: 104, asset: 'USDTUAH', type: 'MORE' },
{ limit: 42, tgChat: 105, asset: 'BUSDUAH', type: 'LESS' }
]
};

Expand All @@ -27,12 +28,33 @@ test('binanceSpotRequest', async function () {

assert.deepEqual(res, [
{
user : { limit: 200, tgChat: 103, asset: 'BNBBUSD' },
matching : 0
user : {
limit : 400,
tgChat : 103,
asset : 'BNBBUSD',
type : 'LESS'
},
matching : 1,
alarm : '1'
},
{
user : { limit: 40, tgChat: 104, asset: 'UAHUSDT', type: 'MORE' },
user : {
limit : 42,
tgChat : 104,
asset : 'USDTUAH',
type : 'MORE'
},
matching : 0
},
{
user : {
limit : 42,
tgChat : 105,
asset : 'BUSDUAH',
type : 'LESS'
},
matching : 1,
alarm : '2'
}
]);
});
Expand Down

0 comments on commit 0407988

Please sign in to comment.