Skip to content

Commit 3042e1e

Browse files
committed
try fix tests
1 parent 2b62d63 commit 3042e1e

1 file changed

Lines changed: 35 additions & 11 deletions

File tree

tests/binance-class-live.test.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,10 @@ describe('Limit buy Order', function () {
272272
assert(res['orderId'] !== undefined)
273273
spotOrderId = res['orderId'];
274274
} catch (e) {
275-
assert(e.toString().includes('{"code":-2010,"msg":"Account has insufficient balance for requested action."}'));
275+
const exceptionA = '{"code":-2010,"msg":"Account has insufficient balance for requested action."}';
276+
const exceptionB = '{"code":-2019,"msg":"Margin is insufficient."}'
277+
const eStr = e.toString();
278+
assert(eStr.includes(exceptionA) || eStr.includes(exceptionB));
276279
}
277280
}
278281

@@ -287,7 +290,10 @@ describe('MarketSell', function () {
287290
const res = await binance.marketSell('LTCUSDT', quantity)
288291
assert(res['orderId'] !== undefined)
289292
} catch (e) {
290-
assert(e.toString().includes('{"code":-2010,"msg":"Account has insufficient balance for requested action."}'));
293+
const exceptionA = '{"code":-2010,"msg":"Account has insufficient balance for requested action."}';
294+
const exceptionB = '{"code":-2019,"msg":"Margin is insufficient."}'
295+
const eStr = e.toString();
296+
assert(eStr.includes(exceptionA) || eStr.includes(exceptionB));
291297
}
292298

293299
}).timeout(TIMEOUT);
@@ -301,28 +307,46 @@ describe('Futures MarketBuy', function () {
301307
assert(res['orderId'] !== undefined)
302308
futuresOrderId = res['orderId'];
303309
} catch (e) {
304-
assert(e.toString().includes('{"code":-2010,"msg":"Account has insufficient balance for requested action."}'));
310+
const exceptionA = '{"code":-2010,"msg":"Account has insufficient balance for requested action."}';
311+
const exceptionB = '{"code":-2019,"msg":"Margin is insufficient."}'
312+
const eStr = e.toString();
313+
assert(eStr.includes(exceptionA) || eStr.includes(exceptionB));
305314
}
306315

307316
}).timeout(TIMEOUT);
308317
});
309318

310319
describe('Futures Limit buy Order', function () {
311320
it('Attempt to buy ETH', async function () {
312-
if (ethusdtPrice !== 0) {
313-
let quantity = 0.1;
314-
const res = await futuresBinance.futuresOrder('LIMIT', 'BUY', 'ETHUSDT', quantity, Math.round(ethusdtPrice * 0.8))
315-
assert(res['orderId'] !== undefined)
316-
futuresOrderId = res['orderId'];
321+
try {
322+
if (ethusdtPrice !== 0) {
323+
let quantity = 0.1;
324+
const res = await futuresBinance.futuresOrder('LIMIT', 'BUY', 'ETHUSDT', quantity, Math.round(ethusdtPrice * 0.8))
325+
assert(res['orderId'] !== undefined)
326+
futuresOrderId = res['orderId'];
327+
}
328+
} catch (e) {
329+
const exceptionA = '{"code":-2010,"msg":"Account has insufficient balance for requested action."}';
330+
const exceptionB = '{"code":-2019,"msg":"Margin is insufficient."}'
331+
const eStr = e.toString();
332+
assert(eStr.includes(exceptionA) || eStr.includes(exceptionB));
317333
}
334+
318335
}).timeout(TIMEOUT);
319336
});
320337

321338
describe('Futures MarketSell', function () {
322339
it('futures Attempt to buy ETH at market price', async function () {
323-
let quantity = 0.1;
324-
const res = await futuresBinance.futuresMarketSell('ETHUSDT', quantity)
325-
assert(res['orderId'] !== undefined)
340+
try {
341+
let quantity = 0.1;
342+
const res = await futuresBinance.futuresMarketSell('ETHUSDT', quantity)
343+
assert(res['orderId'] !== undefined)
344+
} catch (e) {
345+
const exceptionA = '{"code":-2010,"msg":"Account has insufficient balance for requested action."}';
346+
const exceptionB = '{"code":-2019,"msg":"Margin is insufficient."}'
347+
const eStr = e.toString();
348+
assert(eStr.includes(exceptionA) || eStr.includes(exceptionB));
349+
}
326350

327351
}).timeout(TIMEOUT);
328352
});

0 commit comments

Comments
 (0)